(options: StaticAnalysisOptions)
| 72 | } |
| 73 | |
| 74 | export async function runStaticAnalysis(options: StaticAnalysisOptions): Promise<string> { |
| 75 | const targetPath = options.targetPath ? resolve(options.rootDir, options.targetPath) : options.rootDir; |
| 76 | const ext = extname(targetPath); |
| 77 | |
| 78 | if (ext) { |
| 79 | const linter = await detectAvailableLinter(options.rootDir, ext); |
| 80 | if (!linter) return `No linter configured for ${ext} files.`; |
| 81 | |
| 82 | const args = [...linter.args]; |
| 83 | if ([".js", ".ts", ".tsx"].includes(ext)) args.push(targetPath); |
| 84 | else if (ext === ".py") args.push(targetPath); |
| 85 | |
| 86 | const result = await runCommand(linter.cmd, args, options.rootDir); |
| 87 | |
| 88 | if (result.exitCode === 0 && !result.output) return "No issues found. Code is clean."; |
| 89 | return `Static analysis (${result.tool}):\n\n${result.output.substring(0, 5000)}`; |
| 90 | } |
| 91 | |
| 92 | const results: string[] = []; |
| 93 | for (const [fileExt] of Object.entries(LINTER_MAP)) { |
| 94 | const linter = await detectAvailableLinter(options.rootDir, fileExt); |
| 95 | if (!linter) continue; |
| 96 | |
| 97 | const result = await runCommand(linter.cmd, linter.args, options.rootDir); |
| 98 | if (result.output) { |
| 99 | results.push(`[${result.tool}] ${fileExt} files:\n${result.output.substring(0, 2000)}`); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | return results.length > 0 ? results.join("\n\n") : "No linters available or no issues found."; |
| 104 | } |
no test coverage detected