Repository navigation
AP-1542 Correct SonarJava contributor guidance - #6598
erwan-leforestier-sonarsource wants to merge 1 commit into
Conversation
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.OverviewThe 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. FailuresSurefire test failure in Scanner Integration Tests (unrelated to PR)
Summary
Code Review 👍 Approved with suggestions 🟢 Low risk 0 closed / 3 findingsThe 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 💡 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
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💡 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
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 JAVABreaks when this PR and #6597 both merge, and a contributor follows the new PR-title instruction in CONTRIBUTING.md while the Jira key is How
Fix
Compared 🤖 Prompt for agentsVerification PRs 3 inspectedFunctional validation No results Rules 11 not applicable Broader impact PRs 3 inspectedCross-PR 3 PRs inspected 1 open impact
Auto-approval Not enabledFor more verification details, comment Tip Comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
| ## 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. |
There was a problem hiding this comment.
💡 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:3says the rule test guide "explains the underlying issue and caret markers".docs/adrs/junit-5.mdsays "See Rule tests for a verifier example". rule-tests.md no longer has one.docs/systems/index.mddescribes rule-tests.md as "choose semantic and no-semantic expectations".docs/systems/rule-api.mdsays "Test that fallback explicitly; see Rule tests". The unresolved-type guidance has moved.java-checks-test-sources/README.md:10says 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 👍 / 👎
| 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: |
There was a problem hiding this comment.
💡 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/checksdirectory instead of usingTestUtils.mainCodeSourcesPath.rule-tests.md:19says not to add new rule samples there. - The test repeats the path string instead of sharing a sample-path constant, which
SKILL.md:17asks for one sentence earlier. - Only 2 of the 12
// Noncompliantmarkers in the sample have carets.SKILL.md:21says 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 👍 / 👎
|
|
||
| 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. |
There was a problem hiding this comment.
ℹ️ 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
CONTRIBUTING.md:30(this PR) says PR titles must start with aSONARJAVA-XXXXissue key.- #6597 changes the Jira link at
CONTRIBUTING.md:7to theJAVAproject, so the same file then gives two different project keys. - #6597 sets
jira-project: JAVAat.github/workflows/PullRequestCreated.yml:29and also changesautomated-release.yml, so the PR automation stops using the SONARJAVA project. - 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-XXXXkey, or describe it without hard-coding the project key. - #6597: Rename the
SONARJAVA-XXXXkey 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 👍 / 👎
Jira: AP-1542