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

Implemented #523 - open function option FunctionOnlyReturningConstant #524

Merged
merged 3 commits into from Oct 30, 2017
Merged

Implemented #523 - open function option FunctionOnlyReturningConstant #524

merged 3 commits into from Oct 30, 2017

Conversation

schalkms
Copy link
Member

No description provided.


fun KtModifierListOwner.isOpen() = hasModifier(KtTokens.OPEN_KEYWORD)

fun KtModifierListOwner.isPublic(): Boolean {
Copy link
Member

Choose a reason for hiding this comment

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

I think we could refactor this to isPrivate and where its used negate it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not quite sure if I understood you correctly.
!isPrivate() is also true for ‘protected’ and ‘internal’

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree that isPublic is not fully correct as a method name as it checks for much more

Copy link
Member

Choose a reason for hiding this comment

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

I mean that this method effectively just tests if the modifier is not private. I think it is just used once and if we change the code on that line to !isPrivate, we can delete this method.

Copy link
Member Author

Choose a reason for hiding this comment

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

isPublic() is used 6 times.
The method checks if the modifier is not

  • private
  • protected
  • internal


fun KtModifierListOwner.isOpen() = hasModifier(KtTokens.OPEN_KEYWORD)

fun KtModifierListOwner.isPublic(): Boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree that isPublic is not fully correct as a method name as it checks for much more

@@ -24,8 +25,7 @@ class RedundantVisibilityModifierRule(config: Config = Config.empty) : Rule(conf
private val classVisitor = ClassVisitor()
private val childrenVisitor = ChildrenVisitor()

private fun KtModifierListOwner.isExplicitlyPublicNotOverridden() = isExplicitlyPublic()
&& !this.hasModifier(KtTokens.OVERRIDE_KEYWORD)
private fun KtModifierListOwner.isExplicitlyPublicNotOverridden() = isExplicitlyPublic() && !isOverridden()

private fun KtModifierListOwner.isExplicitlyPublic() = this.hasModifier(KtTokens.PUBLIC_KEYWORD)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd move this to the new file with extensions as well. This is the true isPublic method

@arturbosch arturbosch merged commit 66ad660 into detekt:master Oct 30, 2017
@arturbosch arturbosch added this to the RC5-3 milestone Oct 30, 2017
@schalkms schalkms deleted the feature-514 branch November 2, 2017 17:00
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.

None yet

3 participants