split from #17842 , we split creation of module and activation of it in google style config to separate issues, to simplify integration.
Create a new check GoogleNonConstantFieldNameCheck to enforce non-constant field naming conventions per the Google Java Style Guide §5.2.5.
Background (Reason for new check)
The current MemberName check with regex configuration cannot fully enforce Google Style non-constant field naming rules because it cannot:
- Correctly enforce Google-specific underscore placement rules
- Support multipart numeric version suffixes (for example guava33_4_5)
- Reject special-prefix (Hungarian-style) names such as mValue
Proposed Rules (Non-constant fields only)
- Field names must follow lowerCamelCase
- Single-character field names are not allowed
- Special prefix names (for example mValue, sCount, kSize) are not allowed, per Google Java Style Guide §5.1
- Underscores are allowed only between adjacent digits (multipart version or numbering suffix)
- Leading, trailing or double underscores are not allowed
Scope
This check applies only to non-constant fields:
Explicitly out of scope
- Constant fields (static final)
- Local variables
- static fields that are not static final
Examples
Valid:
userName
timeoutMs
foo123
guava33_4_5
kotlinVersion1_9_24
Invalid:
f // violation, single character
mValue // violation,special prefix not allowed
sCount // violation, special prefix not allowed
foo_bar // violation, underscore between letters
gradle_9_5_1 // violation, underscore between letter-digit
kotlin_version1_9_24 // violation, underscore between letters
guava_33_4_5 // violation, underscore between letter-digit
guava33__4_5 // violation, consecutive underscores
guava33_4_5_ // violation, trailing underscore
_foo // violation, leading underscore
split from #17842 , we split creation of module and activation of it in google style config to separate issues, to simplify integration.
Create a new check GoogleNonConstantFieldNameCheck to enforce non-constant field naming conventions per the Google Java Style Guide §5.2.5.
Background (Reason for new check)
The current MemberName check with regex configuration cannot fully enforce Google Style non-constant field naming rules because it cannot:
Proposed Rules (Non-constant fields only)
Scope
This check applies only to non-constant fields:
Explicitly out of scope
Examples
Valid:
Invalid: