Skip to content

AP-1542 Correct SonarJava contributor guidance - #6598

Draft
erwan-leforestier-sonarsource wants to merge 1 commit into
ap/AP-1544from
ap/AP-1542
Draft

erwan-leforestier-sonarsource wants to merge 1 commit into
ap/AP-1544from
ap/AP-1542

Conversation

@erwan-leforestier-sonarsource

@erwan-leforestier-sonarsource erwan-leforestier-sonarsource commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor
  • Route agent build and verification instructions through mise and document the current contribution workflow.
  • Use a tracked rule-test example and clarify verifier assertions, bundled licenses, and ruling sources.

Jira: AP-1542

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

AP-1542

@gitar-bot

gitar-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
CI failed: The Maven build failed on a Surefire failure in the scanner integration tests module, with the failing test and its error not present in the available log. The analyzer judged it unrelated to this documentation-only PR (related_to_pr=no), so it is not attributed to the change.

Overview

The Maven build failed on a Surefire failure in the scanner integration tests module, with the failing test and its error not present in the available log. The analyzer judged it unrelated to this documentation-only PR (related_to_pr=no), so it is not attributed to the change.

Failures

Surefire test failure in Scanner Integration Tests (unrelated to PR)

  • Type: test
  • Affected jobs: 140626047778
  • Related to change: no
  • Confidence: medium
  • Root cause: The reactor reports SonarQube Java :: ITs :: Scanner Integration Tests as FAILURE, and Surefire points to its/scanner-integration-tests/target/surefire-reports for details. The custom-rules example tests shown in the log passed. The PR changes contributor documentation and guidance, not scanner integration test behavior; the supplied evidence does not connect those edits to this failure.
  • Suggested fix: Inspect the Surefire reports and any dump files in its/scanner-integration-tests/target/surefire-reports to identify the failing test and its cause, then fix and rerun that test or module. The provided log does not establish that this is flaky.

Summary

  • Change-related failures: 0
  • Infrastructure/flaky failures: 0
  • Recommended action: Inspect the Surefire reports and any dump files in its/scanner-integration-tests/target/surefire-reports to identify the failing test and its cause, then fix and rerun that test or module. The provided log does not establish that this is flaky.
Code Review 👍 Approved with suggestions 🟢 Low risk 0 closed / 3 findings

The PR updates contributor and agent build/test guidance; it changes no product behavior or access authority, keeping impact limited.

Routes agent build and verification instructions through mise and documents the current contribution workflow, moving rule-test guidance into the new-rule skill. Consider updating docs that still point readers to docs/systems/rule-tests.md for content it no longer contains, and fixing the AbsOnNegative examples that break the placement and marker rules. Also, the new PR-title rule uses SONARJAVA-XXXX, which will conflict with #6597 switching to JAVA.

💡 Quality: Docs still send readers to rule-tests.md for content now in the skill

📄 docs/systems/rule-tests.md:23-25 📄 java-checks-test-sources/README.md:10

This PR moves the semantic/no-semantic guidance, the verifier example and the caret/marker rules out of docs/systems/rule-tests.md and into .agents/skills/new-rule/SKILL.md#rule-test-assertions. Several pages still say rule-tests.md itself has that content:

  • docs/systems/quickfix-tests.md:3 says the rule test guide "explains the underlying issue and caret markers".
  • docs/adrs/junit-5.md says "See Rule tests for a verifier example". rule-tests.md no longer has one.
  • docs/systems/index.md describes rule-tests.md as "choose semantic and no-semantic expectations".
  • docs/systems/rule-api.md says "Test that fallback explicitly; see Rule tests". The unresolved-type guidance has moved.
  • java-checks-test-sources/README.md:10 says that guide covers "verifier setup". This README is edited in this PR.

Rule-tests.md is now a one-line redirect, so each of these pages costs the reader an extra hop. Point these references straight at the skill anchor, or update their wording.

