Skip to content

New Check: GoogleNonConstantFieldNameCheck to enforce Google Java Style Guide member naming #18494

@vivek-0509

Description

@vivek-0509

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:

  1. Correctly enforce Google-specific underscore placement rules
  2. Support multipart numeric version suffixes (for example guava33_4_5)
  3. 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:

  • Instance 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions