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
IgnoredReturnValue
: add option returnValueTypes
to enable rule for particular types
#4922
IgnoredReturnValue
: add option returnValueTypes
to enable rule for particular types
#4922
Conversation
...ules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/IgnoredReturnValue.kt
Outdated
Show resolved
Hide resolved
@@ -92,6 +92,15 @@ class FindingsAssert(actual: List<Finding>) : | |||
} | |||
|
|||
class FindingAssert(val actual: Finding?) : AbstractAssert<FindingAssert, Finding>(actual, FindingAssert::class.java) { | |||
|
|||
fun hasSourceLocation(line: Int, column: Int) = apply { |
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.
I've added this function to make it possible to use this assert in asserts chain:
assertThat(findings)
.singleElement()
.hasSourceLocation(line = 5, column = 10)
.hasMessage("The call onEach is returning a value that is ignored.")
instead of
assertThat(findings).singleElement()
assertThat(findings).hasSourceLocation(line = 5, column = 10)
assertThat(findings.first()).hasMessage("The call onEach is returning a value that is ignored.")
...-errorprone/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/IgnoredReturnValueSpec.kt
Show resolved
Hide resolved
By looking at this rule API, I think we should add also the
The rule should then check if It makes for a more explicit configuration and it aligns to |
Codecov Report
@@ Coverage Diff @@
## main #4922 +/- ##
===========================================
+ Coverage 0 84.83% +84.83%
- Complexity 0 3515 +3515
===========================================
Files 0 497 +497
Lines 0 11554 +11554
Branches 0 2140 +2140
===========================================
+ Hits 0 9802 +9802
- Misses 0 686 +686
- Partials 0 1066 +1066
Continue to review full report at Codecov.
|
Thank you for API review! |
Yes that's correct. If enabled, the rule will flag only function which are returning the values types you listed. If this is not the case, then I misunderstood what was the semantic of your change. |
I mean sentence "rule will check only annotated methods" conflicts with "rule will check only methods returning the specified types" because both contain word "only". So maybe there may be better naming? Something that means "always check methods returning specified types even if checks enabled only for annotated methods"? |
I would suggest to don't implement this logic. The two |
Ok, I think I understand now. I'll add flag |
🤔 I think that we should reframe the configuration of this rule. To me this issue should flag a function if it returns a To do that I would deprecate the current boolean flag and rename it to some naming more clear. |
979cac9
to
2896f59
Compare
2896f59
to
94a3d4c
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.
@cortinico, @BraisGabin, I've just updated this PR, can you take a look?
...ules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/IgnoredReturnValue.kt
Show resolved
Hide resolved
...ules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/IgnoredReturnValue.kt
Show resolved
Hide resolved
...ules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/IgnoredReturnValue.kt
Show resolved
Hide resolved
...ules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/IgnoredReturnValue.kt
Show resolved
Hide resolved
...ules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/IgnoredReturnValue.kt
Show resolved
Hide resolved
Sorry for ping, but should it be merged? |
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.
I'm fine with merging this 👍
@@ -431,12 +431,16 @@ potential-bugs: | |||
active: true | |||
IgnoredReturnValue: | |||
active: true | |||
restrictToAnnotatedMethods: 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.
Reminder for self: this should be noted in the release notes
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.
@cortinico this change was not mentioned in release notes 🙈
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 reminder 👍
Thank you for the PR :) |
This PR adds config option
returnValueTypes
(is this option name OK?) to make it possible to enable the rule for functions returning specified types.Also, I've added
kotlinx.coroutines.flow.Flow
to the default config.Resolves #4640