Example: update the quick-fix guide reference
Declare expected fixes in the same sample as the issue. This fragment comes from `java-checks-test-sources/default/src/main/java/checks/DurationTimeUnitAgreementCheckSample.java`; the [rule test assertions](../../.agents/skills/new-rule/SKILL.md#rule-test-assertions) explain the underlying issue and caret markers.
💡 Quality: AbsOnNegative examples break the skill's placement and marker rules

📄 .agents/skills/new-rule/SKILL.md:17-21 📄 AGENTS.md:25 📄 docs/systems/rule-tests.md:19

SKILL.md:19 holds up AbsOnNegativeCheckTest as the example of a rule that reports in both modes. AGENTS.md:25 points to java-checks/src/test/files/checks/AbsOnNegative.java as the example for "verifier assertions and issue markers". Both examples break guidance from this same PR:

  • The test loads its sample from the legacy src/test/files/checks directory instead of using TestUtils.mainCodeSourcesPath. rule-tests.md:19 says not to add new rule samples there.
  • The test repeats the path string instead of sharing a sample-path constant, which SKILL.md:17 asks for one sentence earlier.
  • Only 2 of the 12 // Noncompliant markers in the sample have carets. SKILL.md:21 says carets belong under each reported location.

An agent that copies these files will produce a test the docs reject. Pick a both-modes test that follows the documented layout, or say plainly that these files show only the verifier calls.

ℹ️ Cross-PR: New PR-title rule asks for SONARJAVA keys after #6597 switches to JAVA

📄 CONTRIBUTING.md:30

Breaks when this PR and #6597 both merge, and a contributor follows the new PR-title instruction in CONTRIBUTING.md while the Jira key is JAVA.

How

  1. CONTRIBUTING.md:30 (this PR) says PR titles must start with a SONARJAVA-XXXX issue key.
  2. #6597 changes the Jira link at CONTRIBUTING.md:7 to the JAVA project, so the same file then gives two different project keys.
  3. #6597 sets jira-project: JAVA at .github/workflows/PullRequestCreated.yml:29 and also changes automated-release.yml, so the PR automation stops using the SONARJAVA project.
  4. The two edits are in different hunks, so git reports no conflict and the stale key goes in unnoticed.

Fix

  • This PR: Write the PR-title instruction with the JAVA-XXXX key, or describe it without hard-coding the project key.
  • #6597: Rename the SONARJAVA-XXXX key in the new CONTRIBUTING.md PR-title sentence along with the other renamed sites.

Compared b939552 with #6597 at d16fca0

🤖 Prompt for agents
Code Review: Routes agent build and verification instructions through mise and documents the current contribution workflow, moving rule-test guidance into the new-rule skill. Consider updating docs that still point readers to `docs/systems/rule-tests.md` for content it no longer contains, and fixing the `AbsOnNegative` examples that break the placement and marker rules. Also, the new PR-title rule uses `SONARJAVA-XXXX`, which will conflict with #6597 switching to `JAVA`.

1. 💡 Quality: Docs still send readers to rule-tests.md for content now in the skill
   Files: docs/systems/rule-tests.md:23-25, java-checks-test-sources/README.md:10

   This PR moves the semantic/no-semantic guidance, the verifier example and the caret/marker rules out of `docs/systems/rule-tests.md` and into `.agents/skills/new-rule/SKILL.md#rule-test-assertions`. Several pages still say rule-tests.md itself has that content:
   - `docs/systems/quickfix-tests.md:3` says the rule test guide "explains the underlying issue and caret markers".
   - `docs/adrs/junit-5.md` says "See Rule tests for a verifier example". rule-tests.md no longer has one.
   - `docs/systems/index.md` describes rule-tests.md as "choose semantic and no-semantic expectations".
   - `docs/systems/rule-api.md` says "Test that fallback explicitly; see Rule tests". The unresolved-type guidance has moved.
   - `java-checks-test-sources/README.md:10` says that guide covers "verifier setup". This README is edited in this PR.
   
   Rule-tests.md is now a one-line redirect, so each of these pages costs the reader an extra hop. Point these references straight at the skill anchor, or update their wording.

   Fix (Example: update the quick-fix guide reference):
   Declare expected fixes in the same sample as the issue. This fragment comes from `java-checks-test-sources/default/src/main/java/checks/DurationTimeUnitAgreementCheckSample.java`; the [rule test assertions](../../.agents/skills/new-rule/SKILL.md#rule-test-assertions) explain the underlying issue and caret markers.

2. 💡 Quality: AbsOnNegative examples break the skill's placement and marker rules
   Files: .agents/skills/new-rule/SKILL.md:17-21, AGENTS.md:25, docs/systems/rule-tests.md:19

   `SKILL.md:19` holds up `AbsOnNegativeCheckTest` as the example of a rule that reports in both modes. `AGENTS.md:25` points to `java-checks/src/test/files/checks/AbsOnNegative.java` as the example for "verifier assertions and issue markers". Both examples break guidance from this same PR:
   - The test loads its sample from the legacy `src/test/files/checks` directory instead of using `TestUtils.mainCodeSourcesPath`. `rule-tests.md:19` says not to add new rule samples there.
   - The test repeats the path string instead of sharing a sample-path constant, which `SKILL.md:17` asks for one sentence earlier.
   - Only 2 of the 12 `// Noncompliant` markers in the sample have carets. `SKILL.md:21` says carets belong under each reported location.
   
   An agent that copies these files will produce a test the docs reject. Pick a both-modes test that follows the documented layout, or say plainly that these files show only the verifier calls.

3. ℹ️ Cross-PR: New PR-title rule asks for SONARJAVA keys after [#6597](<https://github.com/SonarSource/sonar-java/pull/6597>) switches to JAVA
   Files: CONTRIBUTING.md:30

   **Breaks when** this PR and [#6597](<https://github.com/SonarSource/sonar-java/pull/6597>) both merge, and a contributor follows the new PR-title instruction in CONTRIBUTING.md while the Jira key is `JAVA`.
   
   **How**
   
   1. `CONTRIBUTING.md:30` (this PR) says PR titles must start with a `SONARJAVA-XXXX` issue key.
   2. [#6597](<https://github.com/SonarSource/sonar-java/pull/6597>) changes the Jira link at `CONTRIBUTING.md:7` to the `JAVA` project, so the same file then gives two different project keys.
   3. [#6597](<https://github.com/SonarSource/sonar-java/pull/6597>) sets `jira-project: JAVA` at `.github/workflows/PullRequestCreated.yml:29` and also changes `automated-release.yml`, so the PR automation stops using the SONARJAVA project.
   4. The two edits are in different hunks, so git reports no conflict and the stale key goes in unnoticed.
   
   **Fix**
   
   - **This PR:** Write the PR-title instruction with the `JAVA-XXXX` key, or describe it without hard-coding the project key.
   - **[#6597](<https://github.com/SonarSource/sonar-java/pull/6597>):** Rename the `SONARJAVA-XXXX` key in the new CONTRIBUTING.md PR-title sentence along with the other renamed sites.
   
   _Compared `b939552` with [#6597](<https://github.com/SonarSource/sonar-java/pull/6597>) at `d16fca0`_

Verification PRs 3 inspected

Functional validation No results

Rules 11 not applicable

Broader impact PRs 3 inspected
Cross-PR 3 PRs inspected 1 open impact

PR 6596: AP-1544 Add mise tasks for SonarJava checks Inspected
PR 6595: AP-1522 Align SonarJava agent-facing documentation Inspected
PR 6597: JAVA-7436 Rename Jira project key Inspected

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Tip

Comment Gitar fix CI or enable auto-apply: gitar auto-apply:on

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

Comment on lines +23 to +25
## Write verifier assertions

Use JUnit Jupiter (see [JUnit 5](../adrs/junit-5.md)) and `java-checks-testkit/src/main/java/org/sonar/java/checks/verifier/CheckVerifier.java`. Every new rule needs a semantic test and a `withoutSemantic()` test. Resolution can fail when code is incomplete or the classpath is missing; check that the rule neither crashes nor speculates on unresolved types. Use `verifyNoIssues()` if the rule needs resolution, or `verifyIssues()` with the expected remaining findings if it can safely report from syntax alone.
Follow the [new-rule skill](../../.agents/skills/new-rule/SKILL.md#rule-test-assertions) for test cases, verifier methods, and primary and secondary location markers. See [Quick-fix tests](quickfix-tests.md) for fix declarations that accompany an issue marker.

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: Docs still send readers to rule-tests.md for content now in the skill

This PR moves the semantic/no-semantic guidance, the verifier example and the caret/marker rules out of docs/systems/rule-tests.md and into .agents/skills/new-rule/SKILL.md#rule-test-assertions. Several pages still say rule-tests.md itself has that content:

  • docs/systems/quickfix-tests.md:3 says the rule test guide "explains the underlying issue and caret markers".
  • docs/adrs/junit-5.md says "See Rule tests for a verifier example". rule-tests.md no longer has one.
  • docs/systems/index.md describes rule-tests.md as "choose semantic and no-semantic expectations".
  • docs/systems/rule-api.md says "Test that fallback explicitly; see Rule tests". The unresolved-type guidance has moved.
  • java-checks-test-sources/README.md:10 says that guide covers "verifier setup". This README is edited in this PR.

Rule-tests.md is now a one-line redirect, so each of these pages costs the reader an extra hop. Point these references straight at the skill anchor, or update their wording.

Example: update the quick-fix guide reference:

Declare expected fixes in the same sample as the issue. This fragment comes from `java-checks-test-sources/default/src/main/java/checks/DurationTimeUnitAgreementCheckSample.java`; the [rule test assertions](../../.agents/skills/new-rule/SKILL.md#rule-test-assertions) explain the underlying issue and caret markers.
  • Apply fix

Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎

Comment on lines +17 to +21
Use JUnit Jupiter and `java-checks-testkit/src/main/java/org/sonar/java/checks/verifier/CheckVerifier.java`. Cover triggering and similar-looking compliant cases. Every new rule needs a semantic test and a `withoutSemantic()` test. Call `verifyIssues()` when you expect findings and `verifyNoIssues()` when you expect none. In the nonsemantic test, assert any findings the rule can still report safely from syntax alone, but do not assume unresolved types. Share sample-path constants when tests load the same file. For rules gated on a library version, test absent or incompatible dependencies separately; `withoutSemantic()` does not simulate dependency version discovery.

See `java-checks/src/test/java/org/sonar/java/checks/DurationTimeUnitAgreementCheckTest.java` for a rule that needs resolution, and `java-checks/src/test/java/org/sonar/java/checks/AbsOnNegativeCheckTest.java` for a rule that reports in both modes.

Mark each expected issue with `// Noncompliant {{Expected message.}}`. On the line directly below each reported location, align carets under the exact span, for both primary and secondary locations. Add `<` after the secondary carets when the primary is above, or `>` when it is below:

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: AbsOnNegative examples break the skill's placement and marker rules

SKILL.md:19 holds up AbsOnNegativeCheckTest as the example of a rule that reports in both modes. AGENTS.md:25 points to java-checks/src/test/files/checks/AbsOnNegative.java as the example for "verifier assertions and issue markers". Both examples break guidance from this same PR:

  • The test loads its sample from the legacy src/test/files/checks directory instead of using TestUtils.mainCodeSourcesPath. rule-tests.md:19 says not to add new rule samples there.
  • The test repeats the path string instead of sharing a sample-path constant, which SKILL.md:17 asks for one sentence earlier.
  • Only 2 of the 12 // Noncompliant markers in the sample have carets. SKILL.md:21 says carets belong under each reported location.

An agent that copies these files will produce a test the docs reject. Pick a both-modes test that follows the documented layout, or say plainly that these files show only the verifier calls.

Was this helpful? React with 👍 / 👎

Comment thread CONTRIBUTING.md

To ease the review, please have a clean, minimal history of commits in your pull request. Your commits should have a single purpose.
This will help to make your contribution accepted as we like to keep a clean linear history and prefer rebase over merging commits.
Start the pull request title with the associated `SONARJAVA-XXXX` issue key and use the [pull request template](.github/PULL_REQUEST_TEMPLATE.md). If there is no Jira issue yet, follow the standalone PR instructions in the template rather than inventing a key.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ℹ️ Cross-PR: New PR-title rule asks for SONARJAVA keys after #6597 switches to JAVA

Breaks when this PR and #6597 both merge, and a contributor follows the new PR-title instruction in CONTRIBUTING.md while the Jira key is JAVA.

How

  1. CONTRIBUTING.md:30 (this PR) says PR titles must start with a SONARJAVA-XXXX issue key.
  2. #6597 changes the Jira link at CONTRIBUTING.md:7 to the JAVA project, so the same file then gives two different project keys.
  3. #6597 sets jira-project: JAVA at .github/workflows/PullRequestCreated.yml:29 and also changes automated-release.yml, so the PR automation stops using the SONARJAVA project.
  4. The two edits are in different hunks, so git reports no conflict and the stale key goes in unnoticed.

Fix

  • This PR: Write the PR-title instruction with the JAVA-XXXX key, or describe it without hard-coding the project key.
  • #6597: Rename the SONARJAVA-XXXX key in the new CONTRIBUTING.md PR-title sentence along with the other renamed sites.

Compared b939552 with #6597 at d16fca0

Was this helpful? React with 👍 / 👎

This branch has not been deployed

No deployments
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.

1 participant