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

Fix false positive for UnnecessaryApply with disabled type resolution #2963

Merged

Conversation

cortinico
Copy link
Member

@cortinico cortinico commented Aug 11, 2020

Restricting UnnecessaryApply to work only when type resolution is active.

Currently the rule is generating false positives for scenarios where the return value of .apply{} is used. We actually already have the code to handle this scenario (!expression.receiverIsUsed(bindingContext)) but it requires type and symbol resolution to provide a meaningful result.

As a rule of thumb, we should also consider avoiding rules with "mixed" inspection if you have type resolution enabled or not.

Fixes #2938

@codecov
Copy link

codecov bot commented Aug 11, 2020

Codecov Report

Merging #2963 into master will increase coverage by 0.02%.
The diff coverage is 76.47%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2963      +/-   ##
============================================
+ Coverage     80.25%   80.27%   +0.02%     
- Complexity     2465     2478      +13     
============================================
  Files           423      424       +1     
  Lines          7440     7473      +33     
  Branches       1358     1369      +11     
============================================
+ Hits           5971     5999      +28     
+ Misses          763      760       -3     
- Partials        706      714       +8     
Impacted Files Coverage Δ Complexity Δ
...turbosch/detekt/rules/bugs/NullableToStringCall.kt 74.19% <74.19%> (ø) 10.00 <10.00> (?)
...turbosch/detekt/rules/bugs/PotentialBugProvider.kt 100.00% <100.00%> (ø) 2.00 <0.00> (ø)
.../arturbosch/detekt/rules/style/UnnecessaryApply.kt 88.46% <100.00%> (+0.46%) 8.00 <0.00> (+1.00)
.../gitlab/arturbosch/detekt/api/internal/BaseRule.kt 100.00% <0.00%> (+6.25%) 6.00% <0.00%> (ø%)
...rturbosch/detekt/api/internal/CompilerResources.kt 100.00% <0.00%> (+66.66%) 3.00% <0.00%> (+2.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 3bfec16...c991648. Read the comment docs.

@schalkms schalkms merged commit d5ecca3 into detekt:master Aug 11, 2020
@arturbosch arturbosch added this to the 1.11.0 milestone Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive in UnnecessaryApply
3 participants