SonarQube Review Skill
Purpose
Automatically fix issues reported by SonarQube, regardless of language or framework, following a structured process with:
- Issue analysis
- Fix checklist
- Unit tests and coverage (stack-agnostic)
- Review documentation
- .gitignore update
⚙️ Environment Variable Configuration
The skill supports multiple SonarQube editions through environment variables. Detection is automatic based on the availability of the variables (in priority order):
⚠️ IMPORTANT: For security, NEVER read, print, or inspect the value of environment variables that contain tokens. The most you may know is which variable the token is stored in. Use the variables directly in commands without accessing their contents.
Available Variables
For Custom URL (Highest Priority)
SONARQUBE_CUSTOM_URL: Base URL of the custom SonarQube
SONARQUBE_CUSTOM_TOKEN: Authentication token for the custom SonarQube
SONARQUBE_CUSTOM_EDITION: Edition of the custom SonarQube (open or enterprise, default: open)
For SonarQube Enterprise
SONARQUBE_ENTERPRISE_TOKEN: Authentication token for SonarQube Enterprise
SONARQUBE_ENTERPRISE_URL: Base URL of SonarQube Enterprise (required, no fallback)
For SonarQube Open (Default)
SONARQUBE_OPEN_TOKEN: Authentication token for SonarQube Open (preferred)
SONAR_TK: Authentication token for SonarQube Open (fallback for compatibility, used only if SONARQUBE_OPEN_TOKEN is not set)
SONARQUBE_OPEN_URL: Base URL of SonarQube Open (required, no fallback)
Branch Support
Enterprise and Custom editions with enterprise edition automatically support the branch parameter in the API. The skill automatically detects the current branch using git branch --show-current.
🌍 Supports Any Stack
- ✅ Languages: Java, Kotlin, Python, JavaScript, TypeScript, C#, C++, Go, Ruby, PHP, Scala, PLSQL, VB.NET and others
- ✅ Frameworks: Spring, Django, Flask, FastAPI, Express, React, Vue, Angular, .NET, ASP.NET, Gin, Rails, etc.
- ✅ Any test tool that generates coverage reports
- ✅ Any dependency manager (Maven, Gradle, npm, pip, dotnet, etc.)
🔍 Automatic Stack Detection
The skill automatically detects the project's stack by analyzing configuration files. Load the script references/detect-stack.sh to determine the stack and configure the appropriate commands.
Detection Patterns
| File |
Stack |
Manager |
Test Tool |
Coverage Tool |
pom.xml |
Java/Kotlin |
Maven |
Maven Surefire/Failsafe |
JaCoCo |
build.gradle / build.gradle.kts |
Java/Kotlin |
Gradle |
Gradle Test |
JaCoCo |
package.json |
JavaScript/TypeScript |
npm/yarn/pnpm |
Jest/Vitest/Mocha |
Istanbul |
requirements.txt / pyproject.toml |
Python |
pip |
pytest |
Coverage.py |
.csproj / .sln |
C#/.NET |
dotnet |
dotnet test |
OpenCover/Cobertura |
go.mod |
Go |
go mod |
go test |
go test -cover |
Gemfile |
Ruby |
bundler |
rspec/minitest |
SimpleCov |
composer.json |
PHP |
composer |
phpunit |
phpunit |
build.sbt |
Scala |
sbt |
sbt test |
sbt coverage |
Detection Script
Load the script references/detect-stack.sh to automatically detect the project's stack and configure the appropriate commands.
Angular-Specific Support
Angular Detection
- File:
angular.json or angular-cli.json
- Manager: npm, yarn, pnpm
- Test Framework: Karma + Jasmine or Jest
- Coverage Tool: Istanbul (ng test --code-coverage)
Angular Commands
# Tests with coverage
ng test --code-coverage --watch=false
# Linting
ng lint
# Formatting
npx prettier@<VERSION> --write src/
npx eslint@<VERSION> --fix src/
# Build for validation
ng build --configuration=production
Angular Scripts
references/validate-angular.sh — Angular validation (ng lint, ng test, prettier, eslint)
Angular Test Template
references/templates/test-angular.md — Template for Karma/Jasmine tests with TestBed
C# .NET-Specific Support
C# .NET Detection
- File:
.csproj or .sln
- Manager: dotnet CLI
- Test Framework: xUnit, NUnit, MSTest
- Coverage Tool: dotnet test /p:CollectCoverage=true
C# .NET Commands
# Tests with coverage
dotnet test /p:CollectCoverage=true /p:CoverageFormat=cobertura
# Linting and analysis
dotnet build /p:RunAnalyzersDuringBuild=true
# Formatting
dotnet format
# Package restore
dotnet restore
C# .NET Scripts
references/validate-csharp.sh — C#/.NET validation (dotnet build, dotnet test, dotnet format)
C# .NET Test Template
references/templates/test-csharp.md — Template for xUnit/Moq tests
SonarQube Local Validation
Local Validation Script
Load the script references/sonar-local-scan.sh to run SonarQube locally and revalidate fixes before committing.
# Run local scan
bash references/sonar-local-scan.sh
Local SonarQube Configuration
The sonar-local-scan.sh script requires:
sonar-scanner Installation
# Linux/macOS (manual): unzip the SonarScanner ZIP and add <path>/bin to PATH
export PATH="$HOME/sonar-scanner-<version>/bin:$PATH"
# Or use this repository's installer
./install-skill-tools.sh --sonar
Example sonar-project.properties
sonar.projectKey=my-project
sonar.sources=src
sonar.tests=tests
sonar.exclusions=**/node_modules/**,**/dist/**,**/bin/**,**/obj/**
sonar.coverage.exclusions=**/*Tests.cs,**/Program.cs
sonar.cs.vscoveragexml.reportPaths=coverage.xml
sonar.javascript.lcov.reportPaths=coverage/lcov.info
Workflow
Pre Steps
- Save the time you started running the skill to measure the time spent.
- When finishing the run, save the end time to calculate the total time spent.
- Compare the time spent with the "effort" estimated in the issue to evaluate the skill's efficiency (report how many % of time saved or lost relative to the estimated effort).
Phase 1: Analysis and Preparation
Detect Project Stack
- Load the script
references/detect-stack.sh to automatically detect the stack
- The script returns:
STACK, BUILD_TOOL, TEST_FRAMEWORK, COVERAGE_TOOL
- Configure the appropriate commands based on the detected stack
- If automatic detection is not possible, ask the user
Verify issues file
Check the project name, usually it is the workspace folder name.
If it is not at the project root, create the .sonar_devin_auto_fix/ folder
⚠️ CRITICAL SECURITY: Never print the value of environment variables that contain tokens or secrets. NEVER read token values into your memory — the most you may know is which environment variable the token is stored in. Use the variables directly in bash commands without ever inspecting their contents.
Download the project's issues:
If the user specifies the project name, use it; otherwise try to use the workspace folder name, and if that is still not possible, ask the user for the project name.
If the user provides the issues to be fixed, query using the issues parameter and pass a csv list with the issue IDs; otherwise download all unresolved issues from the project using the SonarQube API.
If the user requests to fix only new issues, download the unresolved issues and add the inNewCodePeriod filter set to true.
Automatic SonarQube edition detection:
The skill automatically detects which edition to use based on the available environment variables (in priority order):
- Custom URL (highest priority): If
$SONARQUBE_CUSTOM_URL is set
- Enterprise: If
$SONARQUBE_ENTERPRISE_TOKEN is set
- Open: If
$SONARQUBE_OPEN_TOKEN or $SONAR_TK is set
- Error: If none of the above, abort and request the environment variables to be configured (there is no automatic/fallback URL).
Download issues with automatic detection:
Load the reference script references/download-issues.sh and execute it.
Indent the downloaded issues file using the script references/jsonf.sh
Confirm that .sonar_devin_auto_fix/sonarqube_issues.json exists and is parseable
Base all fixes exclusively on the issues listed in that JSON
Create ToDo Board
Phase 2: Issue Fixing
For each issue, execute in order:
- Modify the code - Resolve the specific issue
- Generate tests automatically (if applicable) - Load the appropriate test template for the detected stack
- Update tests - Ensure 100% coverage of the modified lines
- Run tests - Execute the unit test suite
- Check coverage - Confirm 100% coverage of the modified lines
- Run stack-specific linters - Execute stack linters to validate the fix
- Format the code - Execute stack formatters to keep consistency
- Update the ToDo Board - Mark the issue as
[x] when fixed
Phase 3: Documentation and Finalization
Update .gitignore
- Open
.gitignore at the project root
- Add the line:
.sonar_devin_auto_fix/**
- Only if an equivalent does not already exist
Generate Review Guide
- Create
.sonar_devin_auto_fix/SONAR_FIX_REVIEW_NOTES.md
- Include sections:
- Summary of changes: number of issues fixed and types of fixes
- How to review: instructions for the developer to review the changes
- Points of attention: sensitive logic that was changed
- Tests: how to run tests and coverage
- Post-review verification: final validations
Final validation
- The SonarQube scan will be run by the CI/CD pipeline after the merge
- Confirm that the code is clean and tests are passing
Generate Metrics Dashboard
- Create
.sonar_devin_auto_fix/SONAR_FIX_METRICS.html
- Include:
- Time spent vs estimated effort (in %)
- Number of issues fixed by type (bug, code smell, vulnerability, hotspot)
- Coverage before/after
- Regressions avoided
- Detected stack and tools used
🛠️ Integrated External Tools
The skill automatically integrates external tools per stack to validate and format the code after fixes.
Linters by Stack
| Stack |
Linter |
Command |
| Java/Kotlin |
Checkstyle, PMD |
mvn checkstyle:check pmd:check |
| JavaScript/TypeScript |
ESLint |
npx eslint@<VERSION> src/ |
| Python |
Pylint, Flake8 |
python -m pylint src/ |
| C#/.NET |
StyleCop, Roslyn Analyzers |
dotnet build /p:RunAnalyzersDuringBuild=true |
| Go |
golint, golangci-lint |
golangci-lint run |
| Ruby |
RuboCop |
bundle exec rubocop |
| PHP |
PHPStan |
vendor/bin/phpstan analyse |
| Scala |
Scalastyle, Scapegoat |
sbt scalastyle scapegoat |
Formatters by Stack
| Stack |
Formatter |
Command |
| Java/Kotlin |
Spotless, Google Java Format |
mvn spotless:apply |
| JavaScript/TypeScript |
Prettier |
npx prettier@<VERSION> --write src/ |
| Python |
Black, isort |
python -m black src/ |
| C#/.NET |
dotnet format |
dotnet format |
| Go |
gofmt, goimports |
gofmt -w . |
| Ruby |
Rufo |
bundle exec rufo |
| PHP |
PHP CS Fixer |
vendor/bin/php-cs-fixer fix |
Coverage Tools by Stack
| Stack |
Tool |
Command |
| Java/Kotlin |
JaCoCo |
mvn jacoco:report |
| JavaScript/TypeScript |
Istanbul |
npx vitest@<VERSION> run --coverage |
| Python |
Coverage.py |
python -m coverage run -m pytest |
| C#/.NET |
OpenCover, Cobertura |
dotnet test /p:CollectCoverage=true /p:CoverageFormat=cobertura |
| Go |
go test -cover |
go test -cover ./... |
| Ruby |
SimpleCov |
bundle exec rspec --coverage |
| PHP |
phpunit --coverage-clover |
vendor/bin/phpunit --coverage-clover=coverage.xml |
| Scala |
sbt coverage |
sbt clean coverage test coverageReport |
SonarLint and SonarScanner
The skill may use SonarLint and SonarScanner for local validation before committing:
SonarLint (IDE Integration):
- Available for IntelliJ IDEA, VS Code, Eclipse
- Validates code in real time
- Can be invoked via command line for batch validation
SonarScanner CLI:
- For local scans before push
- Offline validation of fixes
- Command:
sonar-scanner -Dsonar.projectKey=<project> -Dsonar.sources=src
Validation Scripts
The skill loads reference scripts for automatic validation per stack:
references/validate-java.sh — Java/Kotlin validation (Checkstyle, PMD, Spotless, JaCoCo)
references/validate-js.sh — JavaScript/TypeScript validation (ESLint, Prettier, Vitest)
references/validate-python.sh — Python validation (Pylint, Flake8, Black, pytest)
references/validate-csharp.sh — C#/.NET validation (Roslyn Analyzers, dotnet format, dotnet test)
references/validate-go.sh — Go validation (golangci-lint, gofmt, go test)
references/validate-ruby.sh — Ruby validation (RuboCop, Rufo, rspec)
references/validate-php.sh — PHP validation (PHPStan, PHP CS Fixer, phpunit)
references/validate-scala.sh — Scala validation (Scalastyle, Scapegoat, sbt)
🎨 Test Templates by Stack
The skill generates tests automatically based on stack-specific templates. Load the appropriate template from the references/templates/ folder:
test-java.md — Template for JUnit/Mockito tests
test-kotlin.md — Template for KotlinTest/Mockk tests
test-python.md — Template for pytest/unittest tests
test-javascript.md — Template for Jest/Vitest tests
test-typescript.md — Template for TypeScript tests
test-csharp.md — Template for xUnit/Moq tests
test-go.md — Template for Go tests
test-ruby.md — Template for RSpec/Minitest tests
test-php.md — Template for PHPUnit tests
test-scala.md — Template for ScalaTest/ScalaCheck tests
Tests and Coverage
- ✅ 100% coverage of modified lines (verified in coverage report)
- ✅ No coverage exclusions, such as:
- Comments:
// NOSONAR, // no sonar, # noqa, # pragma: no cover, etc.
- Decorators/Attributes:
@IgnoreCoverage, ExcludeFromCodeCoverage, @Suppress, etc.
- Compiler pragmas:
#pragma, etc.
- IMPORTANT: If the file already has a coverage exclusion, remove it and implement tests for the fix as well as for the rest of the file's code, ensuring full coverage.
- ✅ Remove SonarQube scanner files that may be present, such as
sonar-project.properties, sonar-scanner.properties, etc. Also remove other scanners, such as the SonarScanner for Maven usually present in the POM.xml, since our pipeline is autonomous and does not depend on these files to work. (For now, keep only SonarQube-related configurations in .csproj files).
- ✅ All tests passing
- ✅ Coverage report available (formats: OpenCover, JaCoCo, Cobertura, Istanbul, etc.)
Code Quality
- ✅ No new code smells or SonarQube violations
- ✅ No functional regressions
- ✅ No obvious performance problems
- ✅ Minimal, targeted changes
- ✅ Code follows project conventions and standards
- ✅ No unnecessary changes in areas unrelated to the issue
Business Logic
- ✅ Do not change business logic without extreme necessity
- ✅ If it is necessary to change sensitive points (business rules, critical calculations, main flows):
- Minimize the change
- Document clearly in the review guide
- Justify why it was unavoidable
- Add specific tests to validate the change
Dependencies
- ✅ Do not add unnecessary dependencies
- ✅ Stay within the scope of SonarQube fixes
- ✅ If adding a dependency is absolutely necessary, justify and document it
- ✅ Check that there are no conflicts with existing dependencies
Completion Checklist
Useful Commands (Examples by Stack)
⚠️ Important: Isolated Environments with Required Parameters
Commands are configured to force isolated environments. The isolation prefix is required, but you may add more parameters after it.
Rule: Keep the isolation parameter (e.g. -Dmaven.repo.local=./.m2/repository), but you may add more flags.
Java / Kotlin (Maven)
# ✅ ALLOWED - Mandatory isolation + additional parameters
mvn -Dmaven.repo.local=./.m2/repository clean test
mvn -Dmaven.repo.local=./.m2/repository -DskipTests=false jacoco:report
mvn -Dmaven.repo.local=./.m2/repository -Dorg.slf4j.simpleLogger.defaultLogLevel=debug clean test
# ❌ NOT ALLOWED - No isolation
mvn clean test
Java / Kotlin (Gradle)
# ✅ ALLOWED - Mandatory isolation + additional flags
gradle --gradle-user-home ./.gradle test
gradle --gradle-user-home ./.gradle test --info
gradle --gradle-user-home ./.gradle clean build -x test
# ❌ NOT ALLOWED - No isolation
gradle test
JavaScript / TypeScript / Node.js
# npm ✅ ALLOWED
npm install --no-save
npm install --no-save --verbose
npm test -- --coverage --verbose
# yarn ✅ ALLOWED
yarn install --offline
yarn install --offline --verbose
# pnpm ✅ ALLOWED
pnpm install
pnpm install --verbose
# npx ✅ ALLOWED only with pinned versions
npx vitest@<VERSION> run --coverage
npx eslint@<VERSION> src/
Python
# Create venv (if not exists) ✅ ALLOWED
python -m venv .venv
python -m venv .venv --upgrade-deps
# pip with isolation ✅ ALLOWED
python -m pip install -r requirements.txt -q
python -m pip install --target ./.venv/lib -q package-name
python -m pip install --target ./.venv/lib --upgrade package-name
# pytest and coverage ✅ ALLOWED
python -m pytest --cov=src tests/ -v
python -m pytest --cov=src tests/ --cov-report=html
python -m coverage run -m pytest
python -m coverage report --skip-covered
C# / .NET
# ✅ ALLOWED
dotnet test
dotnet test /p:CollectCoverage=true /p:CoverageFormat=cobertura
dotnet test /p:CollectCoverage=true /p:Exclude="[*Tests]*"
Go
# ✅ ALLOWED
go test -cover ./...
go test -cover ./... -v
go test -coverprofile=coverage.out ./... -timeout=10m
Ruby / Rails
# ✅ ALLOWED
bundle install --local
bundle install --local --no-deployment
bundle exec rspec --coverage
bundle exec rspec --coverage -f progress
PHP
# ✅ ALLOWED
composer install --no-dev
composer install --no-dev --optimize-autoloader
composer install --no-dev --classmap-authoritative
vendor/bin/phpunit --coverage-clover=coverage.xml
vendor/bin/phpunit --coverage-clover=coverage.xml -v
Scala
# ✅ ALLOWED
sbt clean coverage test coverageReport
sbt clean coverage test coverageReport -Dconfig=test
sbt "test -- -Dverbose=true"
🧹 Environment Cleanup
When finishing all fixes, run:
git status
Analyze the output and:
- Temporary, build, coverage, or cache files that appear → add to
.gitignore
- Staged files that should not be there → remove with
git restore --staged <file>
- Confirm that
.sonar_devin_auto_fix/ does not appear as staged
⚠️ Do not commit. Leave the repository clean and organized so the human developer can review and decide what to commit.
Cleanup of Isolated Environments (Optional)
If the user asks to remove isolated environments after completion, list the paths first and ask for explicit confirmation before deleting anything. Do not run rm -rf or find -exec rm -rf without consent.
# List what would be removed (do not delete automatically)
echo "The following paths could be removed: .venv .m2 node_modules .npm __pycache__ .pytest_cache"
# Ask the user to confirm before proceeding. Prefer `git clean` for tracked artifacts.
Important: Verify that the isolated environments are in .gitignore:
# Check if already in .gitignore
grep -E "^\.venv$|^\.m2$|^node_modules$|^__pycache__$" .gitignore
# If not found, add them:
echo ".venv" >> .gitignore
echo ".m2" >> .gitignore
echo "node_modules" >> .gitignore
echo ".pytest_cache" >> .gitignore
echo "__pycache__" >> .gitignore
Important Notes
- 🎯 Work in iterations: one issue at a time, with tests and documentation
- 📝 Keep code clean and aligned with the project's existing standard
- 🔍 Prioritize clarity and maintainability
- ⚠️ Always consider the impact of each change on business logic
- 🧹 ALWAYS clean the environment when finishing — no temporary file should remain pending
- ⚡ Be efficient with time and tokens: avoid unnecessary reads, excessive exploration, and repetitions. Read only what is strictly necessary to fix the issue at hand. Prefer direct and objective actions. Avoid invoking unnecessary tools — use only what the task requires.
- 🚫 Do not implement anything beyond what was requested: fix exclusively the issues listed in
sonarqube_issues.json. Do not refactor without need, do not improve, do not add features, do not reorganize code that is not directly related to the issue.
- 🚫 Do not run programming scripts that require human validation before release: when trying to run scripts, a prompt is presented to the user to decide whether it can be executed, which removes your autonomy and generates more work for the user.
The Iron Law
NO COVERAGE EXCLUSIONS
No coverage exclusion may be used to bypass the lack of tests.
No exceptions:
- Do not use
// NOSONAR, // no sonar, # noqa, # pragma: no cover
- Do not use decorators such as
@IgnoreCoverage, ExcludeFromCodeCoverage, @Suppress
- Do not use compiler pragmas such as
#pragma for exclusions
- If the file already has an exclusion, remove it and implement tests for the code
- Ensure 100% coverage of the modified lines
Common Mistakes
| Mistake |
Consequence |
How to avoid |
| Add coverage exclusions |
Code without tests approved |
Implement tests for all modified lines |
| Fix issues without tests |
Undetected regressions |
Always add unit tests for each fix |
| Change business logic without need |
Bug risk |
Stay within the scope of the SonarQube issue |
| Do not run linters after fixing |
New violations introduced |
Run stack linters after each fix |
| Do not clean environment at the end |
Temporary files in repo |
Run environment cleanup when finishing |
| Print environment variable values |
Security violation |
NEVER read or print tokens, use variables directly in commands |
Anti-Patterns
❌ "This code is too simple to need a test"
Even simple code can have bugs. TDD applies to any fix, regardless of complexity.
❌ "I'll add a coverage exclusion just for this case"
Coverage exclusions violate the quality principle. If the code is too complex to test, refactor it.
❌ "SonarQube is wrong, I won't fix it"
SonarQube can have false positives, but most issues are valid. Fix them and discuss legitimate cases with the team.
❌ "I'll fix everything at once without tests"
Bulk fixes without tests drastically increase the risk of regressions. Fix one issue at a time with tests.
❌ "I don't need to run the local scan, the pipeline will validate"
Local validation saves time and avoids pipeline rejections. Use the sonar-local-scan.sh script.
Adaptations for this catalog
This skill follows the agent catalog standards:
- Frontmatter aligned to repo standard:
license: MIT, metadata.version, metadata.author, tripartite description with explicit Do NOT use for clause
- Language: English (en-us) for content, technical terms in English
- Branch policy: follow
feature/{agent}-{YYYYMMDD}-{short-description}
- Git workflow: branches created from
develop, PR target is develop (not main)
Origin
This skill was created following patterns from obra/superpowers/skills/writing-skills and adapted for SonarQube auto-fix workflows across multiple stacks.
1---2name: sonarqube-review3description: Use when fixing SonarQube code quality issues automatically across any language or framework — issue analysis, fix generation, unit tests, and coverage. Supports Community, Enterprise, and custom SonarQube deployments via environment variables. Do NOT use for general code review without SonarQube (use code-review-and-quality), for whole-repo quality interventions without SonarQube (use quality-test-implementation), or for non-SonarQube static analysis tools. Part of the afonsoft/skills collection.4license: MIT5---67# SonarQube Review Skill89## Purpose1011Automatically fix issues reported by SonarQube, **regardless of language or framework**, following a structured process with:12- Issue analysis13- Fix checklist14- Unit tests and coverage (stack-agnostic)15- Review documentation16- .gitignore update1718## ⚙️ Environment Variable Configuration1920The skill supports multiple SonarQube editions through environment variables. Detection is automatic based on the availability of the variables (in priority order):2122> **⚠️ IMPORTANT:** For security, NEVER read, print, or inspect the value of environment variables that contain tokens. The most you may know is which variable the token is stored in. Use the variables directly in commands without accessing their contents.2324### Available Variables2526#### For Custom URL (Highest Priority)27- `SONARQUBE_CUSTOM_URL`: Base URL of the custom SonarQube28- `SONARQUBE_CUSTOM_TOKEN`: Authentication token for the custom SonarQube29- `SONARQUBE_CUSTOM_EDITION`: Edition of the custom SonarQube (`open` or `enterprise`, default: `open`)3031#### For SonarQube Enterprise32- `SONARQUBE_ENTERPRISE_TOKEN`: Authentication token for SonarQube Enterprise33- `SONARQUBE_ENTERPRISE_URL`: Base URL of SonarQube Enterprise (required, no fallback)3435#### For SonarQube Open (Default)36- `SONARQUBE_OPEN_TOKEN`: Authentication token for SonarQube Open (preferred)37- `SONAR_TK`: Authentication token for SonarQube Open (fallback for compatibility, used only if SONARQUBE_OPEN_TOKEN is not set)38- `SONARQUBE_OPEN_URL`: Base URL of SonarQube Open (required, no fallback)3940### Branch Support4142Enterprise and Custom editions with `enterprise` edition automatically support the `branch` parameter in the API. The skill automatically detects the current branch using `git branch --show-current`.4344## 🌍 Supports Any Stack45- ✅ **Languages:** Java, Kotlin, Python, JavaScript, TypeScript, C#, C++, Go, Ruby, PHP, Scala, PLSQL, VB.NET and others46- ✅ **Frameworks:** Spring, Django, Flask, FastAPI, Express, React, Vue, Angular, .NET, ASP.NET, Gin, Rails, etc.47- ✅ **Any test tool** that generates coverage reports48- ✅ **Any dependency manager** (Maven, Gradle, npm, pip, dotnet, etc.)4950## 🔍 Automatic Stack Detection5152The skill automatically detects the project's stack by analyzing configuration files. Load the script `references/detect-stack.sh` to determine the stack and configure the appropriate commands.5354### Detection Patterns5556| File | Stack | Manager | Test Tool | Coverage Tool |57|---|---|---|---|---|58| `pom.xml` | Java/Kotlin | Maven | Maven Surefire/Failsafe | JaCoCo |59| `build.gradle` / `build.gradle.kts` | Java/Kotlin | Gradle | Gradle Test | JaCoCo |60| `package.json` | JavaScript/TypeScript | npm/yarn/pnpm | Jest/Vitest/Mocha | Istanbul |61| `requirements.txt` / `pyproject.toml` | Python | pip | pytest | Coverage.py |62| `.csproj` / `.sln` | C#/.NET | dotnet | dotnet test | OpenCover/Cobertura |63| `go.mod` | Go | go mod | go test | go test -cover |64| `Gemfile` | Ruby | bundler | rspec/minitest | SimpleCov |65| `composer.json` | PHP | composer | phpunit | phpunit |66| `build.sbt` | Scala | sbt | sbt test | sbt coverage |6768### Detection Script6970Load the script `references/detect-stack.sh` to automatically detect the project's stack and configure the appropriate commands.7172## Angular-Specific Support7374### Angular Detection75- File: `angular.json` or `angular-cli.json`76- Manager: npm, yarn, pnpm77- Test Framework: Karma + Jasmine or Jest78- Coverage Tool: Istanbul (ng test --code-coverage)7980### Angular Commands8182```bash83# Tests with coverage84ng test --code-coverage --watch=false8586# Linting87ng lint8889# Formatting90npx prettier@<VERSION> --write src/91npx eslint@<VERSION> --fix src/9293# Build for validation94ng build --configuration=production95```9697### Angular Scripts98- `references/validate-angular.sh` — Angular validation (ng lint, ng test, prettier, eslint)99100### Angular Test Template101- `references/templates/test-angular.md` — Template for Karma/Jasmine tests with TestBed102103## C# .NET-Specific Support104105### C# .NET Detection106- File: `.csproj` or `.sln`107- Manager: dotnet CLI108- Test Framework: xUnit, NUnit, MSTest109- Coverage Tool: dotnet test /p:CollectCoverage=true110111### C# .NET Commands112113```bash114# Tests with coverage115dotnet test /p:CollectCoverage=true /p:CoverageFormat=cobertura116117# Linting and analysis118dotnet build /p:RunAnalyzersDuringBuild=true119120# Formatting121dotnet format122123# Package restore124dotnet restore125```126127### C# .NET Scripts128- `references/validate-csharp.sh` — C#/.NET validation (dotnet build, dotnet test, dotnet format)129130### C# .NET Test Template131- `references/templates/test-csharp.md` — Template for xUnit/Moq tests132133## SonarQube Local Validation134135### Local Validation Script136Load the script `references/sonar-local-scan.sh` to run SonarQube locally and revalidate fixes before committing.137138```bash139# Run local scan140bash references/sonar-local-scan.sh141```142143### Local SonarQube Configuration144The `sonar-local-scan.sh` script requires:145- `sonar-scanner` installed (available at https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/scanners/sonarscanner/)146- Java 17+ and `jq`147- `sonar-project.properties` file in the project root (optional, script configures automatically)148149### sonar-scanner Installation150151```bash152# Linux/macOS (manual): unzip the SonarScanner ZIP and add <path>/bin to PATH153export PATH="$HOME/sonar-scanner-<version>/bin:$PATH"154155# Or use this repository's installer156./install-skill-tools.sh --sonar157```158159### Example sonar-project.properties160```properties161sonar.projectKey=my-project162sonar.sources=src163sonar.tests=tests164sonar.exclusions=**/node_modules/**,**/dist/**,**/bin/**,**/obj/**165sonar.coverage.exclusions=**/*Tests.cs,**/Program.cs166sonar.cs.vscoveragexml.reportPaths=coverage.xml167sonar.javascript.lcov.reportPaths=coverage/lcov.info168```169170## Workflow171172### Pre Steps173- Save the time you started running the skill to measure the time spent.174- When finishing the run, save the end time to calculate the total time spent.175- Compare the time spent with the "effort" estimated in the issue to evaluate the skill's efficiency (report how many % of time saved or lost relative to the estimated effort).176177### Phase 1: Analysis and Preparation1781791. **Detect Project Stack**180 - Load the script `references/detect-stack.sh` to automatically detect the stack181 - The script returns: `STACK`, `BUILD_TOOL`, `TEST_FRAMEWORK`, `COVERAGE_TOOL`182 - Configure the appropriate commands based on the detected stack183 - If automatic detection is not possible, ask the user1841852. **Verify issues file**186 - Check the project name, usually it is the workspace folder name.187 - If it is not at the project root, create the `.sonar_devin_auto_fix/` folder188 - **⚠️ CRITICAL SECURITY:** Never print the value of environment variables that contain tokens or secrets. NEVER read token values into your memory — the most you may know is which environment variable the token is stored in. Use the variables directly in bash commands without ever inspecting their contents.189 - Download the project's issues:190 If the user specifies the project name, use it; otherwise try to use the workspace folder name, and if that is still not possible, ask the user for the project name.191 If the user provides the issues to be fixed, query using the `issues` parameter and pass a csv list with the issue IDs; otherwise download all unresolved issues from the project using the SonarQube API.192 If the user requests to fix only new issues, download the unresolved issues and add the `inNewCodePeriod` filter set to true.193194 **Automatic SonarQube edition detection:**195 The skill automatically detects which edition to use based on the available environment variables (in priority order):196197 1. **Custom URL** (highest priority): If `$SONARQUBE_CUSTOM_URL` is set198 2. **Enterprise**: If `$SONARQUBE_ENTERPRISE_TOKEN` is set199 3. **Open**: If `$SONARQUBE_OPEN_TOKEN` or `$SONAR_TK` is set200 4. **Error**: If none of the above, abort and request the environment variables to be configured (there is no automatic/fallback URL).201202 **Download issues with automatic detection:**203 Load the reference script `references/download-issues.sh` and execute it.204205 - Indent the downloaded issues file using the script `references/jsonf.sh`206 - Confirm that `.sonar_devin_auto_fix/sonarqube_issues.json` exists and is parseable207 - Base all fixes exclusively on the issues listed in that JSON2082092. **Create ToDo Board**210 - Create the file `.sonar_devin_auto_fix/SONAR_FIX_TODO_BOARD.md`211 - Use the format:212 ```markdown213 # SonarQube Review ToDo Board214215 ## SonarQube Issues Checklist216217 - [ ] Issue <ID> — Rule: <RuleKey> — File: `<path/to/file>` — Line: <line>218 Summary: <short issue message>219 ```220 - Group by file if possible221 - Sort by severity (Blocker → Critical → Major → Minor → Info)222223### Phase 2: Issue Fixing224225For each issue, execute in order:2262271. **Modify the code** - Resolve the specific issue2282. **Generate tests automatically** (if applicable) - Load the appropriate test template for the detected stack2293. **Update tests** - Ensure 100% coverage of the modified lines2304. **Run tests** - Execute the unit test suite2315. **Check coverage** - Confirm 100% coverage of the modified lines2326. **Run stack-specific linters** - Execute stack linters to validate the fix2337. **Format the code** - Execute stack formatters to keep consistency2348. **Update the ToDo Board** - Mark the issue as `[x]` when fixed235236### Phase 3: Documentation and Finalization2372381. **Update .gitignore**239 - Open `.gitignore` at the project root240 - Add the line: `.sonar_devin_auto_fix/**`241 - Only if an equivalent does not already exist2422432. **Generate Review Guide**244 - Create `.sonar_devin_auto_fix/SONAR_FIX_REVIEW_NOTES.md`245 - Include sections:246 - **Summary of changes**: number of issues fixed and types of fixes247 - **How to review**: instructions for the developer to review the changes248 - **Points of attention**: sensitive logic that was changed249 - **Tests**: how to run tests and coverage250 - **Post-review verification**: final validations2512523. **Final validation**253 - The SonarQube scan will be run by the CI/CD pipeline after the merge254 - Confirm that the code is clean and tests are passing2552564. **Generate Metrics Dashboard**257 - Create `.sonar_devin_auto_fix/SONAR_FIX_METRICS.html`258 - Include:259 - Time spent vs estimated effort (in %)260 - Number of issues fixed by type (bug, code smell, vulnerability, hotspot)261 - Coverage before/after262 - Regressions avoided263 - Detected stack and tools used264265## 🛠️ Integrated External Tools266267The skill automatically integrates external tools per stack to validate and format the code after fixes.268269### Linters by Stack270271| Stack | Linter | Command |272|---|---|---|273| Java/Kotlin | Checkstyle, PMD | `mvn checkstyle:check pmd:check` |274| JavaScript/TypeScript | ESLint | `npx eslint@<VERSION> src/` |275| Python | Pylint, Flake8 | `python -m pylint src/` |276| C#/.NET | StyleCop, Roslyn Analyzers | `dotnet build /p:RunAnalyzersDuringBuild=true` |277| Go | golint, golangci-lint | `golangci-lint run` |278| Ruby | RuboCop | `bundle exec rubocop` |279| PHP | PHPStan | `vendor/bin/phpstan analyse` |280| Scala | Scalastyle, Scapegoat | `sbt scalastyle scapegoat` |281282### Formatters by Stack283284| Stack | Formatter | Command |285|---|---|---|286| Java/Kotlin | Spotless, Google Java Format | `mvn spotless:apply` |287| JavaScript/TypeScript | Prettier | `npx prettier@<VERSION> --write src/` |288| Python | Black, isort | `python -m black src/` |289| C#/.NET | dotnet format | `dotnet format` |290| Go | gofmt, goimports | `gofmt -w .` |291| Ruby | Rufo | `bundle exec rufo` |292| PHP | PHP CS Fixer | `vendor/bin/php-cs-fixer fix` |293294### Coverage Tools by Stack295296| Stack | Tool | Command |297|---|---|---|298| Java/Kotlin | JaCoCo | `mvn jacoco:report` |299| JavaScript/TypeScript | Istanbul | `npx vitest@<VERSION> run --coverage` |300| Python | Coverage.py | `python -m coverage run -m pytest` |301| C#/.NET | OpenCover, Cobertura | `dotnet test /p:CollectCoverage=true /p:CoverageFormat=cobertura` |302| Go | go test -cover | `go test -cover ./...` |303| Ruby | SimpleCov | `bundle exec rspec --coverage` |304| PHP | phpunit --coverage-clover | `vendor/bin/phpunit --coverage-clover=coverage.xml` |305| Scala | sbt coverage | `sbt clean coverage test coverageReport` |306307### SonarLint and SonarScanner308309The skill may use SonarLint and SonarScanner for local validation before committing:310311**SonarLint (IDE Integration):**312- Available for IntelliJ IDEA, VS Code, Eclipse313- Validates code in real time314- Can be invoked via command line for batch validation315316**SonarScanner CLI:**317- For local scans before push318- Offline validation of fixes319- Command: `sonar-scanner -Dsonar.projectKey=<project> -Dsonar.sources=src`320321### Validation Scripts322323The skill loads reference scripts for automatic validation per stack:324325- `references/validate-java.sh` — Java/Kotlin validation (Checkstyle, PMD, Spotless, JaCoCo)326- `references/validate-js.sh` — JavaScript/TypeScript validation (ESLint, Prettier, Vitest)327- `references/validate-python.sh` — Python validation (Pylint, Flake8, Black, pytest)328- `references/validate-csharp.sh` — C#/.NET validation (Roslyn Analyzers, dotnet format, dotnet test)329- `references/validate-go.sh` — Go validation (golangci-lint, gofmt, go test)330- `references/validate-ruby.sh` — Ruby validation (RuboCop, Rufo, rspec)331- `references/validate-php.sh` — PHP validation (PHPStan, PHP CS Fixer, phpunit)332- `references/validate-scala.sh` — Scala validation (Scalastyle, Scapegoat, sbt)333334## 🎨 Test Templates by Stack335336The skill generates tests automatically based on stack-specific templates. Load the appropriate template from the `references/templates/` folder:337338- `test-java.md` — Template for JUnit/Mockito tests339- `test-kotlin.md` — Template for KotlinTest/Mockk tests340- `test-python.md` — Template for pytest/unittest tests341- `test-javascript.md` — Template for Jest/Vitest tests342- `test-typescript.md` — Template for TypeScript tests343- `test-csharp.md` — Template for xUnit/Moq tests344- `test-go.md` — Template for Go tests345- `test-ruby.md` — Template for RSpec/Minitest tests346- `test-php.md` — Template for PHPUnit tests347- `test-scala.md` — Template for ScalaTest/ScalaCheck tests348349### Tests and Coverage350- ✅ **100% coverage of modified lines** (verified in coverage report)351- ✅ **No coverage exclusions**, such as:352 - Comments: `// NOSONAR`, `// no sonar`, `# noqa`, `# pragma: no cover`, etc.353 - Decorators/Attributes: `@IgnoreCoverage`, `ExcludeFromCodeCoverage`, `@Suppress`, etc.354 - Compiler pragmas: `#pragma`, etc.355 - IMPORTANT: If the file already has a coverage exclusion, remove it and implement tests for the fix as well as for the rest of the file's code, ensuring full coverage.356- ✅ Remove SonarQube scanner files that may be present, such as `sonar-project.properties`, `sonar-scanner.properties`, etc. Also remove other scanners, such as the `SonarScanner for Maven` usually present in the POM.xml, since our pipeline is autonomous and does not depend on these files to work. (For now, keep only SonarQube-related configurations in `.csproj` files).357- ✅ All tests passing358- ✅ Coverage report available (formats: OpenCover, JaCoCo, Cobertura, Istanbul, etc.)359360### Code Quality361- ✅ No new code smells or SonarQube violations362- ✅ No functional regressions363- ✅ No obvious performance problems364- ✅ Minimal, targeted changes365- ✅ Code follows project conventions and standards366- ✅ No unnecessary changes in areas unrelated to the issue367368### Business Logic369- ✅ **Do not change** business logic without extreme necessity370- ✅ If it is necessary to change sensitive points (business rules, critical calculations, main flows):371 - Minimize the change372 - Document clearly in the review guide373 - Justify why it was unavoidable374 - Add specific tests to validate the change375376### Dependencies377- ✅ **Do not add** unnecessary dependencies378- ✅ Stay within the scope of SonarQube fixes379- ✅ If adding a dependency is absolutely necessary, justify and document it380- ✅ Check that there are no conflicts with existing dependencies381382## Completion Checklist383384- [ ] All issues analyzed and categorized in SONAR_FIX_TODO_BOARD.md385- [ ] All issues fixed with 100% test coverage386- [ ] All tests passing387- [ ] .gitignore updated with `.sonar_devin_auto_fix/**`388- [ ] SONAR_FIX_REVIEW_NOTES.md generated with complete instructions389- [ ] No new issue introduced (verified via code review and tests)390391## Useful Commands (Examples by Stack)392393### ⚠️ Important: Isolated Environments with Required Parameters394395**Commands are configured to force isolated environments. The isolation prefix is required, but you may add more parameters after it.**396397**Rule:** Keep the isolation parameter (e.g. `-Dmaven.repo.local=./.m2/repository`), but you may add more flags.398399### Java / Kotlin (Maven)400401```bash402# ✅ ALLOWED - Mandatory isolation + additional parameters403mvn -Dmaven.repo.local=./.m2/repository clean test404mvn -Dmaven.repo.local=./.m2/repository -DskipTests=false jacoco:report405mvn -Dmaven.repo.local=./.m2/repository -Dorg.slf4j.simpleLogger.defaultLogLevel=debug clean test406407# ❌ NOT ALLOWED - No isolation408mvn clean test409```410411### Java / Kotlin (Gradle)412413```bash414# ✅ ALLOWED - Mandatory isolation + additional flags415gradle --gradle-user-home ./.gradle test416gradle --gradle-user-home ./.gradle test --info417gradle --gradle-user-home ./.gradle clean build -x test418419# ❌ NOT ALLOWED - No isolation420gradle test421```422423### JavaScript / TypeScript / Node.js424425```bash426# npm ✅ ALLOWED427npm install --no-save428npm install --no-save --verbose429npm test -- --coverage --verbose430431# yarn ✅ ALLOWED432yarn install --offline433yarn install --offline --verbose434435# pnpm ✅ ALLOWED436pnpm install437pnpm install --verbose438439# npx ✅ ALLOWED only with pinned versions440npx vitest@<VERSION> run --coverage441npx eslint@<VERSION> src/442```443444### Python445446```bash447# Create venv (if not exists) ✅ ALLOWED448python -m venv .venv449python -m venv .venv --upgrade-deps450451# pip with isolation ✅ ALLOWED452python -m pip install -r requirements.txt -q453python -m pip install --target ./.venv/lib -q package-name454python -m pip install --target ./.venv/lib --upgrade package-name455456# pytest and coverage ✅ ALLOWED457python -m pytest --cov=src tests/ -v458python -m pytest --cov=src tests/ --cov-report=html459python -m coverage run -m pytest460python -m coverage report --skip-covered461```462463### C# / .NET464465```bash466# ✅ ALLOWED467dotnet test468dotnet test /p:CollectCoverage=true /p:CoverageFormat=cobertura469dotnet test /p:CollectCoverage=true /p:Exclude="[*Tests]*"470```471472### Go473474```bash475# ✅ ALLOWED476go test -cover ./...477go test -cover ./... -v478go test -coverprofile=coverage.out ./... -timeout=10m479```480481### Ruby / Rails482483```bash484# ✅ ALLOWED485bundle install --local486bundle install --local --no-deployment487bundle exec rspec --coverage488bundle exec rspec --coverage -f progress489```490491### PHP492493```bash494# ✅ ALLOWED495composer install --no-dev496composer install --no-dev --optimize-autoloader497composer install --no-dev --classmap-authoritative498vendor/bin/phpunit --coverage-clover=coverage.xml499vendor/bin/phpunit --coverage-clover=coverage.xml -v500```501502### Scala503504```bash505# ✅ ALLOWED506sbt clean coverage test coverageReport507sbt clean coverage test coverageReport -Dconfig=test508sbt "test -- -Dverbose=true"509```510511## 🧹 Environment Cleanup512513When finishing all fixes, run:514515```bash516git status517```518519Analyze the output and:520521- Temporary, build, coverage, or cache files that appear → add to `.gitignore`522- Staged files that **should not** be there → remove with `git restore --staged <file>`523- Confirm that `.sonar_devin_auto_fix/` **does not appear** as staged524525> ⚠️ **Do not commit.** Leave the repository clean and organized so the human developer can review and decide what to commit.526527### Cleanup of Isolated Environments (Optional)528529If the user asks to remove isolated environments after completion, **list the paths first and ask for explicit confirmation** before deleting anything. Do not run `rm -rf` or `find -exec rm -rf` without consent.530531```bash532# List what would be removed (do not delete automatically)533echo "The following paths could be removed: .venv .m2 node_modules .npm __pycache__ .pytest_cache"534# Ask the user to confirm before proceeding. Prefer `git clean` for tracked artifacts.535```536537**Important:** Verify that the isolated environments are in `.gitignore`:538539```bash540# Check if already in .gitignore541grep -E "^\.venv$|^\.m2$|^node_modules$|^__pycache__$" .gitignore542543# If not found, add them:544echo ".venv" >> .gitignore545echo ".m2" >> .gitignore546echo "node_modules" >> .gitignore547echo ".pytest_cache" >> .gitignore548echo "__pycache__" >> .gitignore549```550551## Important Notes552553- 🎯 Work in iterations: one issue at a time, with tests and documentation554- 📝 Keep code clean and aligned with the project's existing standard555- 🔍 Prioritize clarity and maintainability556- ⚠️ Always consider the impact of each change on business logic557- 🧹 **ALWAYS clean the environment when finishing** — no temporary file should remain pending558- ⚡ **Be efficient with time and tokens:** avoid unnecessary reads, excessive exploration, and repetitions. Read only what is strictly necessary to fix the issue at hand. Prefer direct and objective actions. Avoid invoking unnecessary tools — use only what the task requires.559- 🚫 **Do not implement anything beyond what was requested:** fix exclusively the issues listed in `sonarqube_issues.json`. Do not refactor without need, do not improve, do not add features, do not reorganize code that is not directly related to the issue.560- 🚫 **Do not run programming scripts that require human validation before release:** when trying to run scripts, a prompt is presented to the user to decide whether it can be executed, which removes your autonomy and generates more work for the user.561562## The Iron Law563564```565NO COVERAGE EXCLUSIONS566```567568No coverage exclusion may be used to bypass the lack of tests.569570**No exceptions:**571- Do not use `// NOSONAR`, `// no sonar`, `# noqa`, `# pragma: no cover`572- Do not use decorators such as `@IgnoreCoverage`, `ExcludeFromCodeCoverage`, `@Suppress`573- Do not use compiler pragmas such as `#pragma` for exclusions574- If the file already has an exclusion, remove it and implement tests for the code575- Ensure 100% coverage of the modified lines576577## Common Mistakes578579| Mistake | Consequence | How to avoid |580|------|-------------|-------------|581| Add coverage exclusions | Code without tests approved | Implement tests for all modified lines |582| Fix issues without tests | Undetected regressions | Always add unit tests for each fix |583| Change business logic without need | Bug risk | Stay within the scope of the SonarQube issue |584| Do not run linters after fixing | New violations introduced | Run stack linters after each fix |585| Do not clean environment at the end | Temporary files in repo | Run environment cleanup when finishing |586| Print environment variable values | Security violation | NEVER read or print tokens, use variables directly in commands |587588## Anti-Patterns589590### ❌ "This code is too simple to need a test"591592Even simple code can have bugs. TDD applies to any fix, regardless of complexity.593594### ❌ "I'll add a coverage exclusion just for this case"595596Coverage exclusions violate the quality principle. If the code is too complex to test, refactor it.597598### ❌ "SonarQube is wrong, I won't fix it"599600SonarQube can have false positives, but most issues are valid. Fix them and discuss legitimate cases with the team.601602### ❌ "I'll fix everything at once without tests"603604Bulk fixes without tests drastically increase the risk of regressions. Fix one issue at a time with tests.605606### ❌ "I don't need to run the local scan, the pipeline will validate"607608Local validation saves time and avoids pipeline rejections. Use the `sonar-local-scan.sh` script.609610## Adaptations for this catalog611612This skill follows the agent catalog standards:613- **Frontmatter** aligned to repo standard: `license: MIT`, `metadata.version`, `metadata.author`, tripartite `description` with explicit `Do NOT use for` clause614- **Language:** English (en-us) for content, technical terms in English615- **Branch policy:** follow `feature/{agent}-{YYYYMMDD}-{short-description}`616- **Git workflow:** branches created from `develop`, PR target is `develop` (not `main`)617618## Origin619620This skill was created following patterns from `obra/superpowers/skills/writing-skills` and adapted for SonarQube auto-fix workflows across multiple stacks.