Skip to content

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

Open
romainbrenguier wants to merge 1 commit into
masterfrom
romain/agents-md
Open

SONARJAVA-6828 Add AGENTS.md to provide guidance to agents making changes to rules#5993
romainbrenguier wants to merge 1 commit 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
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

Choose a reason for hiding this comment

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

💡 Quality: Test sample path convention contradicts the example

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.

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 resolved / 1 findings

Adds AGENTS.md to provide clear guidance for agents making changes to rules. Consider correcting the test sample path convention to match the example.

💡 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.

🤖 Prompt for agents
Code Review: Adds AGENTS.md to provide clear guidance for agents making changes to rules. Consider correcting the test sample path convention to match the example.

1. 💡 Quality: Test sample path convention contradicts the example
   Files: 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

@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
- **`reportIssue(tree, message)`** — Report an issue at a specific AST node
- **`reportIssue(tree, message, secondaries, cost)`** — Report with secondary locations
- **`Tree.Kind.*`** — AST node type enumeration (e.g., `Tree.Kind.METHOD`, `Tree.Kind.IF_STATEMENT`, `Tree.Kind.METHOD_INVOCATION`)
- **`TreeUtils.firstAncestorOfKind(tree, Tree.Kind.METHOD)`** — Navigate up the AST

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.

TreeUtils.firstAncestorOfKind does not exist in this repository or its compiled API, so following this guidance produces a non-compiling rule. Please replace this with an actual parent-walking pattern, such as ExpressionUtils.getParentOfType(tree, Tree.Kind.METHOD), or remove the example.

Comment thread AGENTS.md

```java
@Rule(key = "S2230")
public class TransactionalMethodVisibilityCheck extends IssuableSubscriptionVisitor implements DependencyVersionAware {

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.

This DependencyVersionAware example does not compile: SubscriptionVisitor.nodesToVisit() is abstract and IssuableSubscriptionVisitor does not provide a default implementation. Please add the required override, mirroring TransactionalMethodVisibilityCheck:

@Override
public List<Tree.Kind> nodesToVisit() {
  return Collections.singletonList(Tree.Kind.METHOD);
}

Comment thread AGENTS.md
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
@@ -0,0 +1,255 @@
# Introduction

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.

Non-blocking: since CLAUDE.md symlinks to this auto-loaded guide, please add a pointer to .claude/skills/new-rule/SKILL.md. That skill contains required new-rule guidance not present here, including rule-api metadata generation, output paths, and the prohibition on adding external test dependencies. Without a link, an agent following AGENTS.md alone can implement a rule without its required generated metadata.

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