-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Issue #17841: Add GoogleMethodNameCheck to fix method name false nega… #18312
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
base: master
Are you sure you want to change the base?
Issue #17841: Add GoogleMethodNameCheck to fix method name false nega… #18312
Conversation
…false negatives
304a1ac to
2f3db4a
Compare
|
The CI Failures are unrelated |
|
Github, generate report for GoogleMethodName/all-examples-in-one |
|
Failed to download or process the specified configuration(s).
|
|
GitHub, generate report |
2 similar comments
|
GitHub, generate report |
|
GitHub, generate report |
|
Report generation failed on phase "make_report", |
|
GitHub, generate report |
|
Hey @romani, Bug Found (Will Fix)Issue: Test methods with numbering suffix like Cause: The implementation doesn't strip numbering suffix before validating test methods (unlike regular methods). Examples:
Fix: Will add numbering suffix stripping + Design Questions - Need Your Input1. Minimum 2-character segment requirement for test methodsCurrently rejects single lowercase character segments: Examples:
Real example: Question: Should we keep the current 2-character minimum requirement, or should we make it stricter by requiring proper lowerCamelCase (at least 2 words joined with capitalization) for each segment in test method names? 2. Test methods without @test annotationExamples:
Supported annotations: Question: Should test-style method names without annotations be rejected, as Google Style only mentions JUnit tests? |
|
@romani ping |
|
@Zopsss , can you help me to review this PR? |
|
Will fix the CI asap , failures caused due to recent pr merge method access level for getPackageLocation() changed to pubilc |
|
Hi @Zopsss , Before you review the code, I'd like to clarify my understanding of the expected rules for GoogleMethodNameCheck , as Google Style Guide is somewhat ambiguous in places. For regular methods (without For test methods (with One thing I'm unclear about: Google Style says test components should be "lowerCamelCase". Strictly speaking, lowerCamelCase means multiple words joined with capitalization (like transferMoney). Should single-word components like test_foo be valid, or should we require multi-word lowerCamelCase like transferMoney_deductsFromSource? If any of my expectations don't align with what's actually required, please let me know and I'll adjust my implementation before you do a full code review. This should save time . |
src/main/java/com/puppycrawl/tools/checkstyle/checks/naming/GoogleMethodNameCheck.java
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/checks/naming/GoogleMethodNameCheck.java
Show resolved
Hide resolved
| @@ -1,4 +1,5 @@ | |||
| abbreviation.as.word=Abbreviation in name ''{0}'' must contain no more than ''{1}'' consecutive capital letters. | |||
| google.method.name=Method name ''{0}'' is not valid per Google Java Style Guide. | |||
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.
this message does not explain why the method name is invalid. Instead we should keep different messages for the different conditions we hit to easily explain reason behind violation to the user.
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.
please create separate messages for all the logs which should explain the reason behind the 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.
For the separate violation messages, I'm planning to add 4 messages (one per log point):
google.method.name.underscore.regular=Method name ''{0}'' has invalid underscore usage, underscores only allowed between adjacent digits.
google.method.name.underscore.test=Method name ''{0}'' has invalid underscore usage, underscore only allowed between letters or between digits.
google.method.name.format.regular=Method name ''{0}'' must be lowerCamelCase: start with lowercase, at least 2 characters, and avoid single lowercase followed by uppercase.
google.method.name.format.test=Method name ''{0}'' is not valid: each segment must be lowerCamelCase: start lowercase, min 2 chars, avoid single lowercase followed by uppercase.
Does this approach work for you?
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.
google.method.name.underscore.test=Method name ''{0}'' has invalid underscore usage, underscore only allowed between letters or between digits.
this one is for the test methods, so it should mention that it is for test methods.
google.method.name.format.regular=Method name ''{0}'' must be lowerCamelCase: start with lowercase, at least 2 characters, and avoid single lowercase followed by uppercase.
google.method.name.format.test=Method name ''{0}'' is not valid: each segment must be lowerCamelCase: start lowercase, min 2 chars, avoid single lowercase followed by uppercase.
it should end with: avoid single lowercase followed by uppercase or underscore.
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.
it should end with: avoid single lowercase followed by uppercase or underscore.
but this still falls under invalid underscore usage, for example, f_ is not permitted because valid underscore usage is restricted to letter–letter or digit–digit only.
and for this case test_a message already mentions the min 2-chars required for each segment.
src/main/java/com/puppycrawl/tools/checkstyle/checks/naming/GoogleMethodNameCheck.java
Show resolved
Hide resolved
|
GitHub, generate report |
|
GitHub, generate report |
|
GitHub, generate report |
Issue: #17841
Description
Introduces a new
GoogleMethodNamecheck that properly validates method names according to the Google Java Style Guide, fixing false-negatives where underscores between letters and digits were not being flagged.Problem
The previous
MethodNamecheck failed to detect invalid names like:gradle_9_5_1()- underscore between letter 'e' and digit '9'jdk_9_0_392()- underscore between letter 'k' and digit '9'Solution
Created a dedicated
GoogleMethodNamecheck that:@Testmethods separately (underscores allowed)guava33_4_5is valid)Validation Rules
Regular Methods:
_4_5)gradle_9invalid)Test Methods (
@Test,@ParameterizedTest,@RepeatedTest):Override Methods:
@Overrideannotation are skipped (no validation)Breaking Changes
None. This check is backward compatible with the previous MethodName regex behavior.
New module config: https://gist.githubusercontent.com/vivek-0509/6733c4a828cc940c59db1c7af371a806/raw/4758b044822977e75ba30138eefa3a9b3c2026f7/google-method-name.xml
Contirbution repo PR: checkstyle/contribution#1000