agentleFS
Sagargupta16Sagargupta16/agent-brain/skills/sonar-sweep/SKILL.md

sonar-sweep

Skill2 starsChanged 12 days agoMITView on GitHub

Pull the open SonarCloud findings for a repo or PR via its API, print the count by rule and severity first, fix them in place without behavior change (complexity splits, nested ternaries, unused imports), run the repo's lint and type lane once, and report fixed N/N with false positives listed by rule id. Use when the user says "fix all sonarcloud findings", "fix the 47 new sonarcloud issues", "sonarcloud still failing, fix it", "sonar findings on the PR, fix and merge", or "also fix any sonarcloud issues". Never marks an issue won't-fix or disables a rule to drop the count, and stands down on "not sonar, focus on the feature".

The file

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 5 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Add &pullRequest=<n> for PR-new issues.

    line 42
  2. Very specific:

    Verify once at the end, not per file: the repo's own lane (a single pnpm run check if it has one.

    line 65
  3. Very specific:

    If the same message said "merge it", hand to ship with the count table.

    line 76
  4. Distinctive:

    Never mark an issue won't-fix, false positive, or resolved in SonarCloud.

    line 93
  5. Very specific:

    Never disable or exclude a rule in sonar-project.properties, .sonarcloud.properties, ESLint, or ruff config.

    line 95
  6. Distinctive:

    Never remove a feature, a UI element, a test, or a log line to satisfy a rule.

    line 98
  7. Distinctive:

    Never reformat, re-order imports, or "clean up" a file with no finding.

    line 99
  8. Very specific:

    Never report "fixed the sonar issues".

    line 100
  9. Distinctive:

    Never run on a feature turn: "not sonar, just focus on the UI" ends this skill at once.

    line 101
  10. Very specific:

    Never echo SONAR_TOKEN or any credential value in a command or the reply.

    line 103
  11. Distinctive:

    Never chain commands with a double ampersand.

    line 104

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

sonar-sweep

The ask has one shape: a SonarCloud number the user saw on the PR ("fix the 47 new sonarcloud issues") and an order to make it zero without breaking anything. This skill does it with gh plus the SonarCloud API, no plugin needed.

Read first

  • Your user-level rules (honesty and verification, editing files)
  • Feature vs gate: quality gates are a cleanup phase paid back in bulk, not a build phase. On a feature turn where the user has not named Sonar, this skill does not run.
  • The repo's sonar-project.properties or .sonarcloud.properties (automatic analysis vs a scan step in a workflow) and its CLAUDE.md quality rules

Procedure

  1. Resolve the project key, in order: sonar.projectKey in the properties file; the SonarCloud check run on the PR head (gh api repos/<owner>/<repo>/commits/<sha>/check-runs --jq '.check_runs[] | select(.name | test("Sonar")) | .details_url', the URL carries id=<key> and pullRequest=<n>); else <owner>_<repo>, the default for GitHub-imported projects. The organization key is usually the lowercased GitHub owner.
  2. Enumerate, print, then edit. Public projects need no token; a private one takes -H "Authorization: Bearer $SONAR_TOKEN" with the value never echoed: curl -s "https://sonarcloud.io/api/issues/search?componentKeys=<key>&resolved=false&ps=500&facets=rules,severities,types" Add &pullRequest=<n> for PR-new issues; omit it for main. Then the gate: curl -s "https://sonarcloud.io/api/qualitygates/project_status?projectKey=<key>&pullRequest=<n>" Print the total, count per rule id, count per severity, and the failing gate condition. That total is the denominator for the rest of the session. A gate can fail with 0 issues: check new_duplicated_lines_density too (copied test fixtures count as duplication).
  3. Work by rule id, not by file: one rule has one mechanical fix, applied across every occurrence before the next rule.
RuleFix that keeps behavior
S3776 cognitive complexityextract the deepest branch into a named function; same inputs, same return
S3358 nested ternaryif/else or a small lookup map
S1128 unused import (ruff F401)remove; then run the type lane, the import may have carried a side effect
S1192 duplicated stringone const at module top with the identical literal
S6582 optional chain, S6606 nullishrewrite; keep falsy-vs-nullish semantics identical, check the tests around it
S1481 unused local, S1854 dead storedelete the store; if it fed a log line, keep the log
S1186 empty function, S2486 ignored exceptionnarrow the catch to the expected error and handle or rethrow; never pass
S8476 forged client requestbuild with URL, pin the origin
  1. Preserve line endings (no sed -i on CRLF repos), no formatter over untouched files. Every changed line traces to an issue in the list; if not, revert it.
  2. Verify once at the end, not per file: the repo's own lane (a single pnpm run check if it has one; else pnpm run lint then pnpm run typecheck, or uv run ruff check . then uv run mypy) plus the tests covering the touched files. A red lane means step 4 changed behavior; fix that first.
  3. Push to the existing PR branch (never a second PR), wait for the SonarCloud check (gh pr checks <n> --watch), re-run step 2 with the same parameters. The API total is the proof: 47 -> 0 from issues/search, not from the diff.
  4. Whatever remains is a false positive or out of scope. List each by rule id, file:line, and one line why. Do not resolve it in SonarCloud; the user decides.
  5. If the same message said "merge it", hand to ship with the count table.

Output

| scope | before | fixed | left | proof |
| PR #N new | 47 | 47 | 0 | issues/search total=0 at 2026-09-22T10:02:11Z |
| main inherited | 12 | 9 | 3 | issues/search total=3 |

by rule: S3776 14/14, S3358 9/9, S1192 20/20, S6582 4/4
false positives (left unresolved in SonarCloud): S1192 src/x.ts:41 test fixture literal
gate: passed / failed on <condition>
lane: pnpm run check pass | tests 212/212

Must not

  • Never mark an issue won't-fix, false positive, or resolved in SonarCloud; the count drops only because code changed.
  • Never disable or exclude a rule in sonar-project.properties, .sonarcloud.properties, ESLint, or ruff config; never add // NOSONAR or # noqa to make a finding vanish.
  • Never remove a feature, a UI element, a test, or a log line to satisfy a rule.
  • Never reformat, re-order imports, or "clean up" a file with no finding.
  • Never report "fixed the sonar issues"; only fixed N/M with the API total.
  • Never run on a feature turn: "not sonar, just focus on the UI" ends this skill at once; note the count for later.
  • Never echo SONAR_TOKEN or any credential value in a command or the reply.
  • Never chain commands with a double ampersand; one per line.

Non-goals

Other red CI checks (gh-actions), reviewer and Copilot comments and Dependabot alerts (fix-all, which calls this for its Sonar lane), merging (ship), structural refactors beyond the finding (a clean-code skill, if installed).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.