New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[VarCouldBeVal] fix overrides false positives #4664
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for submitting the PR.
While I agree, that a lateinit var
can never really become a val
, I think the underlying issue here is the magic done by the framework. To detekt the variable never changes its value and therefor it could be val. Therefor changing your config to
VarCouldBeVal:
active: true
ignoreAnnotated: ['Inject']
would in my opinion also be a valid fix.
Long story short - I think your approach here is valid. The issue that a private lateinit var
is never assigned a value should be handled by a different rule.
detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/VarCouldBeValSpec.kt
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## main #4664 +/- ##
=========================================
Coverage 84.58% 84.58%
Complexity 3434 3434
=========================================
Files 492 492
Lines 11329 11329
Branches 2058 2058
=========================================
Hits 9583 9583
Misses 701 701
Partials 1045 1045
Continue to review full report at Codecov.
|
f8b505c
to
8d81554
Compare
I ended up doing this workaround for the Inject annotation as this was the main issue in one of our project. But there are many frameworks that rely on an annotation and a |
I don't think that we should ignore |
@meriouma Could you please change this PR to address the issue with I can see the arguments on either side. Since there is an easy workaround for your specific problem I would also not change it at the moment. Maybe this becomes a pattern and we could change it in the future. |
8d81554
to
85a6e3d
Compare
@marschwar Done! |
@marschwar Sure, no problem. I can rebase and rewrite the test case once #4575 is merged. |
85a6e3d
to
b65dbd5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR #4575 has been merged.
I've rebased and updated the test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I'm not sure this is correct as this seems a simple check, but this fixes #4661 and does not break other tests.