Skip to content

Add S1845 recipe: members differing only by capitalization#830

Merged
timtebeek merged 4 commits intomainfrom
member-name-case-insensitive-duplicates
Mar 16, 2026
Merged

Add S1845 recipe: members differing only by capitalization#830
timtebeek merged 4 commits intomainfrom
member-name-case-insensitive-duplicates

Conversation

@timtebeek
Copy link
Member

Summary

  • Adds a new detection-only recipe MemberNameCaseInsensitiveDuplicates implementing SonarQube rule RSPEC-S1845
  • Flags fields and methods whose names differ only by capitalization from other members in the same class or its parent/interface hierarchy
  • Marks conflicting declarations with SearchResult.found() since there's no way to automatically determine which name is correct
  • Does not flag members that exactly match an inherited name (i.e., valid overrides/shadows are excluded)

Test plan

  • Field in child class differs from field in parent by case only
  • Field vs field in same class differing by case
  • Method vs method in same class differing by case
  • Field in class vs method in parent differing by case
  • Method in class vs method in interface differing by case
  • No change when names are completely different
  • No change when names are identical (exact match)
  • No change when overriding a method (same name, same case)

Detection-only recipe that flags fields and methods whose names differ
only by capitalization from other members in the same class or its
parent hierarchy (RSPEC-S1845).
@timtebeek timtebeek marked this pull request as ready for review March 16, 2026 18:48
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Mar 16, 2026
- Extract message string to a static constant
- Include java.lang.Object members in inherited name collection
- Filter out private members/methods from inherited types
- Add tests for Object method conflicts and private parent members
@timtebeek timtebeek merged commit 41789d1 into main Mar 16, 2026
1 check passed
@timtebeek timtebeek deleted the member-name-case-insensitive-duplicates branch March 16, 2026 21:33
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants