Issue #18494: Add GoogleNonConstantFieldNameCheck for Google Java Style compliance#18657
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 |
f342244 to
4024f27
Compare
|
@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 |
|
@romani Let me know if any changes are needed ... |
| * @return true if this variable should be checked | ||
| */ | ||
| private static boolean shouldCheckFieldName(DetailAST ast) { | ||
| final DetailAST modifiersAST = NullUtil.notNull(ast.findFirstToken(TokenTypes.MODIFIERS)); |
There was a problem hiding this comment.
why we think that modifiers always exists?
they defineterly not present always in code, is this our AST feature to have always this node , even it is empty ?
There was a problem hiding this comment.
Yes, modifiers is always present in the AST for VARIABLE_DEF nodes, even when no modifiers are explicitly written in code (e.g., int x; still has an empty MODIFIERS node). This is a Checkstyle AST feature. Existing checks like MemberNameCheck, ConstantNameCheck all use ast.findFirstToken(TokenTypes.MODIFIERS) directly without null checks.
https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#MODIFIERS
There was a problem hiding this comment.
I thinks awesome knowledge, please create special method getModifiers(ast) in this Check and put this init javadoc, eventually this method will be moved to some util, no need to do this now.
60f0289 to
40d2c54
Compare
|
GitHub, generate report |
|
GitHub, generate website |
|
@romani All the changes done PR is ready for review |
| final List<String> expectedXpathQueries = List.of( | ||
| "/COMPILATION_UNIT/CLASS_DEF" | ||
| + "[./IDENT[@text='InputXpathGoogleNonConstantFieldNameSingleChar']]" | ||
| + "/OBJBLOCK/VARIABLE_DEF/IDENT[@text='a']" |
There was a problem hiding this comment.
All 3 examples should be different by Xpath structure.
Please make: as filed of class, as field of inner interface, as filed of inner record or anonymous class.
There was a problem hiding this comment.
Used class inside interface for input3 since interface fields are implicitly public static final and can't produce violations and used anonymous class for input3.
|
|
||
| public final int httpClient = 0; | ||
| public final int mValue = 0; | ||
| // violation above, 'avoid single lowercase letter followed by uppercase' |
There was a problem hiding this comment.
public final int myValue = 0;
public final int mValue = 0;
line above shows a suggested fix for line with violation.
| private final int f = 0; // violation, 'be at least 2 chars' | ||
|
|
||
| protected final int fooBar1_1 = 0; | ||
| protected final int foo_bar = 0; |
There was a problem hiding this comment.
protected final int fooBar = 0;
protected final int foo_bar = 0;
apply same for all others.
40d2c54 to
d049a65
Compare
|
GitHub, generate website |
…e Java Style compliance
d049a65 to
024ed2e
Compare
|
GitHub, generate website |
|
@romani PR is ready for review |
romani
left a comment
There was a problem hiding this comment.
Thanks a lot for hard work on this module
Please start activation Google style of it


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