Batch-fix all issues for a single rule across the codebase
When to use: Sonar flagged 47 instances of the same rule and you'd rather fix them all in one PR.
Prerequisites
- Sonar token — User → Security → Generate Token (project-scoped if possible)
- Docker available — Standard docker setup; image is pulled on first run
Flow
-
Identify the ruleUse sonarqube-mcp. Top 5 rules by open-issue count in project 'foo'.✓ Copied→ Rule key + count + severity
-
Pull all instances of oneList every open issue for rule java:S2293 (Use Diamond Operator) — file, line, snippet.✓ Copied→ 47 issues with file:line and surrounding code
-
Apply the fixFor each, apply the rule's recommended fix. Keep changes minimal; don't reformat.✓ Copied→ 47 small edits across ~20 files
-
Re-scan to verifyAfter my CI runs the next analysis, recheck the issue count for that rule.✓ Copied→ Count drops to 0
Outcome: One focused PR closing a whole rule, instead of 47 scattered fix commits.
Pitfalls
- Rule auto-fix breaks generated code — Filter by directory; skip generated/test paths or audit those manually