feat: AI 修复预生成 + 审查面板 diff 预览两步确认 + SQLFluff 行号修复 + PMD 内置规则精简
- AI 修复预生成:静态/custom/AI 条目审查时预生成修复片段(originalText/newText),展开问题即显示行级 diff,无预生成时展示占位提示,匹配失败回退实时 LLM 生成 - 修复前 diff 预览:侧边新建编辑器组打开内置 diff,确认后写入(两步确认),不覆盖当前文件 - fix: sqlfluff 在 jinja 标签位于注释内时 JJ01 JSON 缺失 end_line_no/end_line_pos,适配器 Range 构造产生 NaN 被 VSCode 交换 start/end 导致行号 LNaN;新增 resolveSqlFluffRange 兜底 + 面板/report 行号 Number.isFinite 防御 - fix: 从 PMD 内置 ruleset 移除 5 条实际不可触发规则(AvoidAssertAsIdentifier、AvoidEnumAsIdentifier、AccessorClassGeneration、AccessorMethodGeneration、LoosePackageCoupling),内置配置 274→269 条全部可触发,同步 static-rules.json 与翻译脚本 - docs: README/DESIGN 更新
This commit is contained in:
+49
-19
@@ -105,8 +105,8 @@ function buildCustomRuleSystemPrompt(): string {
|
||||
return `あなたはコードルールレビュアーです。以下のカスタムルールに違反しているかどうかのみを評価してください。
|
||||
意味を理解し、テキストの一致ではなく判断してください。
|
||||
JSONのみを出力、形式:
|
||||
{ "customRuleResults": [{ "ruleId": "ルールID", "line": 行番号, "severity": "error|warning|info", "message": "違反の説明", "suggestion": "具体的な修正提案" }] }
|
||||
"suggestion" は実行可能な修正提案を必ず含めてください。
|
||||
{ "customRuleResults": [{ "ruleId": "ルールID", "line": 行番号, "severity": "error|warning|info", "message": "違反の説明", "suggestion": "具体的な修正提案", "fix": { "originalText": "置換対象のコード原文(コードコンテキスト内に完全一致すること、行番号プレフィックスなし)", "newText": "修正後のコード片" } }] }
|
||||
各違反に対して必ず実行可能な "suggestion" を含め、可能な場合は適用可能な "fix" も提供してください。
|
||||
ルールに違反していない場合は空の配列を返してください。
|
||||
|
||||
出力言語:ja`;
|
||||
@@ -115,8 +115,8 @@ JSONのみを出力、形式:
|
||||
return `You are a code rule reviewer. Only evaluate whether the following custom rules are violated.
|
||||
Understand semantics, not text matching.
|
||||
Output JSON only, format:
|
||||
{ "customRuleResults": [{ "ruleId": "rule id", "line": line number, "severity": "error|warning|info", "message": "violation description", "suggestion": "concrete fix suggestion" }] }
|
||||
Always include a concrete actionable "suggestion" for each violation.
|
||||
{ "customRuleResults": [{ "ruleId": "rule id", "line": line number, "severity": "error|warning|info", "message": "violation description", "suggestion": "concrete fix suggestion", "fix": { "originalText": "the exact code snippet to replace (must exist verbatim in the code context, without the line-number prefix)", "newText": "the fixed code snippet" } }] }
|
||||
Always include a concrete actionable "suggestion" for each violation, and provide an applicable "fix" snippet when possible.
|
||||
If no rules are violated, return an empty array.
|
||||
|
||||
Output language: en`;
|
||||
@@ -124,8 +124,8 @@ Output language: en`;
|
||||
return `你是代码规则审查员,只评估以下自定义规则是否被违反。
|
||||
理解语义而非文本匹配。
|
||||
仅输出 JSON,格式:
|
||||
{ "customRuleResults": [{ "ruleId": "规则ID", "line": 行号, "severity": "error|warning|info", "message": "触发描述", "suggestion": "具体的修复建议" }] }
|
||||
每条违规都必须给出可执行的 "suggestion" 修复建议。
|
||||
{ "customRuleResults": [{ "ruleId": "规则ID", "line": 行号, "severity": "error|warning|info", "message": "触发描述", "suggestion": "具体的修复建议", "fix": { "originalText": "待替换的代码原文(必须在代码上下文中逐字存在,不含行号前缀)", "newText": "修复后的代码片段" } }] }
|
||||
每条违规都必须给出可执行的 "suggestion" 修复建议,并尽量提供可应用的 "fix" 修复片段。
|
||||
如果没有违反任何规则,返回空数组。
|
||||
|
||||
输出语言:zh-CN`;
|
||||
@@ -137,7 +137,7 @@ function buildDeepReviewSystemPrompt(): string {
|
||||
return `あなたはシニアコードレビュー専門家です。2つのタスクを実行してください:
|
||||
1. 英語の静的解析結果を出力言語に翻訳し、修正提案を追加する
|
||||
2. コードを詳細にレビューし、静的解析でカバーされていない問題を発見する
|
||||
重点分野:セキュリティ脆弱性、論理エラー、パフォーマンス問題、設計欠陥
|
||||
重点分野:セキュリティ脆弱性、ロジックエラー、パフォーマンス問題、設計欠陥
|
||||
静的解析ですでに報告された問題を重複しないでください。
|
||||
|
||||
translatedDiagnosticsの要件:
|
||||
@@ -145,12 +145,17 @@ translatedDiagnosticsの要件:
|
||||
- "originalRuleId" はリスト内のルールID(eslint: 等のプレフィックスを含む)をそのままコピーし、書き換えないでください
|
||||
- "translatedMessage" と "translatedSuggestion" は両方必須で、空にしないでください
|
||||
- "translatedSuggestion" は具体的で実行可能な修正提案(例:この書き方に置き換える)を示してください
|
||||
- 可能な場合は各診断に適用可能な "fix" を提供してください
|
||||
|
||||
findingsの要件:
|
||||
- 可能な場合は各発見に適用可能な "fix" を提供してください
|
||||
- "fix.originalText" は提供されたコード内に逐語的に存在すること(行番号プレフィックスなし)
|
||||
|
||||
JSONのみを出力。文字列内の二重引用符は \\" でエスケープしてください。
|
||||
形式:
|
||||
{
|
||||
"translatedDiagnostics": [{ "originalRuleId": "元のID", "translatedMessage": "翻訳メッセージ", "translatedSuggestion": "提案" }],
|
||||
"findings": [{ "ruleId": "kebab-case", "severity": "error|warning|info", "category": "bug|performance|security|style|design", "title": "タイトル", "description": "説明", "suggestion": "提案", "line": 行番号 }]
|
||||
"translatedDiagnostics": [{ "originalRuleId": "元のID", "translatedMessage": "翻訳メッセージ", "translatedSuggestion": "提案", "fix": { "originalText": "置換対象のコード原文(行番号プレフィックスなし)", "newText": "修正後のコード片" } }],
|
||||
"findings": [{ "ruleId": "kebab-case", "severity": "error|warning|info", "category": "bug|performance|security|style|design", "title": "タイトル", "description": "説明", "suggestion": "提案", "line": 行番号, "fix": { "originalText": "置換対象のコード原文(行番号プレフィックスなし)", "newText": "修正後のコード片" } }]
|
||||
}
|
||||
|
||||
出力言語:ja`;
|
||||
@@ -167,12 +172,17 @@ translatedDiagnostics requirements:
|
||||
- "originalRuleId" must be copied verbatim from the listed rule IDs (keep prefixes like eslint:), do not rewrite
|
||||
- "translatedMessage" and "translatedSuggestion" are both required and must not be empty
|
||||
- "translatedSuggestion" should be a concrete actionable fix suggestion (e.g. what to replace it with), not just a replacement snippet
|
||||
- Provide an applicable "fix" snippet for each diagnostic when possible
|
||||
|
||||
findings requirements:
|
||||
- Provide an applicable "fix" snippet for each finding when possible
|
||||
- "fix.originalText" must exist verbatim in the provided code (without the line-number prefix)
|
||||
|
||||
Output JSON only. Double quotes in strings must be escaped with \\".
|
||||
Format:
|
||||
{
|
||||
"translatedDiagnostics": [{ "originalRuleId": "original id", "translatedMessage": "translated message", "translatedSuggestion": "suggestion" }],
|
||||
"findings": [{ "ruleId": "kebab-case", "severity": "error|warning|info", "category": "bug|performance|security|style|design", "title": "title", "description": "description", "suggestion": "suggestion", "line": line number }]
|
||||
"translatedDiagnostics": [{ "originalRuleId": "original id", "translatedMessage": "translated message", "translatedSuggestion": "suggestion", "fix": { "originalText": "exact snippet to replace (without line-number prefix)", "newText": "fixed snippet" } }],
|
||||
"findings": [{ "ruleId": "kebab-case", "severity": "error|warning|info", "category": "bug|performance|security|style|design", "title": "title", "description": "description", "suggestion": "suggestion", "line": line number, "fix": { "originalText": "exact snippet to replace (without line-number prefix)", "newText": "fixed snippet" } }]
|
||||
}
|
||||
|
||||
Output language: en`;
|
||||
@@ -188,12 +198,17 @@ translatedDiagnostics 要求:
|
||||
- "originalRuleId" 必须原样复制列表中的规则 ID(保留 eslint: 等前缀),不得改写
|
||||
- "translatedMessage" 与 "translatedSuggestion" 均为必填字段,不得为空
|
||||
- "translatedSuggestion" 给出具体可执行的修复建议(如应替换成什么写法),不要只给替换片段
|
||||
- 尽量为每条诊断提供 "fix" 可应用修复片段
|
||||
|
||||
findings 要求:
|
||||
- 尽量为每条发现提供 "fix" 可应用修复片段
|
||||
- "fix.originalText" 必须在提供的代码中逐字存在(不含行号前缀)
|
||||
|
||||
仅输出 JSON,字符串中的双引号必须用 \\" 转义。
|
||||
格式:
|
||||
{
|
||||
"translatedDiagnostics": [{ "originalRuleId": "原始ID", "translatedMessage": "翻译", "translatedSuggestion": "建议" }],
|
||||
"findings": [{ "ruleId": "kebab-case", "severity": "error|warning|info", "category": "bug|performance|security|style|design", "title": "标题", "description": "描述", "suggestion": "建议", "line": 行号 }]
|
||||
"translatedDiagnostics": [{ "originalRuleId": "原始ID", "translatedMessage": "翻译", "translatedSuggestion": "建议", "fix": { "originalText": "待替换的代码原文(不含行号前缀)", "newText": "修复后的代码片段" } }],
|
||||
"findings": [{ "ruleId": "kebab-case", "severity": "error|warning|info", "category": "bug|performance|security|style|design", "title": "标题", "description": "描述", "suggestion": "建议", "line": 行号, "fix": { "originalText": "待替换的代码原文(不含行号前缀)", "newText": "修复后的代码片段" } }]
|
||||
}
|
||||
|
||||
输出语言:zh-CN`;
|
||||
@@ -430,7 +445,8 @@ Report violations in "customRuleResults".\n\n`
|
||||
"line": line_number,
|
||||
"severity": "error|warning|info",
|
||||
"message": "violation description",
|
||||
"suggestion": "concrete fix suggestion"
|
||||
"suggestion": "concrete fix suggestion",
|
||||
"fix": { "originalText": "exact snippet to replace (without line-number prefix)", "newText": "fixed snippet" }
|
||||
}
|
||||
],\n`
|
||||
: '';
|
||||
@@ -456,6 +472,9 @@ F. Testability: side effect isolation, dependency mockability, deterministic out
|
||||
- Check whether this method's return value is correctly handled by callers
|
||||
- Check whether exceptions are caught or declared by callers
|
||||
|
||||
Provide an applicable "fix" snippet for each finding when possible.
|
||||
"fix.originalText" must exist verbatim in the provided method code (without the line-number prefix).
|
||||
|
||||
Output JSON only. Double quotes in strings must be escaped with \\".
|
||||
Format:
|
||||
{
|
||||
@@ -468,7 +487,8 @@ ${ruleOutput} "findings": [
|
||||
"description": "detailed description",
|
||||
"suggestion": "fix suggestion",
|
||||
"line": line_number,
|
||||
"path": "trigger path description, e.g. if(order==null) -> NPE on .getId()"
|
||||
"path": "trigger path description, e.g. if(order==null) -> NPE on .getId()",
|
||||
"fix": { "originalText": "exact snippet to replace (without line-number prefix)", "newText": "fixed snippet" }
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -491,7 +511,8 @@ function buildMethodSystemPromptZh(hasRules: boolean): string {
|
||||
"line": 行号,
|
||||
"severity": "error|warning|info",
|
||||
"message": "违规描述",
|
||||
"suggestion": "具体的修复建议"
|
||||
"suggestion": "具体的修复建议",
|
||||
"fix": { "originalText": "待替换的代码原文(不含行号前缀)", "newText": "修复后的代码片段" }
|
||||
}
|
||||
],\n`
|
||||
: '';
|
||||
@@ -517,6 +538,9 @@ F. 可测试性:副作用隔离、依赖可 Mock 性、确定性输出
|
||||
- 检查本方法的返回值是否被调用者正确处理
|
||||
- 检查异常是否被调用者捕获或声明
|
||||
|
||||
尽可能为每条发现提供可应用的 "fix" 修复片段。
|
||||
"fix.originalText" 必须在提供的方法代码中逐字存在(不含行号前缀)。
|
||||
|
||||
输出 JSON,字符串中的双引号必须用 \\" 转义。
|
||||
格式:
|
||||
{
|
||||
@@ -529,7 +553,8 @@ ${ruleOutput} "findings": [
|
||||
"description": "详细描述",
|
||||
"suggestion": "修复建议",
|
||||
"line": 行号,
|
||||
"path": "触发路径描述,如 if(order==null) -> NPE on .getId()"
|
||||
"path": "触发路径描述,如 if(order==null) -> NPE on .getId()",
|
||||
"fix": { "originalText": "待替换的代码原文(不含行号前缀)", "newText": "修复后的代码片段" }
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -552,7 +577,8 @@ function buildMethodSystemPromptJa(hasRules: boolean): string {
|
||||
"line": 行番号,
|
||||
"severity": "error|warning|info",
|
||||
"message": "違反の説明",
|
||||
"suggestion": "具体的な修正提案"
|
||||
"suggestion": "具体的な修正提案",
|
||||
"fix": { "originalText": "置換対象のコード原文(行番号プレフィックスなし)", "newText": "修正後のコード片" }
|
||||
}
|
||||
],\n`
|
||||
: '';
|
||||
@@ -578,6 +604,9 @@ F. テスタビリティ:副作用の分離、依存のモック化容易性
|
||||
- このメソッドの戻り値が呼び出し元で正しく処理されているか確認
|
||||
- 例外が呼び出し元でキャッチまたは宣言されているか確認
|
||||
|
||||
可能な場合は各発見に適用可能な "fix" を提供してください。
|
||||
"fix.originalText" は提供されたメソッドコード内に逐語的に存在すること(行番号プレフィックスなし)。
|
||||
|
||||
JSONのみを出力。文字列内の二重引用符は \\" でエスケープしてください。
|
||||
形式:
|
||||
{
|
||||
@@ -590,7 +619,8 @@ ${ruleOutput} "findings": [
|
||||
"description": "詳細な説明",
|
||||
"suggestion": "修正提案",
|
||||
"line": 行番号,
|
||||
"path": "トリガーパス説明、例: if(order==null) -> .getId() で NPE"
|
||||
"path": "トリガーパス説明、例: if(order==null) -> .getId() で NPE",
|
||||
"fix": { "originalText": "置換対象のコード原文(行番号プレフィックスなし)", "newText": "修正後のコード片" }
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user