GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — New Check: GoogleMethodName to fix false-negative on method names with underscores · Issue #17841 · checkstyle/checkstyle

New Check: GoogleMethodName to fix false-negative on method names with underscores #17841

New issue
Copy link
New issue
Copy link
Closed
Closed
New Check: GoogleMethodName to fix false-negative on method names with underscores#17841
Copy link
Labels
approvedgoogle stylenew module
Milestone
13.10.0

Description

@mohitsatr
mohitsatr
opened on Sep 29, 2025
Issue body actions

From: https://google.github.io/styleguide/javaguide.html#s5.3-camel-case

In very rare circumstances (for example, multipart version numbers), you may need to use underscores to separate adjacent numbers, since numbers do not have upper and lower case variants.

Google style is not exact. On one hand it says _ can be used in test methods to combine sentences and on another hand in general CamelCase explanation, _ is allowed for numbering suffix in all names(except package and generic names).

Valid uses of underscore :

1. guava33_4_5
2. guavaVersion33_4_5 
3. guavaversion33_4_5 (same as 1.)

Invalid uses of underscore:

1. guava_33_4_5_ (underscore at the end)
2. guava_33_4_5   (underscore between digit and letter)
3. guava_version33_4_5 (underscore between lowercase character sequences)

Note: Underscores are not allowed in normal method names. Name has to have the numbering format part at the end. Following are all invalid

guava_version
guava_Version
Set_guavaVersion3345

Some false-negatives left to address from #17708

$ cat NamesWithUnderscores.java
/** some javadoc. */
public class NamesWithUnderscores {
  void gradle9_5_1_() {} // Expected violation, _ at the end

  void gradle_9_5_1() {} // Expected violation, _ between digit and letter

  void jdk_9_0_392() {} // Expected violation, _ between digit and letter

  void testing_01231(String str) {} // Expected violation, _ between digit and letter
}
$ java -jar checkstyle-11.1.0-all.jar -c google_checks.xml NamesWithUnderscores.java 
Starting audit...
[WARN] /mnt/5D92528E6B945467/test/testing/NamesWithUnderscores.java:4:8: Method name 'gradle9_5_1_' must match pattern '^(?![a-z]$)(?![a-z][A-Z])[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*(?:_[0-9]+)*$'. [MethodName]
Audit done.

We probably need a better approach than Regex. Current regex has already grown very complex.

checkstyle/src/main/resources/google_checks.xml

Lines 436 to 438 in 5d52248

<module name="MethodName">
<property name="format"
value="^(?![a-z]$)(?![a-z][A-Z])[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*(?:_[0-9]+)*$"/>

if special check is needed, it should first determine the type of name - regular or name with numbering and then it should validate the name against the appropriate regex format, which will differ for each type of naming

Keep in mind: unless it's a non-regular name i.e name that has number formating suffix at the end or method with @Test annotation, underscores are not allowed.

Activity

