Skip to content

SONARJAVA-7153: Implement S9427 — Java assert statements should not be used in test code - #6322

Merged
romainbrenguier merged 5 commits into
masterfrom
romain/new-rule-s9427-sonarjava-7153
Oct 14, 2026
Merged

romainbrenguier merged 5 commits into
masterfrom
romain/new-rule-s9427-sonarjava-7153

Conversation

@romainbrenguier

@romainbrenguier romainbrenguier commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Implement S9427 to flag Java assert statements in test code.
  • Add rule tests and test samples.
  • Add rule metadata (including the tests tag required for test-only rules) and Sonar way profile registration.

Out of scope

  • A quick fix that replaces assert with framework assertions (assertEquals / assertTrue / assertNull) is not part of this PR and can be done in a follow-up.

Validation

  • GeneratedCheckListTest passes locally.

🤖 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/new-rule-s9427-sonarjava-7153.txt

Iterated on the PR with uv run ci_loop.py for 1 iterations.
✔️ The PR is now ready for review.

Addressed review comments in pr_report_6322.md using uv run address_reviews.py pr_report_6322.md

PR updated using uv run update_with_claude.py --prompt "Implement the action plan described in the document Repull the rspec metadata from the PR https://github.com/SonarSource/rspec/pull/8321." -a "Repull the rspec metadata from the PR https://github.com/SonarSource/rspec/pull/8321" -g "claude"

PR updated using uv run update_with_claude.py --prompt "Implement the action plan described in the document /tmp/action_plan_romain/new-rule-s9427-sonarjava-7153.txt." -a "/tmp/action_plan_romain/new-rule-s9427-sonarjava-7153.txt" -g "claude"

Iterated on the PR with uv run ci_loop.py for 1 iterations.
✔️ The PR is now ready for review.

…not be used in test code

Detects Java assert statements in explicitly annotated JUnit 4, JUnit Jupiter, and TestNG test methods.
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

SONARJAVA-7153

@datadog-sonarsource

This comment has been minimized.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@romainbrenguier
romainbrenguier marked this pull request as ready for review October 12, 2026 12:10
@rombirli

Copy link
Copy Markdown
Contributor

/pvf

@hashicorp-vault-sonar-prod

Copy link
Copy Markdown
Contributor

📊 Performance Validation complete
🆕 392 new · 🗑️ 0 lost issues
View dashboard

@rombirli rombirli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RSpec PR have failing checks and must be fixed before merging this one (metadata pulled again)

romainbrenguier and others added 3 commits October 13, 2026 16:39
…tract test variables

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…R #8321)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@gitar-bot

gitar-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · Adding S9427 to flag native asserts in annotated tests could introduce unexpected issues that affect analysis results or quality gates.

Adds rule S9427 to flag Java assert statements in test code, with rule tests, test samples, metadata including the tests tag, and Sonar way profile registration. No issues found.

Verification Repos 4 inspected

Functional validation No results

Rules No rules evaluated

Cross-repo 4 repositories inspected 0 open impacts

SonarSource/sonarlint-eclipse Inspected
SonarSource/sonarlint-intellij Inspected
SonarSource/sonarlint-vscode Inspected
SonarSource/sonar-java-symbolic-execution Inspected

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqube-next

Copy link
Copy Markdown
Contributor

@romainbrenguier

Copy link
Copy Markdown
Contributor Author

@rombirli RSpec PR SonarSource/rspec#8321 is now green (required checks and Validate Rules pass). I also added the missing tests tag to rules/S9427/metadata.json there (the rule has scope Tests) and re-pulled the metadata with rule-api in 5e3664b, which fixes the GeneratedCheckListTest.rules_targeting_tests_should_have_tests_tag CI failure. The other review comments were handled in c72b380. Could you take another look?

@romainbrenguier
romainbrenguier merged commit 8b4299e into master Oct 14, 2026
23 checks passed
@romainbrenguier
romainbrenguier deleted the romain/new-rule-s9427-sonarjava-7153 branch October 14, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants