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

Refactor ObjectPropertyNaming #1026

Merged
merged 1 commit into from
Aug 6, 2018
Merged

Refactor ObjectPropertyNaming #1026

merged 1 commit into from
Aug 6, 2018

Conversation

scottkennedy
Copy link
Contributor

This adds a privatePropertyPattern and much more closely matches the
code in TopLevelPropertyNaming. They may be able to share a base class (or be merged into one) in the future.

Copy link
Member

@schalkms schalkms left a comment

Choose a reason for hiding this comment

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

Good! I am fine with the fine-grained approach you have taken.

}
}

private fun doesNotMatchPattern(element: KtVariableDeclaration, pattern: Regex) =
!element.identifierName().matches(pattern)
private fun handleProperty(property: KtProperty) {
Copy link
Member

Choose a reason for hiding this comment

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

Good refactoring!

message = "Private object property names should match the pattern: $privatePropertyPattern"))
}
} else {
if (!property.identifierName().matches(propertyPattern)) {
Copy link
Member

@schalkms schalkms Jul 31, 2018

Choose a reason for hiding this comment

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

else if (condition) {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I literally copied this code from TopLevelPropertyNaming. I'm happy to make this change, but I'll probably make it there too to keep it consistent.

Copy link
Member

Choose a reason for hiding this comment

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

No worries..

@@ -87,7 +88,6 @@ class ObjectPropertyNamingSpec : SubjectSpek<ObjectPropertyNaming>({
val code = compileContentForTest("""
object O {
val _nAme = "Artur"
private val _name = "Artur"
}
""")
assertThat(subject.lint(code)).hasSize(2)
Copy link
Member

@schalkms schalkms Jul 31, 2018

Choose a reason for hiding this comment

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

Why does this test snippet report 2 violations?
It should only report 1 for the variable _nAme.
I suppose there's is an error in the rule implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. I changed the test to 1, and it still passed. I'm not convinced the test is actually running 😕

This adds a privatePropertyPattern and much more closely matches the
code in TopLevelPropertyNaming.
}
""")
assertThat(subject.lint(code)).hasSize(2)
assertThat(subject.lint(code)).hasSize(1)
Copy link
Member

Choose a reason for hiding this comment

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

@scottkennedy what did you change to only report 1 violation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because there's only one property in the object now. I believe 1 is correct.

However, it wasn't failing the test when it was 2, and it's not failing now that it's 1, so I don't think the test is working.

Copy link
Member

@schalkms schalkms Jul 31, 2018

Choose a reason for hiding this comment

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

I checked out your branch on my machine. Running the tests in IntelliJ does work. However it doesn't when using the CLI.

@arturbosch arturbosch merged commit 847149b into detekt:master Aug 6, 2018
@arturbosch arturbosch added this to the RC9 milestone Sep 10, 2018
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