Issue #18494: Add GoogleNonConstantFieldNameCheck for Google Java Style compliance#18657
Issue #18494: Add GoogleNonConstantFieldNameCheck for Google Java Style compliance#18657vivek-0509 wants to merge 1 commit intocheckstyle:masterfrom
Conversation
|
GitHub, generate report |
|
Github, generate site |
|
Report generation failed on phase "make_report", |
2508be9 to
0621ade
Compare
|
GitHub, generate report |
|
Hey @romani, I have reviewed the diff report all are genuine violations. |
0621ade to
649199d
Compare
|
Diff report is very huge hard to get actual diff. |
|
GitHub, generate report |
|
Hi @romani , I have generated a comparison diff report. I have overridden the messages to be identical. Here is the report https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/649199d_2026065114/reports/diff/index.html. Please let me know if I have understood your request correctly or if any changes are needed. |
|
diff is still wild. |
|
GitHub, generate report |
|
@romani I updated the configurations to use the same id for both checks, but they still appear as Red/Green pairs. It seems the report tool uses the full Check class name for the rule name, so MemberName and GoogleMemberName are treated as different rules despite the shared ID. Am I missing something? |
|
@romani When an explicit id is set in the config, the ID is appended to the class name in the format ClassName#id ( the fix can be that, If source contains # (indicating an explicit module ID was set), compare only the portion after # instead of the full string. This would allow proper matching of violations from different checks that share the same ID, and the diff report would show only true behavioral differences. |
|
tools is right, we tried to hack it, but tool is right in it behavior to show diff. |
|
so, we can look at diff and see why we have more violations that it used to be. https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/649199d_2026150917/reports/diff/elasticsearch/index.html#A1 google state that type immutability if critical point in decision. Checkstyle is not type aware, we can not make decision if it is immutable or not. So better to not give violation. |
|
Understood, will change the scope to skip all static fields and update the issue accordingly. |
649199d to
f342244
Compare
|
GitHub, generate report |
|
@romani updated the scope for the check to skip static member names |
| * for word boundaries.</li> | ||
| * <li>Underscores may be used to separate adjacent numbers (e.g., version | ||
| * numbers like {@code guava33_4_5}), but NOT between letters and digits.</li> | ||
| * </ul> |
There was a problem hiding this comment.
we need to mention that static fields are skipped, as Chckstyle not able to make sure that used type is immutable.
| * @since 13.1.0 | ||
| */ | ||
| @StatelessCheck | ||
| public class GoogleMemberNameCheck extends AbstractCheck { |
There was a problem hiding this comment.
Checks that member names conform to the
Google Java Style Guide for non-constant field naming.
hmm, why we named it GoogleMemberNameCheck ?
as it should be GoogleNonConstantFieldNameCheck.
and it will make it clear why we have limitation on static.
f342244 to
4024f27
Compare
0bb782c to
3bf4c23
Compare
|
GitHub, generate website |
|
@Zopsss All the changes done please review |
| class Example2 { | ||
|
|
||
| static final int STATIC_FINAL = 0; | ||
| private static final int Invalid_Name = 1; |
There was a problem hiding this comment.
please correct the variable name. It is static final so it doesn't throw any violation.
| * @param ast the VARIABLE_DEF AST node | ||
| * @return true if this variable should be checked | ||
| */ | ||
| private static boolean mustCheckName(DetailAST ast) { |
There was a problem hiding this comment.
please rename this method to shouldCheckFieldName
| if (INVALID_UNDERSCORE_PATTERN.matcher(fieldName).find()) { | ||
| log(nameAst, MSG_KEY_INVALID_UNDERSCORE, fieldName); | ||
| } | ||
| else { | ||
| final String nameWithoutNumberingSuffix = NUMBERING_SUFFIX_PATTERN | ||
| .matcher(fieldName).replaceAll(""); | ||
| if (!NON_CONSTANT_FIELD_NAME_PATTERN.matcher(nameWithoutNumberingSuffix).matches()) { | ||
| log(nameAst, MSG_KEY_INVALID_FORMAT, fieldName); | ||
| } |
There was a problem hiding this comment.
here we are using if/else condition.
If there is a variable like aTest_Test_09_90 then on the first pass it will log violation for invalid underscore, then user will run CS again and it will log violation for invalid non constant field name.
User will need to run CS 2 times.
The user should be able to solve all problems in one go, for that all violations should be logged in the first pass.
There was a problem hiding this comment.
Sure, I will use a single message and will simplify the method, the message would be
Non-constant field name ''{0}'' must start lowercase, be at least 2 chars, avoid single lowercase letter followed by uppercase, contain only letters, digits or underscores, with underscores allowed only between adjacent digits.
This way, when a name fails validation, the user sees all the rules that are enforced and can fix everything in one go.
…e Java Style compliance
3bf4c23 to
60f0289
Compare
|
GitHub, generate website |
|
GitHub, generate report |
|
@Zopsss All the changes are done please review |
|
@Zopsss Ping |
|
@vivek-0509 There is different number of violations in old diff report ( where we had multiple violation messages ) and the latest diff report ( where we have only one violation message ) Old report: https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/0bb782c_2026121113/reports/diff/index.html Latest Report: https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/60f0289_2026020714/reports/diff/index.html HBase & openjdk25's violation messages numbers do not match. Can you investigate why this happened? And did we introduced any false-positive/negative with new changes? |
|
@Zopsss I also noticed this change. However, there are no logical changes or modifications to the regex. We only consolidated the if else blocks into a single condition while preserving the same logic in the check class. I re-reviewed the diff report after the changes with this in mind and did not find any false positives. Since we fetch the latest code, the increase in violations appears to be due to new files added to the codebase that already contain these violations. In the diff report, the difference is observed for Checkstyle and OpenJDK, while HBase still shows the same number of violations. |
|
@Zopsss In new report there are 721 files checked So the new files also has violations that our check flagged due to which we see increased in the violation number. Same case with openJDK there also 2 files increased which lead to increase in the violation number |
|
For Checkstyle, I found a new file named Link to one of the new files in the new diff report |
|
@vivek-0509 if you have extra time, thne can you also check reason behind extra violations in openjdk? If you're not able to then it's also fine. |
1 similar comment
|
@vivek-0509 if you have extra time, thne can you also check reason behind extra violations in openjdk? If you're not able to then it's also fine. |
|
@Zopsss |
|
|
Zopsss
left a comment
There was a problem hiding this comment.
Really sorry for all the delays, everything looks fine now. Thanks a lot for all the hardwork!!!!
|
@Zopsss Thankyou very much for reviewing |
|
@romani PR is waiting for your approval. |
|
GitHub, generate report |
|
GitHub, generate website |






Adds GoogleNonConstantFieldNameCheck to enforce non-constant field naming per Google Java Style Guide §5.2.5.
Part of #17842
Detailed Issue at #18494
Rules Enforced
f)mValue,sCount)guava33_4_5)Scope
Diff Regression config: https://gist.githubusercontent.com/vivek-0509/36cbe7f3789730951f15e7b6d551c6f3/raw/7ac2050528756f02e9952ae546a9c1e8cfed29c0/base_config.xml
Diff Regression patch config: https://gist.githubusercontent.com/vivek-0509/a979757b15933ce44f9b0f676a038195/raw/77433e7a8e91c9d621be184f4efcb829cb12d868/patch_config.xml
Contirbution repo PR: checkstyle/contribution#1021