-
-
Notifications
You must be signed in to change notification settings - Fork 770
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
New Rule: IgnoredReturnValue #2698
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2698 +/- ##
============================================
+ Coverage 79.85% 79.89% +0.04%
- Complexity 2305 2314 +9
============================================
Files 381 382 +1
Lines 6940 6979 +39
Branches 1250 1262 +12
============================================
+ Hits 5542 5576 +34
Misses 779 779
- Partials 619 624 +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, I like this rule 🥇
Did you run this on detekt itself or any 3rd party projects in order to check for any false-positives?
Script:
https://github.com/detekt/detekt/blob/master/scripts/get_analysis_projects.groovy
detekt-rules/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/IgnoredReturnValue.kt
Show resolved
Hide resolved
detekt-rules/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/IgnoredReturnValue.kt
Outdated
Show resolved
Hide resolved
val returnType = resolvedCall.resultingDescriptor.returnType ?: return | ||
|
||
if (returnType.isUnit()) { | ||
return | ||
} |
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.
nit: then the @Suppress
isn't necessary anymore.
val returnType = resolvedCall.resultingDescriptor.returnType ?: return | |
if (returnType.isUnit()) { | |
return | |
} | |
if (resolvedCall.resultingDescriptor.returnType?.isUnit() == true) return |
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'd rather keep it separated to improve readability. Feel free to reopen if you think it's still needed in the following diff.
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.
True. Maybe the code should read if (returnType?.isUnit() == true)
.
I just don't want to spam the codebase with Suppress
annotations.
You can read #2239 for more context. But in short: I think that this rule should use the |
Agree on this. I'll extend the rule to account only calls to functions annotated with |
I would do this in a next step and merge this PR first. It makes it also easier to review. |
I understand your point, but, wouldn't that delay our release? I mean, we would have no-production ready code in |
The rule is disabled anyway. |
b436aa9
to
c2bb657
Compare
I've posted another diff for this rule. There are still some open points that I would love to get an input from @BraisGabin @schalkms:
|
HTH 🙂 |
Yes, I think that this should be configurable, and in this configuration we can support both options. The default value should be something like
The problem here is that in detekt we doesn't have a defined way to do this. I'll open an issue to talk about this. In my opinion the second option is the best. It provides a lot of flexibility and it's easy to read.
Yes
Agree. |
I'd either go for option 2 or 3. Option 2 could be achieved using this: detekt/detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/SplitPattern.kt Lines 90 to 96 in 57e0b91
This will make the rule behavior consistent with the I'd be in for option 2, I just don't want to block this PR with #2711 |
For me the option 2 is the best. And for sure, this doesn't need to wait for #2711. That issue is a more generic one and probably something to face for For me this PR can be merged right now if you agree. The missing parts are just to add more configuration but the rule right now work as intended with the default configurations. So any other feature can be added in other PR. |
Sure, go for that, I'll follow up with a couple of small PRs |
I've cherry-picked @bbaldino commits and fixed the tests for the new rule
IgnoredReturnValue
.I've tried this approach that checks if a
PsiElement
is "isolated" and the return value is notUnit
. I'm not sure it's the correct one but from the tests it seems promising.I'd be happy to receive further ideas for test cases or improvements.
Closes #209
Closes #2239
Closes #2242