@codacy/analysis-runner (英语)
目录
概览
Codacy Analysis CLI的核心管弦引擎. 发现工具、检查能力、呼叫 analyze() ,并转换输出。 CLI和IDE的整合方案都可用.
快开始
工具适配器生活在一个伴机预设包中, @codacy/analysis-adaptersA级
消费者安装并登记内置适配器 一次 运行前
任何与工具相关的工具 —— 运行器的适配器注册开始为空而无
自动人口.
import { registerBuiltinAdapters } from "@codacy/analysis-adapters";
import { analyze, createNullLogger } from "@codacy/analysis-runner";
// Register all built-in tools + cloud-only descriptors (call once at startup).
registerBuiltinAdapters();
// Run analysis. `repositoryRoot` must be a git work tree.
const result = await analyze({
repositoryRoot: "/abs/path/to/repo",
// files: ["src/index.ts"], // optional: scope to specific files
logger: createNullLogger(), // or bring your own Logger (see below)
});
// Issue paths are repo-relative; line/column are 1-based.
for (const issue of result.issues) {
console.log(
`${issue.filePath}:${issue.line}:${issue.column} ${issue.patternId} ${issue.message}`,
);
}
只注册一个工具子集,导入 builtinAdapterEntries 从预设和
调用 registerLazyAdapter(descriptor, load) 为了你想要的那些.
创建配置
analyze() 读取 .codacy/codacy.config.json在方案上产生一个
init* 家庭——他们建立 CodacyConfig 从登记的适配器; writeCodacyConfig
坚持:
import {
getRegisteredAdapters,
initLocalConfig, // local-config detection only (offline)
// initDefaultConfig / initAutoConfig / initRemoteConfig also available
writeCodacyConfig,
} from "@codacy/analysis-runner";
const adapters = await getRegisteredAdapters();
const { config } = await initLocalConfig(repositoryRoot, adapters);
await writeCodacyConfig(repositoryRoot, config);
initAutoConfig 此外,还采用已登记的描述符(getRegisteredDescriptors()(中文(简体) )
和预设 loadUnsupportedPatterns 切入门堆栈专用图案; initRemoteConfig
从 Codacy Cloud 取出配置( 通过 API 令牌 —— 参见下面的证书助手) .
自定义日志和取消
- 自己传
Logger(单位:千美元)@codacy/tooling合同:debug编号 :info编号 :warn编号 :error(中文(简体) ) 以路径进度进入您的用户界面,或createNullLogger()为了沉默。 执行 没有 使用情况createLogger()在嵌入器中——它写到文件/sderr. 驱动进度 UI 从onToolStart编号 :onToolComplete编号 :onToolProgress调用AnalyzeOptions。 。 。 . - 过
signal: AbortSignal打开AnalyzeOptions取消飞行中运行; 信号荣誉 适配器返回部分结果,剩余工具被标记被取消.
API 密码
| 导出 | 目的 |
|---|---|
analyze(options) | 主要切入点——运行全分析管. 选项包括 repositoryRoot, (中文(简体) ), tools, (中文(简体) ), files, (中文(简体) ), logger, (中文(简体) ), signal,以及 onTool* 进度回调 |
registerAdapter(adapter) 编号 : registerLazyAdapter(descriptor, load) | 注册工具适配器( eager/ 懒惰) |
clearAdapters() | 重置适配器登记册(供测试) |
getRegisteredAdapters() 编号 : getRegisteredDescriptors() | 列出已注册适配器/描述符 |
initLocalConfig() 编号 : initDefaultConfig() 编号 : initAutoConfig() 编号 : initRemoteConfig() | 构建一个 CodacyConfig (本地,默认,堆积意识,或云源) |
readCodacyConfig() 编号 : writeCodacyConfig() | 读取/写作 .codacy/codacy.config.json |
buildToolConfig() | 从 CodacyConfig + 本地配置集合 Codacy ToolFig |
discover(path) | 扫描回波并报告语言、框架、库和显著文件 |
formatOutput(result, format) | 将分析结果转换为格式化的字符串 |
createLogger() 编号 : createNullLogger() | 文件/stderr记录器(CLI) / no-op记录器(嵌入器) |
saveCredentials() 编号 : loadCredentials() 编号 : deleteCredentials() 编号 : resolveApiToken() | 机器存储的 API- token 存储在 ~/.codacy/credentials |
validateApiToken() 编号 : configureApiToken() 编号 : listIgnoredFiles() | Codacy Cloud API 帮助者 |
适配器 登记 住在伴侣的预设中
@codacy/analysis-adapters(单位:千美元)registerBuiltinAdapters, (中文(简体) ),builtinAdapterEntries),不在这里——跑者留下 工具不可识别.
管道步骤
- 发现注册的适配器(由
options.tools如果设置) - 检查可用性 • 构建能力报告
- 应用执行模式规则(标准/严格/自动安装/检查)
- 通过 git 发现文件, 应用排除层, 路径到工具
- 检查本地配置 + 构建 CodacyToolConfig 每个工具
- 执行
adapter.analyze()带有超时和货币控制 - 分析结果汇总
- 格式输出
输出格式
| 格式 | 说明 |
|---|---|
json | 漂亮打印的分析结果( 默认) |
sarif | SARIF v2.1.0 文档 |
container | 每行1个JSON对象(Codacy Docker跑车) |
text | 有颜色和分组的可读终端摘要 |
执行模式
| 模式 | 行为 |
|---|---|
standard | 跳过无法使用的工具, 报告它们( 默认) |
strict | 无法使用任何配置的工具时失败 |
auto-install | 试图在分析前安装缺失的工具 |
inspect | 干跑:报告能力不运行分析 |