360 Secure SkillHub
360 安全技能中心

sonar-fix-issue

该 Skill 接收 SonarQube 规则键、文件路径和可选行号,也支持自然语言描述;通过 MCP 或 sonar CLI 查询规则说明,读取目标文件后做最小修复,并解释违规原因与改动。若规则查询工具不可用,则依赖内置知识完成修复。

分类:开发
SonarSource
热度 34.44
最近更新 2026-11-25 05:14:05

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add sonarsource/sonarqube-agent-plugins/sonar-fix-issue
兼容性
通用兼容
联网要求
不联网
数据出网
可选出网
Metadata
name
sonar-fix-issue
description
Fix a specific SonarQube issue in code by rule key and location
argument-hint
[rule-key] [file-path:line]
allowed-tools
Read, Edit, Bash(sonar:*)

SonarQube — Fix Issue

Fix a code quality or security issue identified by SonarQube.

Usage

sonar-fix-issue java:S1481 src/main/java/MyClass.java:42
sonar-fix-issue python:S2077 src/auth/login.py
sonar-fix-issue Remove unused variable in MyClass.java

Instructions

Step 1: Identify the issue

Parse the user-provided arguments for:

  • A rule key (e.g. java:S1481, python:S2077)
  • A file path and optional line number (e.g. src/auth/login.py:34)
  • Or a plain-language description if no rule key is given

If neither a rule key nor a file path can be determined, ask: "Which rule and file should I fix?"

Step 2: Look up the rule (if a key was given)

Call mcp__sonarqube__show_rule with the rule key to retrieve the full rule description, rationale, and remediation guidance before touching any code. Do not add extra parameters (such as projectKey) unless the tool schema requires them — after integration, rule lookup usually needs only the rule key.

If the MCP tool is unavailable, fall back to sonar api get "/api/rules/show?key=<rule-key>". If sonar is also unavailable or unauthenticated, rely on built-in knowledge of SonarQube rules.

Step 3: Read the file

Read the full file content. If a line number was given, focus analysis around that line but read the whole file to understand context.

Step 4: Apply the fix

  • Make the minimal change that resolves the rule violation
  • Do not refactor surrounding code or fix unrelated issues
  • Preserve existing behaviour — the fix must not change what the code does

Step 5: Explain the change

After editing, briefly explain:

  • What the violation was
  • Why the rule flags it
  • What was changed and why it resolves the issue

Step 6: Suggest next steps

  • "Invoke the sonar-analyze skill with <file> to confirm no new issues were introduced."
  • "Invoke the sonar-list-issues skill with the project key (or sonar.projectKey in sonar-project.properties) — the CLI always uses -p."