SONARJAVA-6944: Implement rule S9387 TestNG Javadoc tags should be converted to annotations - #6124
romainbrenguier wants to merge 7 commits into
Conversation
…nverted to annotations Detect TestNG-specific Javadoc tags (@test, @beforeMethod, @afterMethod, etc.) used as configuration markers instead of proper TestNG annotations (@test, @BeforeMethod, @AfterMethod, etc.). Case-insensitive matching with support for all 15 TestNG tags and secondary locations for multiple tags per method. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Addresses code review feedback: 1. Single-line Javadoc `/** @test */` is now detected by updating BLOCK_TAG_PATTERN to match tags following the `/**` opener 2. False positives from annotation examples in `<pre>` and `{@code}` blocks are eliminated by removing those regions before pattern matching 3. Issue and secondary locations now report precisely on the method name using `simpleName()` and avoid redundant operations 4. Type-only tags (`@beforeClass`, `@afterClass`, `@parameters`, `@listeners`) removed from method-level checks since they cannot be applied to methods Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…icate test @BeforeClass and @afterclass are method-level annotations in TestNG (@target(METHOD)), not type-only. The previous commit incorrectly removed them from the tag map. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Revert manually added @beforeClass/@afterclass entries in S9387.html (auto-generated from RSPEC, should not be hand-edited) - Move @beforeClass/@afterclass noncompliant test cases above the "Compliant cases" section for clarity - Add secondary location assertion to multipleTestNGTags test case Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace \s with [\t ] in regex patterns to avoid super-linear backtracking (SonarQube S8786). Use tree.simpleName() for secondary locations to match the primary issue location scope. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…in S9387 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code Review ✅ Approved 7 resolved / 7 findingsImplements rule S9387 to detect TestNG Javadoc tags ( ✅ 7 resolved✅ Bug: Single-line Javadoc
|
| Auto-apply | Compact |
|
|
Was this helpful? React with 👍 / 👎 | Gitar
|




Summary
@test,@beforeMethod,@afterMethod,@beforeClass,@afterClass,@dataProvider, etc.) used as configuration markers instead of proper TestNG annotationsTest plan
🤖 Generated with Claude Code