Skip to content

SONARJAVA-6828 Add AGENTS.md to provide guidance to agents making changes to rules - #5993

Merged
romainbrenguier merged 4 commits into
masterfrom
romain/agents-md
Aug 24, 2026
Merged

SONARJAVA-6828 Add AGENTS.md to provide guidance to agents making changes to rules#5993
romainbrenguier merged 4 commits into
masterfrom
romain/agents-md

Conversation

@romainbrenguier

Copy link
Copy Markdown
Contributor

This is to help being more efficient when creating new rules.

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Add AGENTS.md to provide guidance to agents making changes to rules SONARJAVA-6828 Add AGENTS.md to provide guidance to agents making changes to rules Aug 21, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

SONARJAVA-6828

Comment thread AGENTS.md Outdated

@nathsou nathsou 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.

I found three correctness issues in the agent guidance that can directly lead to non-compiling rules or failing tests. I also left a non-blocking suggestion to point the auto-loaded guide at the existing new-rule skill, which contains required metadata-generation and test-dependency guidance absent here.

Comment thread AGENTS.md Outdated
Comment thread AGENTS.md
Comment thread AGENTS.md Outdated
The file general structure for a rule implementation and its tests is as follows:
- Rule class: `java-checks/src/main/java/org/sonar/java/checks/{RuleId}Check.java`
- Test class: `java-checks/src/test/java/org/sonar/java/checks/{RuleId}CheckTest.java`
- Test samples: `java-checks-test-sources/default/src/main/files/checks/{RuleId}CheckSample.java`

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.

The normal-sample path is invalid. java-checks-test-sources/default/src/main/files/ contains only non-compiling; normal samples live under src/main/java/checks/ and should be loaded with TestUtils.mainCodeSourcesPath("checks/{RuleId}CheckSample.java"). This also contradicts the legacy src/test/files example below. Please update both the documented convention and the example. The same incorrect normal-sample path is duplicated in .claude/skills/new-rule/SKILL.md:75.

Comment thread AGENTS.md
romainbrenguier and others added 3 commits August 24, 2026 11:22
- Fix non-existent TreeUtils.firstAncestorOfKind to ExpressionUtils.getParentOfType
- Add missing nodesToVisit() override in DependencyVersionAware example
- Fix test sample path from files/checks/ to java/checks/
- Update test example to use TestUtils.mainCodeSourcesPath()
- Add pointer to .claude/skills/new-rule/SKILL.md for metadata guidance

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The path used `main/files/checks/` instead of `main/java/checks/`
for the normal test sample location.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gitar-bot

gitar-bot Bot commented Aug 24, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Adds AGENTS.md guidelines and rules for agents modifying the repository, addressing the test sample path convention contradiction. No issues found.

✅ 1 resolved
Quality: Test sample path convention contradicts the example

📄 AGENTS.md:196 📄 AGENTS.md:211 📄 AGENTS.md:219 📄 AGENTS.md:29
The doc states test samples should live at java-checks-test-sources/default/src/main/files/checks/{RuleId}CheckSample.java, but the AbsOnNegativeCheckTest example immediately below uses the legacy path src/test/files/checks/AbsOnNegative.java (which the Repository Structure section says should be migrated away from). An agent following this example would place new samples in the deprecated location. Align the example's onFile(...) path with the stated java-checks-test-sources convention, or note that the example reflects a legacy test.

Options

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

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

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
0 Dependency risks
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@romainbrenguier
romainbrenguier merged commit 18788dd into master Aug 24, 2026
18 checks passed
@romainbrenguier
romainbrenguier deleted the romain/agents-md branch August 24, 2026 14:31
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