Repository navigation
AP-1542 Correct SonarJava contributor guidance #6598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ap/AP-1544
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,5 +27,6 @@ To run ITs locally, please follow the [README](https://github.com/SonarSource/so | |
|
|
||
| ### Clean commit history | ||
|
|
||
| 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. Choose a reason for hiding this commentThe 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 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 Was this helpful? React with 👍 / 👎 |
||
|
|
||
| Keep commits focused and history linear. Rebase the branch onto the target branch instead of merging the target into it; integrate the PR by rebase only, without a merge or squash commit. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,32 +20,22 @@ For the default main-code case, name the sample after the check with a **Sample. | |
|
|
||
| Reuse the prepared test dependencies or use focused stubs. Do not add dependencies just to exercise an API when the existing test reactor can model it. | ||
|
|
||
| ## Assert both analysis modes | ||
| ## 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. | ||
|
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 skillThis 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:
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎 |
||
|
|
||
| For a concrete pair, see `java-checks/src/test/java/org/sonar/java/checks/DurationTimeUnitAgreementCheckTest.java`. Share sample-path constants when tests load the same sample. If behavior depends on a library version, add a case for an absent or incompatible dependency as well as the supported one; `withoutSemantic()` alone does not simulate a change to dependency version discovery. | ||
|
|
||
| ## Mark expected issues in the sample | ||
| ## Verify | ||
|
|
||
| Cover both triggering and similar-looking compliant cases. Put `// Noncompliant {{Expected message.}}` on the line with an expected issue. Put carets directly below to assert the primary range; a bare marker cannot catch a regression that moves highlighting to the wrong expression. Mark secondary ranges with carets and a direction marker: `<` points back to a primary above and `>` points forward to a primary below. | ||
| From the repository root after [toolchain setup](build.md), run the targeted test and its prerequisite reactor modules. Substitute the test class for the example: | ||
|
|
||
| ```java | ||
| new Thread(() -> { | ||
| // ^^^^^^> | ||
| Thread.sleep(1000); // Noncompliant {{Do not sleep here.}} | ||
| // ^^^^^ | ||
| }); | ||
| ```bash | ||
| mise run test:unit --module java-checks --test DurationTimeUnitAgreementCheckTest | ||
| ``` | ||
|
|
||
| If a caret cannot express the span (for example at column 1 or across multiple lines), use the explicit attributes such as `sc`, `el`, `ec` or `secondary`. Prefer relative lines to absolute lines so unrelated edits above the marker do not break the test. See [Quick-fix tests](quickfix-tests.md) for fix declarations that accompany an issue marker. | ||
|
|
||
| ## Verify | ||
|
|
||
| From the repository root with the project dependencies and compiled samples available, run the targeted rule test; substitute the test class for the example: | ||
| To compile the shared samples as in CI, run from the root: | ||
|
|
||
| ```bash | ||
| mvn test -pl java-checks -Dtest=DurationTimeUnitAgreementCheckTest | ||
| mise exec java@26 -- mvn -f java-checks-test-sources/pom.xml clean compile | ||
| ``` | ||
|
|
||
| From `java-checks-test-sources`, `mvn clean compile` compiles the shared samples as in CI. It does not compile test-scope samples; use `mvn test-compile` from the same directory when changing those. | ||
| Use `test-compile` instead of `compile` when changing test-scope samples. | ||
There was a problem hiding this comment.
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:19holds upAbsOnNegativeCheckTestas the example of a rule that reports in both modes.AGENTS.md:25points tojava-checks/src/test/files/checks/AbsOnNegative.javaas the example for "verifier assertions and issue markers". Both examples break guidance from this same PR:src/test/files/checksdirectory instead of usingTestUtils.mainCodeSourcesPath.rule-tests.md:19says not to add new rule samples there.SKILL.md:17asks for one sentence earlier.// 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 👍 / 👎