SONARJAVA-6823: Implemented rule S9356 "continue" should not be used in loops - #5989
SONARJAVA-6823: Implemented rule S9356 "continue" should not be used in loops#5989romainbrenguier wants to merge 2 commits into
Conversation
…in loops Detect every use of the continue statement inside loops (for, for-each, while, do-while), whether labeled or unlabeled. The rule flags continue as a code smell that reduces readability — loops should use inverted conditional logic instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| @@ -0,0 +1,67 @@ | |||
| <p>This rule raises an issue when a statement that skips the rest of the current loop iteration and proceeds to the next iteration is used in a loop, | |||
| including both simple and labeled forms.</p> | |||
| <p>In Java, this specifically refers to the <code>continue</code> statement.</p> | |||
There was a problem hiding this comment.
💡 Quality: Duplicated sentence in S9356.html rule description
The sentence stating that in Java this refers to the continue statement appears twice: line 3 ("In Java, this specifically refers to the continue statement.") and line 20 ("In Java, this refers to the continue statement."). The second occurrence is redundant and should be removed for cleaner documentation.
Was this helpful? React with 👍 / 👎
|
|
❌ Ruling needs updating. A fix PR has been created: #5992 Please review and merge it into your branch. |
| void test() { | ||
| CheckVerifier.newVerifier() | ||
| .onFile(mainCodeSourcesPath("checks/IntegerSubtractionInComparisonCheckSample.java")) | ||
| .withCheck(new IntegerSubtractionInComparisonCheck()) | ||
| .onFile(mainCodeSourcesPath("checks/ContinueInLoopCheckSample.java")) | ||
| .withCheck(new ContinueInLoopCheck()) | ||
| .verifyIssues(); | ||
| } |
There was a problem hiding this comment.
We should also have a test withoutSemantic
Ruling Diff SummaryDetected changes in 4 rule files: 0 issues removed, 296 issues added. S9356 (
|
CI failed: Integration test JavaRulingTest failed due to issue differences in LITS ruling checks after introducing new rule S9356.OverviewAll failing CI jobs encountered test failures in FailuresLITS Ruling Test Failures (confidence: high)
Summary
Code Review 👍 Approved with suggestions 0 resolved / 1 findingsImplements rule S9356 to flag 'continue' statements in loops using an IssuableSubscriptionVisitor. Consider removing the duplicated sentence in the S9356.html rule description. 💡 Quality: Duplicated sentence in S9356.html rule description📄 sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S9356.html:3 📄 sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S9356.html:20 The sentence stating that in Java this refers to the 🤖 Prompt for agentsImplementation Status ✅ 1 / 1 issues implemented✅ SONARJAVA-6823 — 1 / 1 objectivesThe PR successfully implements the S9356 rule prohibiting the use of continue statements in loops, complete with rule definition, unit tests, and sample code. ✅ 1 complete
Tip Comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|
|
❌ Ruling needs updating. A fix PR has been created: #5994 Please review and merge it into your branch. |




Summary
continuestatement inside loops (for, for-each, while, do-while), whether labeled or unlabeledcontinueIssuableSubscriptionVisitorsubscribing toCONTINUE_STATEMENTTest plan
ContinueInLoopCheckTestpasses🤖 Generated with Claude Code