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
Added rule UnnecessaryInnerClass #4394
Added rule UnnecessaryInnerClass #4394
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4394 +/- ##
============================================
+ Coverage 84.34% 84.39% +0.05%
- Complexity 3299 3324 +25
============================================
Files 473 474 +1
Lines 10532 10605 +73
Branches 1885 1899 +14
============================================
+ Hits 8883 8950 +67
- Misses 671 672 +1
- Partials 978 983 +5
Continue to review full report at Codecov.
|
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 for tackling this very old issue! I think this rule fits nicely into detekt.
As mentioned in the issue description, there's a high risk for false positives though. Hence, this rule should be tested thoroughly on sample projects. Have you run this rule on other codebases? If not, the following script in detekt might help to achieve that.
https://github.com/detekt/detekt/blob/main/scripts/get_analysis_projects.kts
} | ||
""".trimIndent() | ||
|
||
Assertions.assertThat(subject.lintWithContext(env, code)).hasSize(1) |
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.
The Assertions.
reference can be imported and thus removed from the assert
statements for a cleaner test structure.
Other rules show examples on how to use it.
The rule requires the binding context to be present, which would mean configuring the |
I'm still hesitant to merge this, since I feel like the rule could take a few more test runs. Testing it in production is not the route, which I'd like to go here. |
Why not? Releasing experimental and beta code is not an unusual workflow, e.g. the pattern matching preview code that's been released in JDK 16 and 17; and given that the rule will be disabled by default, no user's going to have their code broken by any issues with this rule unless they actively go out of their way to enable it. It'll be a lot more straightforward to be able to test the new rule when it can be integrated via the Gradle plug-in; otherwise, it's going to be a very arduous task to hand-build the classpath for all of these projects to test out the rule manually. |
Alternatively, we could enable this new rule for the detekt project itself to help us evaluate. I agree with @severn-everett that since this is a new rule disabled by default, we can roll it out to production and gather feedback. A counterpart is |
} | ||
} | ||
|
||
// Replace this "contructor().apply{}" pattern with buildSet() when Kotlin is upgraded to 1.6 |
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.
Can we replace it now? #4277
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.
Yeah, I'll swing back and fix this tomorrow.
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.
It doesn't look like it's available until the API version is at 1.6; I'll update the note to reflect that
This addresses issue #875.