SONARJAVA-6482 Change number of issues raised for S5786 to one per class#5685
Conversation
bbd6182 to
660de09
Compare
| String description = modifiers.size() == 1 | ||
| ? String.format(MODIFIER_MESSAGE, modifiers.get(0).keyword().text()) |
There was a problem hiding this comment.
💡 Quality: Inconsistent single-modifier quick-fix wording between S5786 and S5810
For the single-modifier removal quick fix, S5786 now uses the description String.format(MODIFIER_MESSAGE, ...) → "Remove this 'protected' modifier." (JUnit5DefaultPackageClassAndMethodCheck.java:116-117), while S5810 still uses JavaQuickFix.newQuickFix("Remove "%s" modifier", ...) → "Remove "protected" modifier" (JUnit5SilentlyIgnoreClassAndMethodCheck.java:107). These two closely-related rules now present differently-worded quick-fix labels for what is the same single-modifier removal action. This is purely cosmetic (it does not affect behavior), but aligning the wording would give users a consistent experience across the two test-modifier rules. Consider using the same description string (e.g. the MODIFIER_MESSAGE form) in both checks, or extracting a shared constant.
Was this helpful? React with 👍 / 👎
660de09 to
f59eb2c
Compare
…dant visibility modifiers at once Instead of reporting a separate issue on each noncompliant modifier, the rule now reports a single issue on the class name listing all offending modifiers as secondaries. The quick fix removes all of them in one click. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
f59eb2c to
f05ed3d
Compare
|
rombirli
left a comment
There was a problem hiding this comment.
I’m requesting changes because I don’t understand why these two rules diverged this much, or why the common abstraction was removed.
They still seem to share the same core traversal and JUnit 5 classification logic, so I would expect them to follow the same direction and keep the shared parent class.
Could you either keep the common abstraction, or explain why this level of divergence is necessary?
The other comments are personal preferences and optional.
| <properties> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <maven.compiler.release>21</maven.compiler.release> | ||
| <slf4j.version>1.7.30</slf4j.version> |
| // Handled by S5810 | ||
| public void visitNode(Tree tree) { | ||
| ClassTree classTree = (ClassTree) tree; | ||
| if (classTree.symbol().isAbstract() || (classTree.simpleName() == null)) { |
There was a problem hiding this comment.
redundant parentheses
| if (classTree.symbol().isAbstract() || (classTree.simpleName() == null)) { | |
| if (classTree.symbol().isAbstract() || classTree.simpleName() == null) { |
There was a problem hiding this comment.
A few things are now duplicated :
MODIFIER_MESSAGE, nodesToVisit, UnitTestUtils.groupJUnit5Methods and ClassPatternsUtils.shouldBePublicClass are only used in JUnit5DefaultPackageClassAndMethodCheck and JUnit5SilentlyIgnoreClassAndMethodCheck
IMO it makes sense to keep this superclass even if it only contains a few things.
There was a problem hiding this comment.
I think both rules should follow the same direction here.
S5786 was moved to a bulk quick-fix model, while S5810 still keeps a separate per-issue/per-modifier behavior. In my view, that creates unnecessary divergence between two checks that still share the same core traversal and JUnit 5 classification logic.
I would prefer:
- keeping AbstractJUnit5NotCompliantModifierChecker with the shared visit / grouping / class-handling logic;
- aligning S5810 with S5786 on the reporting model, with a bulk quick fix for the noncompliant modifiers in the same test class.
The shared abstraction still looks valid to me, and keeping it would make future changes safer.
There was a problem hiding this comment.
Was clarified in Slack discussion.
rombirli
left a comment
There was a problem hiding this comment.
Approved after discussion on why these two rules need to diverge for business reasons.
Code Review 👍 Approved with suggestions 3 resolved / 4 findingsRefactors S5786 to report a single issue per class with a consolidated quick fix, addressing several issues including missing file newlines and test coverage. Consider aligning the quick-fix description with S5810 for consistent messaging. 💡 Quality: Inconsistent single-modifier quick-fix wording between S5786 and S5810📄 java-checks/src/main/java/org/sonar/java/checks/tests/JUnit5DefaultPackageClassAndMethodCheck.java:116-117 📄 java-checks/src/main/java/org/sonar/java/checks/tests/JUnit5SilentlyIgnoreClassAndMethodCheck.java:107 For the single-modifier removal quick fix, S5786 now uses the description ✅ 3 resolved✅ Quality: Missing newline at end of JUnit5SilentlyIgnoreClassAndMethodCheck.java
✅ Edge Case: No test for merged class+method modifier quick fix
✅ Quality: Developer-specific absolute path committed in command doc
🤖 Prompt for agentsOptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |




Instead of reporting a separate issue on each noncompliant modifier, the rule
now reports a single issue on the class name listing all offending modifiers as
secondaries. The quick fix removes all of them in one click.
See SONARJAVA-6482.