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

Don't flag inherited visibility in NestedClassesVisibility #2261

Merged
merged 4 commits into from
Jan 19, 2020
Merged

Don't flag inherited visibility in NestedClassesVisibility #2261

merged 4 commits into from
Jan 19, 2020

Conversation

schalkms
Copy link
Member

The rule had an issue that it forced the use of an additional
unnecessary modifier. However, the visibility of nested classes is
inherited from the parent class.
These nested classes can't have a higher visibility than their parent.
The following example outlines the issue.

internal class A1 { // non-compliant
class B
}
internal class A2 { // compliant
internal class B
}

Closes #1930

The rule had an issue that it forced the use of an additional
unnecessary modifier. However, the visibility of nested classes is
inherited from the parent class.
These nested classes can't have a higher visibility than their parent.
The following example outlines the issue.

internal class A1 { // non-compliant
  class B
}
internal class A2 { // compliant
  internal class B
}

Closes #1930
@codecov-io
Copy link

codecov-io commented Jan 16, 2020

Codecov Report

Merging #2261 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2261      +/-   ##
============================================
- Coverage     81.45%   81.42%   -0.03%     
+ Complexity     2114     2113       -1     
============================================
  Files           349      349              
  Lines          6054     6051       -3     
  Branches       1106     1106              
============================================
- Hits           4931     4927       -4     
  Misses          532      532              
- Partials        591      592       +1
Impacted Files Coverage Δ Complexity Δ
...osch/detekt/rules/style/NestedClassesVisibility.kt 83.33% <100%> (-10%) 14 <0> (-1)

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 a517db9...9a48c1a. Read the comment docs.

@BraisGabin
Copy link
Member

If we want that this rule detects the misleading modifiers we should check the private classes with public or internal classes too.

@schalkms
Copy link
Member Author

schalkms commented Jan 17, 2020

@BraisGabin Agreed. Please open a new issue for that. This should be done in a separate PR though.

@arturbosch arturbosch merged commit 368d380 into detekt:master Jan 19, 2020
@arturbosch arturbosch added this to the 1.5.0 milestone Jan 19, 2020
@schalkms schalkms deleted the #1930-NestedClassesVisibility branch January 27, 2020 19:21
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.

NestedClassesVisibility(False negative): Nested class doesn't inherit visibility from parent
4 participants