Skip to content

Conversation

@SohamBhoyar
Copy link

Issue: #17839

Description
This Pull Request updates the regular expression used by the MethodNameCheck when configured with the Google Style naming convention.

The original Google Style regex did not permit method names containing underscores (_) even when those underscores were used purely to separate numeric suffixes, which is common practice for library or version identifiers (e.g., in utility methods like gradle_9_5_1 or jdk_9_0_392).

The update to the regex allows method names to contain numeric segments separated by underscores, specifically catering to these versioning suffixes while maintaining the overall strictness of the Google naming convention.

Rationale
This change resolves false-positive violations when checking code that follows the standard practice of including external version identifiers (which often contain underscores and numbers) within method names for clarity.

Changes Made
MethodNameCheck.java: Modified the default MethodName pattern when style=google is set to include the necessary exceptions for numeric suffixes.

MethodNameCheckTest.java: Added a new test case, testUnderscoreFalseNegatives, which uses InputGoogleStyleUnderscore.java to verify that method names like gradle_9_5_1 and testing_01231 no longer cause violations with the updated regex.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read and watch videos at Starting_Development.
Please make CI green.

/** Creates a new {@code MethodNameCheck} instance. */
public MethodNameCheck() {
super("^[a-z][a-zA-Z0-9]*$");
super("^[a-z][a-zA-Z0-9]*(_[0-9]+)*$");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change should be in google_checks.xml , not in Check class.
The default value should not be changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants