sonarqube
Analyze SonarCloud quality issues for a specific PR
What this skill does
# SonarQube Analysis
Analyze SonarCloud quality issues for a specific PR. Generates comprehensive report with metrics, top violators, and action plan.
**Core principle:** Analysis-only = no code changes, pure insight.
## Process
1. **Verify Token**: Check `$SONARQUBE_TOKEN` environment variable
2. **Fetch Issues**: Call SonarCloud API for PR issues
3. **Parse Data**: Group by severity, type, file, rule
4. **Generate Report**: Structured output with action plan
5. **Cleanup**: Remove temporary files
## Prerequisites
### Environment Variable
```bash
# Set SonarQube token (add to ~/.bashrc or ~/.zshrc)
export SONARQUBE_TOKEN="your_token_here"
# Verify token is set
echo $SONARQUBE_TOKEN
```
**To get token:**
1. Go to SonarCloud โ My Account โ Security
2. Generate new token
3. Copy and export as environment variable
### Project Configuration
Configure your SonarCloud project details:
```bash
# Add to project's CLAUDE.md or as environment variables
SONAR_ORGANIZATION="your-org-name"
SONAR_PROJECT_KEY="your-org_your-project"
SONAR_BASE_URL="https://sonarcloud.io/api"
```
**If not set:** Ask user to provide organization and project key.
## Fetch Issues
**Important:** Direct curl with `-u "$SONARQUBE_TOKEN:"` fails in zsh due to authentication parsing. Use bash script wrapper:
```bash
# Create temporary bash script to handle authentication
cat > /tmp/fetch_sonar.sh << 'SCRIPT'
#!/bin/bash
curl -s -u "${SONARQUBE_TOKEN}:" \
"https://sonarcloud.io/api/issues/search?componentKeys=${SONAR_PROJECT_KEY}&pullRequest=$1&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true&ps=500"
SCRIPT
chmod +x /tmp/fetch_sonar.sh
/tmp/fetch_sonar.sh $PR_NUMBER > /tmp/sonar_pr_$PR_NUMBER.json
```
**API Parameters:**
- `componentKeys`: Your project key
- `pullRequest`: PR number
- `issueStatuses`: OPEN,CONFIRMED (exclude resolved)
- `sinceLeakPeriod`: Only new issues in this PR
- `ps`: Page size (max 500)
## Analysis Script
Create Node.js analysis script at `/tmp/sonar_analyze.js`:
```javascript
const fs = require('fs');
const prNumber = process.argv[2];
const data = JSON.parse(fs.readFileSync(`/tmp/sonar_pr_${prNumber}.json`, 'utf8'));
const issues = data.issues || [];
// Group by severity
const bySeverity = issues.reduce((acc, i) => {
acc[i.severity] = (acc[i.severity] || 0) + 1;
return acc;
}, {});
// Group by type
const byType = issues.reduce((acc, i) => {
acc[i.type] = (acc[i.type] || 0) + 1;
return acc;
}, {});
// Group by file
const byFile = issues.reduce((acc, i) => {
const file = i.component.split(':')[1] || i.component;
acc[file] = (acc[file] || 0) + 1;
return acc;
}, {});
// Group by rule
const byRule = issues.reduce((acc, i) => {
if (!acc[i.rule]) {
acc[i.rule] = {
count: 0,
severity: i.severity,
message: i.message
};
}
acc[i.rule].count++;
return acc;
}, {});
// Output structured data
console.log(JSON.stringify({
total: data.total,
bySeverity,
byType,
topFiles: Object.entries(byFile)
.sort((a, b) => b[1] - a[1])
.slice(0, 10),
topRules: Object.entries(byRule)
.map(([rule, d]) => ({ rule, ...d }))
.sort((a, b) => b.count - a.count)
.slice(0, 5)
}, null, 2));
```
**Run analysis:**
```bash
node /tmp/sonar_analyze.js $PR_NUMBER > /tmp/sonar_analysis_$PR_NUMBER.json
```
## Report Format
Generate formatted report from analysis:
```
๐ SonarCloud Analysis - PR #XXX
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ EXECUTIVE SUMMARY
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Total Issues: {TOTAL}
By Severity:
๐ด Blocker/Critical: {COUNT} ({PERCENTAGE}%)
๐ก Major: {COUNT} ({PERCENTAGE}%)
๐ต Minor/Info: {COUNT} ({PERCENTAGE}%)
By Type:
๐ Bugs: {COUNT}
๐ก๏ธ Vulnerabilities: {COUNT}
๐งน Code Smells: {COUNT}
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ TOP 10 FILES WITH ISSUES
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1. src/components/UserProfile.tsx - 8 issues
2. src/services/auth.service.ts - 5 issues
3. src/utils/validation.ts - 4 issues
...
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๏ธ TOP 5 VIOLATED RULES
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1. typescript:S1854 (MAJOR) - 12 occurrences
"Dead stores should be removed"
2. typescript:S3776 (CRITICAL) - 8 occurrences
"Cognitive Complexity of functions should not be too high"
3. typescript:S1186 (MINOR) - 6 occurrences
"Functions should not be empty"
...
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
ACTION PLAN
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Priority 1 - CRITICAL/BLOCKER ({COUNT} issues):
โข Fix immediately before merge
โข Focus on: {TOP_FILES}
Priority 2 - MAJOR ({COUNT} issues):
โข Address in this PR if possible
โข Consider technical debt ticket if extensive
Priority 3 - MINOR/INFO ({COUNT} issues):
โข Can be addressed in follow-up PR
โข Add to backlog for refactoring sprint
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ LINKS
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
View in SonarCloud:
https://sonarcloud.io/project/pull_requests_list?id={PROJECT_KEY}&pullRequest={PR_NUMBER}
```
## Severity Mapping
| SonarCloud | Symbol | Priority | Action |
|------------|--------|----------|--------|
| BLOCKER | ๐ด | P0 | Fix immediately |
| CRITICAL | ๐ด | P0 | Fix immediately |
| MAJOR | ๐ก | P1 | Fix in this PR |
| MINOR | ๐ต | P2 | Consider for follow-up |
| INFO | ๐ต | P3 | Optional improvement |
## Issue Types
| Type | Symbol | Description |
|------|--------|-------------|
| BUG | ๐ | Code that is demonstrably wrong |
| VULNERABILITY | ๐ก๏ธ | Security issues |
| CODE_SMELL | ๐งน | Maintainability issue |
| SECURITY_HOTSPOT | ๐ | Security-sensitive code to review |
## Cleanup
Always clean up temporary files after execution:
```bash
rm -f /tmp/fetch_sonar.sh
rm -f /tmp/sonar_pr_$PR_NUMBER.json
rm -f /tmp/sonar_analyze.js
rm -f /tmp/sonar_analysis_$PR_NUMBER.json
```
## Error Handling
| Error | Cause | Action |
|-------|-------|--------|
| Token not set | `$SONARQUBE_TOKEN` missing | Ask user to export token |
| 401 Unauthorized | Invalid or expired token | Request new token from SonarCloud |
| 404 Not Found | PR doesn't exist in SonarCloud | Verify PR number and project key |
| Empty response | No issues found | Report clean PR, congratulate team |
| >500 issues | Pagination limit reached | Warn about incomplete data, suggest filtering |
| Network error | API unreachable | Check internet connection, retry |
## Configuration Options
### Project-Level Configuration
Create `.sonarcloud.properties` or add to `CLAUDE.md`:
```properties
# SonarCloud Configuration
SONAR_ORGANIZATION=your-org
SONAR_PROJECT_KEY=your-org_your-project
SONAR_EXCLUSIONS=**/*.test.ts,**/*.spec.ts,**/migrations/**
SONAR_COVERAGE_EXCLUSIONS=**/*.test.ts,src/test/**
```
### API Rate Limits
SonarCloud API limits:
- Free tier: 10,000 requests/day
- Paid tier: Unlimited
**Tip:** Cache results for repeated queries to same PR.
## Integration Examples
### GitHub Actions
```yaml
- name: SonarQube Analysis
run: |
export SONARQUBE_TOKEN=${{ secrets.SONAR_TOKEN }}
export SONAR_PROJECT_KEY="${{ secrets.SONAR_PROJECT }}"
claude -p "/sonarqube ${{ github.event.pull_request.number }}"
```
### Pre-merge Hook
Add to `.claude/hooks/pre-merge.sh`:
```bash
#!/bin/bash
PR_NUMBER=$(gh pr view --json number -q .number)
claude -p "/sonarqube $PR_NUMBER"
```
## Red Flags - NEVER Do
**Never:**
- โ Modify code or auto-fix issues (analysis-only command)
- โ Skip token verification (security risk)
- โ Leave temp files in `/tmp` (cleanup required)
- โ Commit SonarQube token to repository (use env vars)
- โ Run without checking token expiration
**Always:**
- โ
Generate structured, actionable report
- โ
Clean up after execution
- โ
Handle API errors gracefully
- โ
Verify token is valid before API calls
- โ
Parse and present data clearly
## Advanced Usage
### Custom Filters
```bash
# Only show critical/blocker issues
/sonarqube 123 --severity BLOCKER,CRITICAL
# Only show bugs and vulnerabilities
/sonarqube 123 --types BUG,VULNERABILITY
# SpRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.