Skip to content
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 rule to warn on ignored return value #2242

Closed
wants to merge 5 commits into from

Conversation

bbaldino
Copy link
Contributor

@bbaldino bbaldino commented Jan 10, 2020

Addresses #2239.

I'd consider this as draft at this point. It works for the test cases I've provided, but I'm not familiar with all of the psi element types and I worry a bit that there may be some I missed (or perhaps a better way to detect what I am detecting).

@bbaldino
Copy link
Contributor Author

Travis tests look like they're failing because I didn't update default-detekt-yml. Not sure how that should be updated yet, though, so will leave it as-is until I hear how to proceed there.

@BraisGabin
Copy link
Member

Travis tests look like they're failing because I didn't update default-detekt-yml. Not sure how that should be updated yet, though, so will leave it as-is until I hear how to proceed there.

Run ./gradlew generateDocumentation and those files would be updated.

@bbaldino
Copy link
Contributor Author

Travis tests look like they're failing because I didn't update default-detekt-yml. Not sure how that should be updated yet, though, so will leave it as-is until I hear how to proceed there.

Run ./gradlew generateDocumentation and those files would be updated.

I ran this, but it didn't seem to result in any changes I could commit.

@bbaldino
Copy link
Contributor Author

Travis tests look like they're failing because I didn't update default-detekt-yml. Not sure how that should be updated yet, though, so will leave it as-is until I hear how to proceed there.

Run ./gradlew generateDocumentation and those files would be updated.

I ran this, but it didn't seem to result in any changes I could commit.

Found it. Had to add it to PotentialBugProvider.

@bbaldino
Copy link
Contributor Author

I've made some more tweaks, but when testing against my code base I'm running into a lot of incorrect classifications. I'm checking the PsiElement type of each one I find and adding handling for it, but it feels a bit like whack-a-mole and can be hard to differentiate in places where elements are nested multiple levels below where an assignment or something is actually done. I have a feeling my lack of knowledge of the Psi types may be making this more difficult than it needs to be? Are there some useful helpers to differentiate expressions from assignment expressions, etc.?

@codecov-io
Copy link

codecov-io commented Jan 11, 2020

Codecov Report

Merging #2242 into master will increase coverage by 0.03%.
The diff coverage is 87.5%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2242      +/-   ##
============================================
+ Coverage     81.38%   81.41%   +0.03%     
- Complexity     2074     2083       +9     
============================================
  Files           343      344       +1     
  Lines          5984     6000      +16     
  Branches       1086     1091       +5     
============================================
+ Hits           4870     4885      +15     
  Misses          532      532              
- Partials        582      583       +1
Impacted Files Coverage Δ Complexity Δ
...sch/detekt/rules/providers/PotentialBugProvider.kt 100% <100%> (ø) 3 <0> (ø) ⬇️
...arturbosch/detekt/rules/bugs/IgnoredReturnValue.kt 85.71% <85.71%> (ø) 6 <6> (?)
...turbosch/detekt/rules/style/UnusedPrivateMember.kt 93.47% <0%> (ø) 5% <0%> (ø) ⬇️
...osch/detekt/rules/bugs/WrongEqualsTypeParameter.kt 100% <0%> (ø) 10% <0%> (+3%) ⬆️
.../gitlab/arturbosch/detekt/rules/MethodSignature.kt 70% <0%> (+10%) 0% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5dfe7c5...ef69090. Read the comment docs.

@schalkms
Copy link
Member

schalkms commented Jan 11, 2020

Continuing here, because it’s easier than on Slack.
The way to go would be to take a code snippet that gets flagged by your rule and debug the Psi tree with the watch functionality in IntelliJ. I don’t think there’s some pre defined helper function in the Framework, which does the trick for you.
Please correct me if I’m wrong @3flex.

@bbaldino
Copy link
Contributor Author

Continuing here, because it’s easier than on Slack.
The way to go would be to take a code snippet that gets flagged by your rule and debug the Psi tree with the watch functionality in IntelliJ. I don’t think there’s some pre defined helper function in the Framework, which does the trick for you.
Please correct me if I’m wrong @3flex.

Ok, this is what I've been doing. Thanks for confirming.

@3flex
Copy link
Member

3flex commented Jan 11, 2020

Also have a look at PsiViewer plugin for IntelliJ which I've found useful.

@bbaldino
Copy link
Contributor Author

Also have a look at PsiViewer plugin for IntelliJ which I've found useful.

Ah! This is super helpful. Thanks!

@schalkms
Copy link
Member

schalkms commented Feb 7, 2020

@bbaldino do you have an update on this PR? Do you need assistance from our side?

@bbaldino
Copy link
Contributor Author

bbaldino commented Feb 7, 2020

@bbaldino do you have an update on this PR? Do you need assistance from our side?

Sorry for the lack of updates, work has been busy and I haven't had much time to work on this. Where I was hung up, though, was discovering all the different expressions which this should apply to; finding them all and good ways to properly detect them was proving tough.

I wondered about detekt's policy on rules: might it be interesting to have an initial version of this which was naive and only detected some cases? Or are rules only merged when they are 'complete'?

@schalkms
Copy link
Member

schalkms commented Feb 8, 2020

I wondered about detekt's policy on rules: might it be interesting to have an initial version of this which was naive and only detected some cases? Or are rules only merged when they are 'complete'?

We haven’t had this case so far. I obviously don’t want to include rules that are buggy into detekt. In your case the rule just doesn’t flag all corner cases, which is okay. I hope that I understood you correctly.
In my opinion this rule should go into an experimental rule set.

@bbaldino
Copy link
Contributor Author

I wondered about detekt's policy on rules: might it be interesting to have an initial version of this which was naive and only detected some cases? Or are rules only merged when they are 'complete'?

We haven’t had this case so far. I obviously don’t want to include rules that are buggy into detekt. In your case the rule just doesn’t flag all corner cases, which is okay. I hope that I understood you correctly.
In my opinion this rule should go into an experimental rule set.

Yeah that makes sense and is what I was wondering. I still have been a bit strapped for time, but I'll plan on seeing if I can focus on a smaller ruleset which can detect some cases but not give any false positives.

@schalkms
Copy link
Member

@bbaldino great! Just pings us if you need help or assistance.

@schalkms
Copy link
Member

schalkms commented May 9, 2020

Since this PR become inactive, I'm wondering if you @bbaldino still plan to work further on this PR. We are open to answer any questions you have.

@bbaldino
Copy link
Contributor Author

Apologies for the radio silence...work got busy and I haven't had time to come back to this--and unfortunately don't think I'll be able to anytime soon. Feel free to close this if you like, I can reopen if I ever get back around to it.

@schalkms
Copy link
Member

@bbaldino no worries.. Thanks for the fast reply. I'll put a help wanted tag on this PR in case somebody wants to pick it up and thus help out here.

@cortinico
Copy link
Member

@schalkms I can pick this up, can you assign this PR to me?

@BraisGabin
Copy link
Member

All yours ;) and thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants