-
-
Notifications
You must be signed in to change notification settings - Fork 774
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
Add unnecessary apply rule #1229
Conversation
detekt-rules/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnnecessaryApplySpec.kt
Outdated
Show resolved
Hide resolved
detekt-rules/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnnecessaryApplySpec.kt
Outdated
Show resolved
Hide resolved
}""") | ||
assertThat(findings).hasSize(0) | ||
} | ||
} |
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.
How about a test case where apply is called with unnecessary parentheses a.apply({ test = true })
.
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.
That should be covered by the existing UnnecessaryParentheses
check.
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.
That's true. But not only that, it would also be an unnecessary apply. If we add this test we ensure that the user doesn't run detekt, realizes the UnnecessaryParentheses
, fixes it, runs detekt again only to see yet another issue on the exact line of code.
If we ensure both rules report at the same time it gives the report more information that the user can act on.
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.
Makes sense. I've added some more tests, including one to cover this scenario.
Thank you for the contribution! |
07c1b10
to
cf810c0
Compare
Would also be nice to add a test case where the return value of
|
cf810c0
to
befbec6
Compare
Adds a rule, some tests for it, and also updates the StyleGuideProvider to include this new rule.
I've added some tests for this. |
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 implementing this. I like this rule.
val findings = subject.lint(""" | ||
fun b(i : Int) { | ||
} | ||
fun f() { |
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.
Ca we please use separate test cases for each code sample. This makes it easier to debug and trace it.
val findings = subject.lint(""" | ||
fun b(i : Int) { | ||
} | ||
fun f() { |
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 same applies here.
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 the additional tests! As @schalkms mentioned it makes sense splitting them into individual test cases to make them easier to maintain and more self-explanatory.
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 the contribution!
This PR adds a rule to check for unnecessary use of apply, as described in issue #1214.