sonarqube-quality
Skill0 starsChanged 5 months agoMITView on GitHub
This skill should be used when the user asks to "run SonarQube", "SonarQube prüfen", "check code quality", "Code-Qualität prüfen", "Sonar-Analyse", "scan for bugs/vulnerabilities/code smells", "auf 100% Qualität bringen", wants a green Quality Gate, zero SonarQube issues, or to verify quality during refactoring or before committing. Runs a local Dockerized SonarQube (localhost:9000), auto-detects the build system, executes the right scanner, waits for analysis, and reports every open issue + security hotspot so they can be driven to zero.
In this repository11 other files it gives its agents.
- architecture-analysisSkill
- bearer-privacySkill
- build-verifySkill
- code-audit-suiteSkill
- dast-runtimeSkill
- kubescape-k8sSkill
- license-complianceSkill
- megalinter-qualitySkill
- opengrep-sastSkill
- secrets-scanSkill
- trivy-securitySkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 15
Use this skill during refactoring and general coding: run an analysis, read the exact issue list, fix the root causes, re-run, and repeat …
- Distinctive: line 34
Analyze: Run the orchestrator from the project directory:
- Distinctive: line 56
Run analysis after a meaningful batch of edits, not after every single line — the server-side task takes a few seconds each time.
- Distinctive: line 82
If the admin password was already changed (likely on an instance that has been running), token creation fails with a clear message.
- Very specific: line 125
Suppression policy: avoid // NOSONAR, @SuppressWarnings, # NOSONAR, and "Won't Fix" resolutions.
≈ “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.
Files
SonarQube Quality
Purpose
Drive code to zero open SonarQube issues (bugs, vulnerabilities, code smells),
zero security hotspots awaiting review, and a green Quality Gate, using a
SonarQube instance already running locally in Docker on http://localhost:9000.
Use this skill during refactoring and general coding: run an analysis, read the
exact issue list, fix the root causes, re-run, and repeat until the report says
RESULT: PASS.
Prerequisites
- Docker is running with the
sonarqubecontainer published on9000:9000(the server). Verify withdocker ps. python3is available (used only for stdlib-based API calls — no pip needed).- Per language, the build tool must be installed only for JVM/.NET projects:
- Maven →
mvn; Gradle →gradleor./gradlew - .NET →
dotnet+ thedotnet-sonarscannerglobal tool - Everything else (JS/TS, Python, Go, PHP, Ruby, etc.) needs no local
scanner — it runs via the
sonarsource/sonar-scanner-cliDocker image.
- Maven →
Core Workflow (the quality loop)
To bring a project to 100% clean, follow this loop. Announce each analysis run.
- Analyze. Run the orchestrator from the project directory:
It checks the server is UP, ensures an analysis token exists (creating one on first run), detects the build system, runs the matching scanner, waits for the server-side Compute Engine task, then prints the full report.~/.claude/skills/sonarqube-quality/scripts/sonar-check.sh [PROJECT_DIR] - Read the report. It lists every open issue grouped by file, as
Lnn [TYPE/SEVERITY] message (rule-key), plus security hotspots, the Quality Gate status, and the project ratings (reliability / security / maintainability). - Fix root causes. For each issue, open the file at the given line and fix the underlying problem — do not silence it. See "Driving issues to zero" below.
- Re-run
sonar-check.sh. The analysis is incremental on the server side; each run reflects the current code. - Stop at PASS. The script exits
0and printsRESULT: PASSonly when open issues = 0, hotspots-to-review = 0, and the Quality Gate isOK. Treat a non-zero exit as "not done yet".
Run analysis after a meaningful batch of edits, not after every single line — the server-side task takes a few seconds each time.
How sonar-check.sh decides the scanner
Detection order (first match wins):
| Found in project root | Scanner used |
pom.xml | mvn verify sonar:sonar |
build.gradle[.kts] | gradle sonar (or ./gradlew sonar) |
*.sln / *.csproj | dotnet sonarscanner begin/build/end |
| anything else | sonarsource/sonar-scanner-cli (Docker) |
The project key defaults to a sanitized directory name; override with
SONAR_PROJECT_KEY. SonarQube auto-creates the project on first analysis. For
multi-language repos, language-specific options, coverage import, and exclusions,
see references/scanners.md.
Authentication / token handling
The skill manages its own token. On first run, sonar-api.py ensure-token
authenticates as admin (default password admin), generates a user token named
claude-code-analysis, and caches it at ~/.claude/.sonar-token (mode 600).
Later runs reuse and validate the cached token.
If the admin password was already changed (likely on an instance that has been running), token creation fails with a clear message. In that case, ask the user for the admin password and re-run with it exported:
SONAR_ADMIN_PASS='the-real-password' ~/.claude/skills/sonarqube-quality/scripts/sonar-check.shAlternatively, the user can create a token in the SonarQube UI
(My Account → Security → Generate Tokens) and save it to ~/.claude/.sonar-token.
Security & concurrency notes (local throwaway instance)
- The
admin/admindefault and the long-lived token cached in plaintext at~/.claude/.sonar-token(mode 600) assume a local, disposable SonarQube. Do not point this at a shared/production server without changing the admin password and managing token lifetime. - The token is handed to the scanners via the
SONAR_TOKENenvironment variable, not a-Dsonar.tokenCLI argument — so it is not exposed to other local users viaps. - Parallel runs: the token file is written atomically and a same-named token
is never revoked (a colliding name falls back to a per-process token name), so
two concurrent Sonar runs won't pull each other's token out from under a live
scan. They still share one instance — give them distinct
SONAR_PROJECT_KEYs. sonar-scanner-cliis an amd64-only image (pinned viaSONAR_SCANNER_PLATFORM). On native Linux, if.scannerworkcannot be written into the project due to a container/host UID mismatch, run with--user $(id -u):$(id -g)(Docker Desktop maps ownership automatically). Scanner artifacts are cleaned up on exit.
Driving issues to zero
Aim for genuine fixes, ranked by type:
- Bugs (reliability): correctness defects — null dereferences, wrong conditions, resource leaks, unreachable code. Fix the logic.
- Vulnerabilities (security): injection, weak crypto, hard-coded secrets, unsafe deserialization. Fix the insecure pattern; never just suppress.
- Code smells (maintainability): complexity, duplication, dead code, naming, missing braces, magic numbers. Refactor toward the rule's intent.
- Security hotspots: these require human-style review, not just fixing.
For each, decide whether the code is actually safe in context. If unsafe, fix
it. If genuinely safe, it can be marked reviewed/safe via the API — see
references/web-api.md. Do not mark hotspots safe to make the number go down; justify each.
Suppression policy: avoid // NOSONAR, @SuppressWarnings, # NOSONAR, and
"Won't Fix" resolutions. Use them only for verified false positives, and state the
justification in the same change. A passing report achieved by suppression is not
the goal.
Duplications and coverage are part of "all levels". To eliminate duplicated
blocks, extract shared code. To raise coverage, the scanner must import a coverage
report produced by the project's test runner — see the coverage section in
references/scanners.md.
Manual / advanced API use
For querying issues, hotspots, measures, or changing hotspot status directly
(without a full re-scan), use the helper subcommands or raw endpoints documented
in references/web-api.md:
python3 ~/.claude/skills/sonarqube-quality/scripts/sonar-api.py report --project-key KEYTroubleshooting
For "server not UP", scanner-can't-reach-server (Docker networking /
host.docker.internal), admin-password-changed, stuck Compute Engine tasks,
missing dotnet-sonarscanner, JVM version requirements, and large-repo tuning,
see references/troubleshooting.md.
Additional Resources
Scripts (scripts/)
sonar-check.sh— one-command orchestrator: server check → token → detect build → scan → wait → report. Exit 0 only when clean.sonar-api.py— stdlib-only Web API helper with subcommandsstatus,ensure-token,wait-task,report.
Reference Files (references/)
scanners.md— per-language scanner setup, coverage import, exclusions, multi-module/monorepo notes.web-api.md— SonarQube Web API endpoints used, manual queries, issue types/severities, ratings, and changing hotspot status.troubleshooting.md— common failures and fixes.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
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.