Next
  1. mohitsatr
    changed the title [-]False-negative: Method names with underscores #17839[/-] [+]False-negative: Method names with underscores[/+] on Sep 29, 2025
  2. romani
    added
    approved
    new module
    google style
    on Sep 29, 2025
  3. romani commented on Sep 29, 2025

    @romani
    romani
    on Sep 29, 2025
    Member
    More actions

    current Check is https://checkstyle.sourceforge.io/checks/naming/methodname.html#MethodName

    we can make GoogleMethodName that has no properties and does exactly what Google need, even treatment of Test annotation can be hardcoded.

    Reacted by rnveach
  4. aryanttripathi commented on Oct 5, 2025

    @aryanttripathi
    aryanttripathi
    on Oct 5, 2025
    Contributor
    More actions

    Hey @mohitsatr @romani Can i work on this issue? I am new to checkstyle and want to contribute in it. Also can you explain a little what changes actually need to made, do we need to break on the basis of conditions?

  5. mohitsatr commented on Oct 5, 2025

    @mohitsatr
    mohitsatr
    on Oct 5, 2025
    MemberAuthor
    More actions

    @Aryant-Tripathi Please start with good xxx issues first.

    Please watch set-up tutorials

    Reacted by Aryant Tripathi
  6. vivek-0509 commented on Dec 14, 2025

    @vivek-0509
    vivek-0509
    on Dec 14, 2025
    Member
    More actions

    I am on it

  7. vivek-0509
    added 2 commits that reference this issue on Dec 15, 2025

    Issue checkstyle#17841: Add GoogleMethodNameCheck to fix method name …

    304a1ac

    Issue checkstyle#17841: Add GoogleMethodNameCheck to fix method name …

    2f3db4a
  8. Zopsss commented on Dec 25, 2025

    @Zopsss
    Zopsss
    on Dec 25, 2025
    Member
    More actions

    @mohitsatr how is this valid?

    void gradle9_5_1_() {} // ok

    This is a similar case to:

    Invalid uses of underscore:
    
    1. guava_33_4_5_ (underscore at the end)
    
    Reacted by Mohit Sharma
  9. Zopsss commented on Dec 25, 2025

    @Zopsss
    Zopsss
    on Dec 25, 2025
    Member
    More actions

    @vivek-0509 Please create a separate issue for this new check, we first need a solid understanding of what all the things this new check should cover. The issue description should cover all the things we can expect from this new check and the reason behind creating it.

  10. mohitsatr commented on Dec 25, 2025

    @mohitsatr
    mohitsatr
    on Dec 25, 2025
    MemberAuthor
    More actions

    @Zopsss, Yes you are right. Fixed

    Reacted by Mauryan Kansara
  11. vivek-0509 commented on Dec 25, 2025

    @vivek-0509
    vivek-0509
    on Dec 25, 2025
    Member
    More actions

    @

    @vivek-0509 Please create a separate issue for this new check, we first need a solid understanding of what all the things this new check should cover. The issue description should cover all the things we can expect from this new check and the reason behind creating it.

    Sure

  12. vivek-0509
    added a commit that references this issue on Dec 30, 2025

    Issue checkstyle#17841: Add GoogleMethodNameCheck to fix method name …

    42dd5c4
  13. 17 remaining items

  14. vivek-0509
    added 4 commits that reference this issue on Feb 28, 2026

    Issue checkstyle#17841: Add GoogleMethodName module to google_checks.xml

    1e8fcd2

    Issue checkstyle#17841: Add GoogleMethodName module to google_checks.xml

    66fa452

    Issue checkstyle#17841: Add GoogleMethodName module to google_checks.xml

    bcfdfca

    Issue checkstyle#17841: Add GoogleMethodName module to google_checks.xml

    f4edc30
  15. Atharv3221
    added 4 commits that reference this issue on Aug 2, 2026

    Issue checkstyle#17841: Add GoogleMethodName to google_checks

    fe3f133

    Issue checkstyle#17841: Add GoogleMethodName to google_checks

    1b370c3

    Issue checkstyle#17841: Add GoogleMethodName to google_checks

    a6f3d02

    Issue checkstyle#17841: Add GoogleMethodName to google_checks

    739e4c8
  16. romani
    added a commit that references this issue on Aug 9, 2026

    Issue #17841: Add GoogleMethodName to google_checks

    b709107
  17. github-actions
    added this to the 13.10.0 milestone on Aug 9, 2026
  18. romani commented on Aug 9, 2026

    @romani
    romani
    on Aug 9, 2026
    Member
    More actions

    new Check is merged and placed to google style config.

  19. romani
    closed this as completedon Aug 9, 2026
  20. romani
    changed the title [-]False-negative: Method names with underscores[/-] [+]Google style: False-negative on Method names with underscores[/+] on Aug 9, 2026
  21. romani
    changed the title [-]Google style: False-negative on Method names with underscores[/-] [+]New Check: GoogleMethodName to fix False-negative on Method names with underscores[/+] on Aug 9, 2026
  22. romani
    changed the title [-]New Check: GoogleMethodName to fix False-negative on Method names with underscores[/-] [+]New Check: GoogleMethodName to fix false-negative on method names with underscores[/+] on Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    approvedgoogle stylenew module

    Type

    No type

    Projects

    No projects

      Milestone

      • 13.10.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.