본문으로 건너뛰기
cccskills
무료GitHub에 공개

sonarqube

Analyze SonarCloud findings for a pull request, a proposed code change. Group issues by severity, type, file, and rule, then produce a report highlighting frequent problems and recommended priorities without modifying code.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

원문원문 설명 보기

Analyze SonarCloud quality issues for a specific PR

연동 도구GitHub
설치 방법 보기

이럴 때 유용합니다

  • Reviewing quality findings before merging a pull request
  • Finding files and rules with the most issues
  • Prioritizing bugs and security findings
  • Preparing an analysis report without code changes

포함된 파일(1)

  • SKILL.md9.9 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

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

# 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:

# 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:

# 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:

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:

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

SonarCloudSymbolPriorityAction
BLOCKER🔴P0Fix immediately
CRITICAL🔴P0Fix immediately
MAJOR🟡P1Fix in this PR
MINOR🔵P2Consider for follow-up
INFO🔵P3Optional improvement

Issue types

TypeSymbolDescription
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:

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

ErrorCauseAction
Token not set$SONARQUBE_TOKEN missingAsk user to export token
401 UnauthorizedInvalid or expired tokenRequest new token from SonarCloud
404 Not FoundPR doesn't exist in SonarCloudVerify PR number and project key
Empty responseNo issues foundReport clean PR, congratulate team
>500 issuesPagination limit reachedWarn about incomplete data, suggest filtering
Network errorAPI unreachableCheck internet connection, retry

Configuration options

Project-level configuration

Create .sonarcloud.properties or add to CLAUDE.md:

# 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

- 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:

#!/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

# Only show critical/blocker issues
/sonarqube 123 --severity BLOCKER,CRITICAL

# Only show bugs and vulnerabilities
/sonarqube 123 --types BUG,VULNERABILITY

# Specific file pattern
/sonarqube 123 --files "src/services/**"

Multiple PRs

# Compare issues across PRs
/sonarqube 123,124,125 --compare

Troubleshooting

Issue: "curl: (22) The requested URL returned error: 401"

Cause: Invalid or missing token

Fix:

# Regenerate token in SonarCloud
# Export new token
export SONARQUBE_TOKEN="new_token_here"

Issue: "Empty response or no issues"

Cause: Analysis not yet complete or PR not analyzed

Fix: Wait for SonarCloud analysis to complete (~2-5 minutes after PR creation)

Issue: "componentKeys not found"

Cause: Wrong project key

Fix: Verify project key in SonarCloud URL:

https://sonarcloud.io/project/overview?id=YOUR_PROJECT_KEY

Usage examples

# Basic usage
/sonarqube 170

# With PR prefix
/sonarqube PR #234

# Using PR URL
/sonarqube https://github.com/org/repo/pull/170

# Custom severity filter (if implemented)
/sonarqube 170 --critical-only

PR Number: $ARGUMENTS

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Evaluate Claude Code agents, skills, and commands with weighted quality criteria. Get scores, readiness grades, template comparisons, and practical improvement suggestions in Markdown or JSON reports to guide reviews before release.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Review skills before release
  • Compare agent definitions with reference templates
  • Quickly check critical quality criteria
FlorianBruniaux/claude-code-ultimate-guide6.2천2026년 10월 20일 업데이트

Assess a codebase across seven areas, including exposed credentials, security, dependencies, structure, and tests. Receive category scores, findings tied to file locations, and a prioritized improvement plan with smaller tasks that can be completed quickly.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Assessing the overall health of an inherited project
  • Reviewing exposed credentials and security risks
  • Identifying dependency and test coverage gaps
FlorianBruniaux/claude-code-ultimate-guide6.2천2026년 10월 20일 업데이트

Measure code patterns such as casts to any or disabled lint rules, then run repeated, targeted edits. Keep changes that improve the chosen metric, revert unsuccessful changes, and track results for each improvement loop.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Finding code patterns to prioritize for cleanup
  • Preparing measurement files for an improvement loop
  • Repeating targeted edits to reduce casts to any
FlorianBruniaux/claude-code-ultimate-guide6.2천2026년 10월 20일 업데이트

best-of-n

무료

Generate several separate solutions, compare them against criteria fixed in advance, and verify the selected result through executable checks or an independent reviewer. Keep a proof log documenting candidates, evidence, failures, and remaining limits.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Comparing implementation options before choosing one
  • Verifying a solution when a wrong choice would be costly
  • Keeping evaluation evidence for delivery or audit
FlorianBruniaux/claude-code-ultimate-guide6.2천2026년 10월 20일 업데이트

canary

무료

Monitor a live application after deployment and compare it with a saved baseline, a record of its earlier state. Check page responses, loading times, and new errors, flag persistent changes, and produce a per-page health report.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Recording a healthy baseline before deployment
  • Monitoring production immediately after deployment
  • Checking key pages for slower responses or failures
FlorianBruniaux/claude-code-ultimate-guide6.2천2026년 10월 20일 업데이트

catchup

무료

Rebuild project context after clearing a conversation or returning to work. Review recent Git history, uncommitted changes, and TODO markers to get a structured summary of project status and suggested next steps.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Restoring project context after /clear
  • Reviewing recent changes after a long break
  • Checking unfinished work before choosing the next task
FlorianBruniaux/claude-code-ultimate-guide6.2천2026년 10월 20일 업데이트

FlorianBruniaux의 스킬 모두 보기

이 스킬의 문제 신고