-
-
Notifications
You must be signed in to change notification settings - Fork 757
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
Refactor ObjectPropertyNaming #1026
Conversation
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else if (condition) {}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.