Issue #17841: Add GoogleMethodNameCheck to fix method name false nega…#18312
Issue #17841: Add GoogleMethodNameCheck to fix method name false nega…#18312vivek-0509 wants to merge 2 commits intocheckstyle:masterfrom
Conversation
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 . |
| @@ -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.
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.
please create separate messages for all the logs which should explain the reason behind the violation.
There was a problem hiding this comment.
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.
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.
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.
|
GitHub, generate report |
|
GitHub, generate report |
Hello @romani. Yes I think I can support this. Does that mean I need to use some nightly build of Checkstyle or will there be a stable release with this rule? |
|
@romani Please guide how should we proceed. |
9c553bb to
6dcfec9
Compare
|
GitHub, generate report |
|
GitHub, generate website |
6dcfec9 to
227d5fd
Compare
|
@romani CI failures are unrelated |
|
@romani Updated the example for this also to keep only the relevant part of the violation message |
227d5fd to
8d4b3a3
Compare
|
@romani Updated the XpathRegressionTest for this also to have atleast 3 tests with different structure.. |
8d4b3a3 to
b53a863
Compare
|
Rebased and resolved all the merge conflicts, no other changes |
66fa452 to
bcfdfca
Compare
bcfdfca to
f4edc30
Compare
|
Updated the version to 13.4.0, i was getting the spell check ci failure with the diff to add |
|
@Zopsss @romani the PR is related to Google Style project.. |
part of Issue: #17841
Issue: #18420
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.
Diff Regression config: https://gist.githubusercontent.com/vivek-0509/3c0bc74332fbdb3a6ce4aef1c43d2f6b/raw/a7d36ba756226bac0e01e9148dc8bd7f3016ec96/base_config.xml
Diff Regression patch config: https://gist.githubusercontent.com/vivek-0509/a2777cd3e2a86dc84c549268d6651aa0/raw/6490530b3efb4213b7a2421dace6f157c7b264a2/patch_config.xml
Contirbution repo PR: checkstyle/contribution#1000