Skip to content

Fix false negative in IgnoredReturnValue#3179

Merged
schalkms merged 5 commits intodetekt:masterfrom
t-kameyama:issue_3170
Oct 28, 2020
Merged

Fix false negative in IgnoredReturnValue#3179
schalkms merged 5 commits intodetekt:masterfrom
t-kameyama:issue_3170

Conversation

@t-kameyama
Copy link
Copy Markdown
Contributor

Fixes #3170

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 27, 2020

Codecov Report

Merging #3179 into master will decrease coverage by 0.01%.
The diff coverage is 52.94%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #3179      +/-   ##
============================================
- Coverage     79.58%   79.57%   -0.02%     
+ Complexity     2610     2606       -4     
============================================
  Files           439      439              
  Lines          7935     7920      -15     
  Branches       1511     1502       -9     
============================================
- Hits           6315     6302      -13     
  Misses          820      820              
+ Partials        800      798       -2     
Impacted Files Coverage Δ Complexity Δ
...ekt/rules/style/optional/PreferToOverPairSyntax.kt 73.33% <0.00%> (-5.24%) 7.00 <1.00> (+2.00) ⬇️
...arturbosch/detekt/rules/bugs/IgnoredReturnValue.kt 83.33% <60.00%> (+4.16%) 10.00 <0.00> (-7.00) ⬆️
...ekt/rules/style/RedundantVisibilityModifierRule.kt 91.48% <60.00%> (-4.07%) 11.00 <1.00> (+1.00) ⬇️

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 b5a423f...0ceea6a. Read the comment docs.


val parentQualifiedExpression = expression.getStrictParentOfType<KtQualifiedExpression>()
if (parentQualifiedExpression != null && parentQualifiedExpression.selectorExpression != expression) return
if (expression.isUsedAsExpression(bindingContext)) return
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 what if the statment is not the last of the if? I mean:

val a = if (random()) {
  2
} else {
  returnsInt()
  3
}

Is this handled correctly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 5c2d3e3, but the following case is not flagged. I will fix.

if (Random.nextBoolean()) {
    1
} else {
    returnsInt()
    2
}.plus(1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 217901b

@t-kameyama t-kameyama requested a review from BraisGabin October 28, 2020 00:27
Copy link
Copy Markdown
Member

@BraisGabin BraisGabin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏🏻👏🏻

@schalkms schalkms merged commit e2bd8ad into detekt:master Oct 28, 2020
@t-kameyama t-kameyama deleted the issue_3170 branch October 28, 2020 11:23
@arturbosch arturbosch added this to the 1.15.0 milestone Nov 2, 2020
arturbosch pushed a commit that referenced this pull request Nov 15, 2020
* Fix false negative in IgnoredReturnValue

* Add "report when a function is not the last statement in a 'if' block and 'if' block is used" test

* Report when a function is not the last statement in a block and it's in a chain

* Refactor

* Add @Suppress(LargeClass)
arturbosch pushed a commit that referenced this pull request Dec 21, 2020
* Fix false negative in IgnoredReturnValue

* Add "report when a function is not the last statement in a 'if' block and 'if' block is used" test

* Report when a function is not the last statement in a block and it's in a chain

* Refactor

* Add @Suppress(LargeClass)
arturbosch pushed a commit that referenced this pull request Jan 16, 2021
* Fix false negative in IgnoredReturnValue

* Add "report when a function is not the last statement in a 'if' block and 'if' block is used" test

* Report when a function is not the last statement in a block and it's in a chain

* Refactor

* Add @Suppress(LargeClass)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False negative in IgnoredReturnValue

4 participants