Repository navigation
SONARJAVA-7054: Reduce S9397 scope to short format strings without brackets or backticks - #6227
Conversation
…ckets or quotes
Limit the rule to format strings shorter than 15 characters and exclude
cases where %s markers appear inside unclosed brackets {}()[] or between
single quotes.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
67b6fb6 to
2558149
Compare
This comment has been minimized.
This comment has been minimized.
… coverage Rewrite the method to use a while-loop with if/else-if chains instead of a for-loop with multiple continue statements. Extract helper methods to reduce cognitive complexity. Add test cases for edge cases (unmatched closing brackets, escaped percents in backticks, nested brackets, backtick sections without placeholders). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
🤖 Generated with GitHub Actions
|
❌ Ruling needs updating. A fix PR has been created: #6229 Please review and merge it into your branch. |
Ruling Diff SummaryDetected changes in 5 rule files: 396 issues removed, 0 issues added. S9397 (
|
|
❌ Ruling needs updating. A fix PR has been created: #6230 Please review and merge it into your branch. |
Replace loop counter manipulation with an afterPercent flag to avoid modifying the loop variable inside the body (S127). Inline the isEnclosedPlaceholder helper to reduce method count and cognitive complexity (S3776). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
❌ Ruling needs updating. A fix PR has been created: #6230 Please review and merge it into your branch. |
Extend hasPlaceholderInBracketsOrQuotes to treat single quotes and double quotes the same as backticks, so that format strings like '%s' are considered compliant. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
❌ Ruling needs updating. A fix PR has been created: #6231 Please review and merge it into your branch. |
nathsou
left a comment
There was a problem hiding this comment.
The new quote handling still needs to distinguish a quoted range from an apostrophe in ordinary text.
Refactor hasPlaceholderInBracketsOrQuotes to properly distinguish apostrophes from quoted ranges: only suppress when %s lies between matching quote delimiters. Also fixes %%s handling and removes unreachable double-quote branch to resolve SonarQube issues. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Addressed review feedback in 9b3dbb1: refactored |
nathsou
left a comment
There was a problem hiding this comment.
The possessive cases are fixed. One quote-pairing case still suppresses a placeholder outside both quoted spans.
nathsou
left a comment
There was a problem hiding this comment.
Approved. I left an inline comment on the remaining quote-pairing edge case.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
❌ Ruling needs updating. A fix PR has been created: #6231 Please review and merge it into your branch. |
Convert for-loops with internal counter mutations to while-loops in hasPlaceholderInBrackets, hasPlaceholderInMatchingQuotes, and containsPlaceholder to resolve S127 (loop counter assigned from within loop body) violations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…lar-to-main-small Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Code Review ✅ Approved 5 closed / 5 findings🟡 Medium risk · The rule now skips longer or delimited format strings, changing issue detection. Reduces S9397 scope to short format strings without brackets or backticks by excluding ✅ 5 closed✅ Edge Case: Bracket/quote scan treats escaped
|
| Auto-apply | Compact |
|
|
Was this helpful? React with 👍 / 👎 | Gitar
|




Summary
String.formatis reasonable%smarkers appear inside unclosed brackets{}()[](e.g.,"{%s}")%smarkers appear between backticks (e.g.,"`%s`")Test plan
hasPlaceholderInBracketsOrQuotesto fix SonarQube quality gate violations (S3776, S127, S135)🤖 Generated with Claude Code
Agent workflow
Tool link: https://github.com/SonarSource/languages-experimental-tooling/tree/romain/my-tickets/personal/romain-brenguier
PR created using
uv run create_with_claude.py /tmp/action_plan_romain/sonarjava-7054.txtPR updated using
uv run update_with_claude.py --prompt "We shouldn't just recognize backtick for rule StringFormatCheck but also quotes, simple and double. Fix this." -a "None" -g "claude"Addressed review comments in pr_report_6227.md using
uv run address_reviews.py pr_report_6227.mdAddressed review comments in pr_report_6227.md using
uv run address_reviews.py pr_report_6227.mdPR created using
uv run create_with_claude.py /tmp/action_plan_romain/sonarjava-7054.txtPR created using
uv run create_with_claude.py /tmp/action_plan_romain/sonarjava-7054.txtIterated on the PR with
uv run ci_loop.pyfor 2 iterations.✔️ The PR is now ready for review.