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

UnnecessaryInnerClass: fix false positives labeled expression to outer class #4865

Merged
merged 2 commits into from May 29, 2022
Merged

UnnecessaryInnerClass: fix false positives labeled expression to outer class #4865

merged 2 commits into from May 29, 2022

Conversation

dzirbel
Copy link
Contributor

@dzirbel dzirbel commented May 26, 2022

Fix an issue where inner classes which reference their outer class via a labeled
expression would still be reported as unnecessary. This seems to be due to a
missing visitExpressionWithLabel() check which resolves the label name: if the
label is referencing a parent class, then the nested class must be inner.

I wasn't able to find a way to resolve the labeled expression as a ClassId to
match the existing class check from KtReferenceExpression, so I settled for
using the class name instead, which is easy to obtain. This means there's a fair
bit of duplication in overriden checkForOuterUsage() methods to check parent
classes which could probably be removed, but I didn't see a particularly clean
way to do so.

…r class

Fix an issue where inner classes which reference their outer class via a labeled
expression would still be reported as unnecessary. This seems to be due to a
missing visitExpressionWithLabel() check which resolves the label name: if the
label is referencing a parent class, then the nested class must be `inner`.

I wasn't able to find a way to resolve the labeled expression as a ClassId to
match the existing class check from KtReferenceExpression, so I settled for
using the class name instead, which is easy to obtain. This means there's a fair
bit of duplication in overriden checkForOuterUsage() methods to check parent
classes which could probably be removed, but I didn't see a particularly clean
way to do so.
@codecov
Copy link

codecov bot commented May 26, 2022

Codecov Report

Merging #4865 (436cb9d) into main (fcd9c48) will increase coverage by 0.00%.
The diff coverage is 91.66%.

❗ Current head 436cb9d differs from pull request most recent head 71393c3. Consider uploading reports for the commit 71393c3 to get more accurate results

@@            Coverage Diff            @@
##               main    #4865   +/-   ##
=========================================
  Coverage     84.79%   84.80%           
- Complexity     3447     3452    +5     
=========================================
  Files           492      492           
  Lines         11315    11326   +11     
  Branches       2083     2086    +3     
=========================================
+ Hits           9595     9605   +10     
  Misses          673      673           
- Partials       1047     1048    +1     
Impacted Files Coverage Δ
...rbosch/detekt/rules/style/UnnecessaryInnerClass.kt 91.22% <91.66%> (-0.08%) ⬇️

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 fcd9c48...71393c3. Read the comment docs.

@schalkms schalkms added this to the 1.21.0 milestone May 27, 2022
@schalkms schalkms merged commit 2f5b8f5 into detekt:main May 29, 2022
@dzirbel dzirbel deleted the unnecessaryInnerClassLabels branch May 29, 2022 22:12
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.

None yet

2 participants