Fix: Corrected Google Style MethodNameCheck to allow numeric suffixes… #17864
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.