dsh-git-push 2.20.18 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/cli-tool.mjs +2 -4
- package/cli.mjs +36 -2
- package/lib/app/apply.js +9 -9
- package/lib/app/command-registry.js +44 -20
- package/lib/app/handlers/meta.js +7 -142
- package/lib/app/handlers/npm.js +18 -1
- package/lib/app/handlers/preprocess.js +107 -0
- package/lib/app/handlers/repo-actions.js +2 -2
- package/lib/app/http-handlers.js +25 -12
- package/lib/app/index.js +2 -1
- package/lib/app/inject-text.js +3 -2
- package/lib/app/preprocess-client.js +136 -0
- package/lib/app/repo-ownership.js +1 -1
- package/lib/app/schema.js +3 -3
- package/lib/app/severity.js +14 -0
- package/lib/app/slash-commands.js +5 -164
- package/lib/app/tool-call.js +75 -140
- package/lib/app/tools.js +13 -6
- package/lib/cli/commands-preprocess.mjs +74 -0
- package/lib/cli/commands-tool.mjs +3 -2
- package/lib/cli/commands-vcs.mjs +4 -4
- package/lib/cli/shared.mjs +42 -13
- package/lib/client-parts/git/controller.js +2 -2
- package/lib/client.js +2 -2
- package/lib/commit-push/pre-commit-engine.js +57 -10
- package/lib/commit-push.js +125 -36
- package/lib/{exempt/index.js → git/exempt-markers.js} +8 -1
- package/lib/git/ignore.js +1 -1
- package/lib/git/repos.js +2 -2
- package/lib/git/sensitive.js +1 -1
- package/lib/npm/publish.js +20 -5
- package/lib/plugin/auto-push.js +2 -2
- package/lib/preprocess/providers.js +191 -0
- package/lib/self/index.js +1 -1
- package/lib/skip-dirs.js +14 -55
- package/package.json +29 -37
- package/scripts/build-client.mjs +2 -0
- package/scripts/check.mjs +4 -2
- package/scripts/local-registry.mjs +2 -1
- package/skills/dev/dsh-git-push.md +5 -0
- package/cli-audit.mjs +0 -141
- package/lib/app/audit-api.js +0 -173
- package/lib/app/host-doc-checks.js +0 -25
- package/lib/app/scope-check.js +0 -69
- package/lib/ast/brace.js +0 -120
- package/lib/ast/callgraph.js +0 -135
- package/lib/ast/code-lines.js +0 -175
- package/lib/ast/consts.js +0 -12
- package/lib/ast/control-flow.js +0 -470
- package/lib/ast/credential.js +0 -315
- package/lib/ast/dataflow.js +0 -391
- package/lib/ast/dup-code.js +0 -165
- package/lib/ast/fs-hotspots.js +0 -154
- package/lib/ast/index.js +0 -38
- package/lib/ast/io-risk-const.js +0 -95
- package/lib/ast/io-risk-fn.js +0 -208
- package/lib/ast/io-risk-loop.js +0 -308
- package/lib/ast/io-risk.js +0 -314
- package/lib/ast/lang.js +0 -156
- package/lib/ast/line-count.js +0 -52
- package/lib/ast/magic-number.js +0 -272
- package/lib/ast/naming.js +0 -292
- package/lib/ast/perf.js +0 -488
- package/lib/ast/scope-collisions.js +0 -228
- package/lib/ast/scope.js +0 -241
- package/lib/ast/shell.js +0 -131
- package/lib/ast/size.js +0 -448
- package/lib/ast/symbol-index.js +0 -399
- package/lib/ast/tokenizer.js +0 -421
- package/lib/ast/treesitter.js +0 -413
- package/lib/audit/analysis-coverage.js +0 -98
- package/lib/audit/audit-file.js +0 -205
- package/lib/audit/auditignore-rules.js +0 -148
- package/lib/audit/checks.js +0 -17
- package/lib/audit/client-entry.js +0 -93
- package/lib/audit/collector.js +0 -610
- package/lib/audit/ext-runner.js +0 -80
- package/lib/audit/file-context.js +0 -391
- package/lib/audit/finding.js +0 -101
- package/lib/audit/gitignore-match.js +0 -113
- package/lib/audit/glob.js +0 -63
- package/lib/audit/history-report.js +0 -100
- package/lib/audit/history.js +0 -126
- package/lib/audit/ignore-blind.js +0 -102
- package/lib/audit/index.js +0 -33
- package/lib/audit/orchestrate.js +0 -672
- package/lib/audit/public.js +0 -24
- package/lib/audit/repo-level.js +0 -30
- package/lib/audit/report-yaml.js +0 -90
- package/lib/audit/scope-policy.js +0 -110
- package/lib/audit/slot.js +0 -66
- package/lib/audit-rules/audit-rules-comment.yml +0 -199
- package/lib/audit-rules/audit-rules-cpp.yml +0 -114
- package/lib/audit-rules/audit-rules-csharp.yml +0 -82
- package/lib/audit-rules/audit-rules-docs.yml +0 -32
- package/lib/audit-rules/audit-rules-dsh.yml +0 -177
- package/lib/audit-rules/audit-rules-filehealth.yml +0 -42
- package/lib/audit-rules/audit-rules-folder.yml +0 -99
- package/lib/audit-rules/audit-rules-frontend.yml +0 -335
- package/lib/audit-rules/audit-rules-go.yml +0 -103
- package/lib/audit-rules/audit-rules-i18n.yml +0 -45
- package/lib/audit-rules/audit-rules-java.yml +0 -105
- package/lib/audit-rules/audit-rules-nodejs.yml +0 -662
- package/lib/audit-rules/audit-rules-npm.yml +0 -187
- package/lib/audit-rules/audit-rules-paths.yml +0 -98
- package/lib/audit-rules/audit-rules-performance.yml +0 -245
- package/lib/audit-rules/audit-rules-php.yml +0 -101
- package/lib/audit-rules/audit-rules-private.yml +0 -24
- package/lib/audit-rules/audit-rules-python.yml +0 -106
- package/lib/audit-rules/audit-rules-robustness.yml +0 -31
- package/lib/audit-rules/audit-rules-rust.yml +0 -109
- package/lib/audit-rules/audit-rules-structure.yml +0 -158
- package/lib/audit-rules/audit-rules-swift.yml +0 -99
- package/lib/audit-rules/audit-rules-template.yml +0 -108
- package/lib/audit-ui-sdk/contract.js +0 -117
- package/lib/audit-ui-sdk/index.js +0 -17
- package/lib/checks/button-bind.js +0 -347
- package/lib/checks/common.js +0 -170
- package/lib/checks/credential-file.js +0 -43
- package/lib/checks/dataflow.js +0 -40
- package/lib/checks/dispatch.js +0 -117
- package/lib/checks/dup-code.js +0 -69
- package/lib/checks/dup-const.js +0 -232
- package/lib/checks/file-health.js +0 -150
- package/lib/checks/filter.js +0 -137
- package/lib/checks/folder.js +0 -173
- package/lib/checks/fs-scanner.js +0 -57
- package/lib/checks/hardcoded-path.js +0 -98
- package/lib/checks/index.js +0 -49
- package/lib/checks/io.js +0 -66
- package/lib/checks/magic-number.js +0 -42
- package/lib/checks/npm-json.js +0 -273
- package/lib/checks/private.js +0 -64
- package/lib/checks/regex.js +0 -298
- package/lib/checks/scope-collision.js +0 -68
- package/lib/checks/semantic.js +0 -134
- package/lib/checks/structural.js +0 -281
- package/lib/cli/commands-audit.mjs +0 -142
- package/lib/cli/commands-doc.mjs +0 -127
- package/lib/client-parts/audit/audit.js +0 -301
- package/lib/exempt/tool.js +0 -198
- package/lib/git/module-splitter.js +0 -47
- package/lib/link-check/index.js +0 -187
- package/lib/lint-adapter/detect.js +0 -161
- package/lib/lint-adapter/index.js +0 -50
- package/lib/lint-adapter/runner.js +0 -133
- package/lib/rule/compilers/credential.js +0 -62
- package/lib/rule/compilers/dataflow.js +0 -38
- package/lib/rule/compilers/file-health.js +0 -75
- package/lib/rule/compilers/frontend.js +0 -86
- package/lib/rule/compilers/func.js +0 -35
- package/lib/rule/compilers/helpers.js +0 -71
- package/lib/rule/compilers/index.js +0 -29
- package/lib/rule/compilers/link-semantic.js +0 -45
- package/lib/rule/compilers/list-kinds.js +0 -12
- package/lib/rule/compilers/numeric-kinds.js +0 -73
- package/lib/rule/compilers/regex.js +0 -78
- package/lib/rule/compilers/structure.js +0 -107
- package/lib/rule/compilers.js +0 -17
- package/lib/rule/homoglyph.js +0 -45
- package/lib/rule/loader.js +0 -274
- package/lib/rule/registry.js +0 -122
- package/lib/rule/scope.js +0 -67
- package/lib/score/docs-score.js +0 -166
- package/lib/score/index.js +0 -234
- package/scripts/__pycache__/module-splitter.cpython-38.pyc +0 -0
- package/scripts/audit-ext/_example-readme-present.mjs +0 -34
- package/scripts/audit-ext/dsh-inject-declarations.mjs +0 -209
- package/scripts/audit-ext/variable-min-length.mjs +0 -102
- package/scripts/audit-gate.mjs +0 -235
- package/scripts/audit-runner.mjs +0 -35
- package/scripts/audit-runtime-check.mjs +0 -129
- package/scripts/browser-page-probe.mjs +0 -271
- package/scripts/check-js-scope.mjs +0 -87
- package/scripts/clean-date-comments.py +0 -102
- package/scripts/cpu-sample.mjs +0 -188
- package/scripts/doc-drift.mjs +0 -200
- package/scripts/hot-path-probe-cjs.cjs +0 -71
- package/scripts/hot-path-probe-fs-shim.mjs +0 -28
- package/scripts/hot-path-probe-fsp-shim.mjs +0 -31
- package/scripts/hot-path-probe.mjs +0 -153
- package/scripts/module-splitter.py +0 -800
- package/scripts/picker-repro.mjs +0 -115
- package/scripts/platform-scan.mjs +0 -168
- package/scripts/probe-recheck.mjs +0 -47
- package/scripts/rename-locator.mjs +0 -97
- package/scripts/rule-switch.mjs +0 -97
- package/scripts/rules-solo-audit.mjs +0 -173
- package/scripts/scan-file-io.mjs +0 -717
- package/scripts/scan-fs-hotspots.mjs +0 -107
- package/scripts/symbol-index.mjs +0 -85
- package/scripts/verify-prestep.mjs +0 -100
- package/skills/dev/audit-rule-authoring.md +0 -58
- package/skills/guide/guide-audit.md +0 -270
- /package/lib/{audit → app}/ownership.js +0 -0
- /package/lib/app/{schema-audit.js → schema-preprocess.js} +0 -0
- /package/lib/{audit-defaults.js → git/defaults.js} +0 -0
package/lib/ast/treesitter.js
DELETED
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AST 实现层 · tree-sitter(真语法树 · WASM)
|
|
3
|
-
*
|
|
4
|
-
* 定位:**可选增强,绝不是必需依赖**。任何一步失败(资产缺失 / wasm 加载失败 / 无对应语法 /
|
|
5
|
-
* 解析出语法错误 / 超出预算)都返回「未使用」信号,由调用方**回退**到
|
|
6
|
-
* lib/ast/code-lines.js 的 token 级判定(行级 + 列级,2.8.9 已落地)。
|
|
7
|
-
*
|
|
8
|
-
* 为什么这么设计:审计是提交门禁的一部分,**不能因为增强件坏了就整体失效** ✗。
|
|
9
|
-
* 回退不是异常路径,而是常态路径之一 ✓。
|
|
10
|
-
*
|
|
11
|
-
* 来源:**npm 依赖**——`web-tree-sitter@0.25.10`(运行时 + 它的 tree-sitter.wasm)与
|
|
12
|
-
* `tree-sitter-wasms@0.1.13`(各语言预编译 grammar,MIT)。仓库内不再保存任何 vendored 副本。
|
|
13
|
-
* 两者**必须精确锁版**:实测 web-tree-sitter@0.27.1 与本套语法 ABI 不兼容
|
|
14
|
-
* (在 getDylinkMetadata 处报空消息错误)⇒ 升版会让 AST 全线静默降级。
|
|
15
|
-
* 解析顺序(三级):`DSH_GIT_PUSH_TS_ASSETS` env 覆盖 → npm 包目录 → 两者都拿不到即返回「不可用」,
|
|
16
|
-
* 由调用方回退 token 级判定。
|
|
17
|
-
*
|
|
18
|
-
* 语言口径(既定口径):**加载哪些语言 = lib/audit-rules/ 里存在哪些语言规则包**
|
|
19
|
-
* (**空占位包也算**:cpp/go/php/rust/swift)。语法文件不存在时该语言自动走回退 ✓。
|
|
20
|
-
*/
|
|
21
|
-
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
22
|
-
import { createHash } from 'node:crypto';
|
|
23
|
-
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
24
|
-
import { dirname, join } from 'node:path';
|
|
25
|
-
|
|
26
|
-
/** env 覆盖的外部目录:内含 tree-sitter.js / tree-sitter.wasm / tree-sitter-<lang>.wasm。
|
|
27
|
-
* **回退路径测试**把它指向不存在的目录即可(测试不碰真实依赖 ✗);运维也可用它把资产指到别处。
|
|
28
|
-
* 在模块加载时求值,测试需用子进程改 env ✓ */
|
|
29
|
-
export const ASSETS_DIR = process.env.DSH_GIT_PUSH_TS_ASSETS || '';
|
|
30
|
-
|
|
31
|
-
/** 包目录(解析失败为空串 ⇒ 上层按「不可用」回退)。 */
|
|
32
|
-
let runtimeDir = null;
|
|
33
|
-
let grammarsDir = null;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 定位两个依赖包目录。
|
|
37
|
-
*
|
|
38
|
-
* 用 `import.meta.resolve` 而不是 `require.resolve`:本模块是 ESM,且 require 需要 createRequire 垫片。
|
|
39
|
-
* web-tree-sitter 有 exports 字段,`resolve('web-tree-sitter')` 拿到的是 **ESM 入口**
|
|
40
|
-
* tree-sitter.js(实测),取其 dirname 即包目录,`tree-sitter.wasm` 就在同级 ✓;
|
|
41
|
-
* `web-tree-sitter/package.json` 反而**不在 exports 白名单里**(ERR_PACKAGE_PATH_NOT_EXPORTED)⇒
|
|
42
|
-
* 想拿包目录只能由入口路径回溯,不要改成解析 package.json。
|
|
43
|
-
* tree-sitter-wasms 无 exports 字段 ⇒ 子路径可自由解析(这里解析一个必然存在的语法作为锚)。
|
|
44
|
-
* @returns {{runtimeDir: string, grammarsDir: string}}
|
|
45
|
-
*/
|
|
46
|
-
function resolveDirs() {
|
|
47
|
-
if (runtimeDir !== null && grammarsDir !== null) return { runtimeDir, grammarsDir };
|
|
48
|
-
const pick = (spec) => {
|
|
49
|
-
try { return dirname(fileURLToPath(import.meta.resolve(spec))); } catch { return ''; }
|
|
50
|
-
};
|
|
51
|
-
if (runtimeDir === null) runtimeDir = pick('web-tree-sitter');
|
|
52
|
-
if (grammarsDir === null) grammarsDir = pick('tree-sitter-wasms/out/tree-sitter-javascript.wasm');
|
|
53
|
-
// env 覆盖优先:指向一个「runtime 与语法同级」的目录(回退实验与运维换源都走这里)
|
|
54
|
-
if (ASSETS_DIR) { runtimeDir = ASSETS_DIR; grammarsDir = ASSETS_DIR; }
|
|
55
|
-
return { runtimeDir, grammarsDir };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** 扩展名 → 语法名(grammar)。没有映射的扩展名一律走回退 ✓。 */
|
|
59
|
-
export const EXT_TO_GRAMMAR = {
|
|
60
|
-
js: 'javascript', mjs: 'javascript', cjs: 'javascript', jsx: 'javascript',
|
|
61
|
-
ts: 'typescript', tsx: 'typescript', mts: 'typescript', cts: 'typescript',
|
|
62
|
-
py: 'python',
|
|
63
|
-
// ── 规则包早已存在、此前一直无语法树(走 token 级回退)的语言 ──
|
|
64
|
-
// 语法名以 tree-sitter-wasms@0.1.13 的 out/ 里**实际存在的文件名**为准(逐个核对过,不凭记忆写)。
|
|
65
|
-
// C# 的内部名带下划线:写成 csharp 会去找不存在的 wasm ⇒ 静默回退,规则表现成「看起来接不通」。
|
|
66
|
-
cs: 'c_sharp',
|
|
67
|
-
c: 'c',
|
|
68
|
-
cpp: 'cpp', cc: 'cpp', cxx: 'cpp', hpp: 'cpp', hh: 'cpp', hxx: 'cpp',
|
|
69
|
-
// .h 归属取 cpp 而非 c:C 与 C++ 共用该扩展名,cpp 语法是 C 的超集。
|
|
70
|
-
// 交给 c 语法时,合法 C++ 头文件会解析出 ERROR ⇒ 整棵树作废退回 token 级(等于白接);
|
|
71
|
-
// 反过来把纯 C 头交给 cpp 语法不会报错(C 是子集)。
|
|
72
|
-
h: 'cpp',
|
|
73
|
-
go: 'go',
|
|
74
|
-
java: 'java',
|
|
75
|
-
kt: 'kotlin',
|
|
76
|
-
php: 'php', phtml: 'php',
|
|
77
|
-
rs: 'rust',
|
|
78
|
-
swift: 'swift',
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/** 单文件解析预算(字符数):超此长度不解析,直接回退(避免大文件拖慢审计)。 */
|
|
82
|
-
const MAX_PARSE_CHARS = Number(process.env.DSH_GIT_PUSH_TS_MAX_CHARS || 400000) || 400000;
|
|
83
|
-
/** 语法树缓存条数上限(按内容 hash 命中)。 */
|
|
84
|
-
const TREE_CACHE_MAX = Number(process.env.DSH_GIT_PUSH_TS_TREE_CACHE || 64) || 64;
|
|
85
|
-
|
|
86
|
-
/** 惰性状态(模块级):web-tree-sitter 模块 / 初始化 Promise / 语言与解析器缓存。 */
|
|
87
|
-
let modPromise = null;
|
|
88
|
-
let initPromise = null;
|
|
89
|
-
const langCache = new Map();
|
|
90
|
-
const parserCache = new Map();
|
|
91
|
-
const treeCache = new Map(); // hash → tree(简单 FIFO 淘汰)
|
|
92
|
-
|
|
93
|
-
/** 资产是否就位(供调用方与自检使用)。 */
|
|
94
|
-
export function treesitterAvailable() {
|
|
95
|
-
try {
|
|
96
|
-
const { runtimeDir: rd } = resolveDirs();
|
|
97
|
-
if (!rd) return false;
|
|
98
|
-
// env 覆盖模式下 runtime 是目录里的 tree-sitter.js;npm 模式下入口由 exports 决定
|
|
99
|
-
// (tree-sitter.js / tree-sitter.mjs 都可能),故只校验「能拿到 ESM 入口 + 同级 wasm」。
|
|
100
|
-
return existsSync(join(rd, 'tree-sitter.wasm'));
|
|
101
|
-
} catch { return false; }
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** 当前资产里实际可用的语法名列表(按目录里存在的 wasm 推断)。 */
|
|
105
|
-
export function availableGrammars() {
|
|
106
|
-
try {
|
|
107
|
-
const { grammarsDir: gd } = resolveDirs();
|
|
108
|
-
if (!gd) return [];
|
|
109
|
-
return readdirSync(gd)
|
|
110
|
-
.map((f) => /^tree-sitter-(.+)\.wasm$/.exec(f))
|
|
111
|
-
.filter(Boolean)
|
|
112
|
-
.map((m) => m[1])
|
|
113
|
-
.sort();
|
|
114
|
-
} catch { return []; }
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** 由扩展名(可带点)取语法名;无映射返回 ''。 */
|
|
118
|
-
export function grammarForExt(ext = '') {
|
|
119
|
-
const e = String(ext).toLowerCase().replace(/^\./, '');
|
|
120
|
-
return EXT_TO_GRAMMAR[e] || '';
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** 懒加载 web-tree-sitter 运行时(ESM 具名导出:Parser / Language / Query)。
|
|
124
|
-
* 文件名用上游原名:0.25.10 是 `tree-sitter.js` / `tree-sitter.wasm`(0.27.x 才是 web-tree-sitter.* ✗ 且与
|
|
125
|
-
* tree-sitter-wasms@0.1.13 的语法不兼容 —— 实测 0.27.1 在 getDylinkMetadata 处报空消息错误 ✗)。 */
|
|
126
|
-
async function loadModule() {
|
|
127
|
-
if (!modPromise) {
|
|
128
|
-
// 两种布局:
|
|
129
|
-
// · npm 依赖 → 裸 specifier,让 ESM loader 按包的 exports 取 ESM 入口(0.25.10 → ./tree-sitter.js);
|
|
130
|
-
// · vendored / env 覆盖目录 → 目录里就有 tree-sitter.js,必须按文件路径加载,
|
|
131
|
-
// 否则在「只拷了插件目录、没装 dependencies」的部署端会 import 失败(实测过:语法读得到、runtime 拿不到)。
|
|
132
|
-
const { runtimeDir: rd } = resolveDirs();
|
|
133
|
-
const vendoredRuntime = rd ? join(rd, 'tree-sitter.js') : '';
|
|
134
|
-
modPromise = vendoredRuntime && existsSync(vendoredRuntime)
|
|
135
|
-
? import(pathToFileURL(vendoredRuntime).href)
|
|
136
|
-
: import('web-tree-sitter');
|
|
137
|
-
}
|
|
138
|
-
return modPromise;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/** 初始化一次(定位运行时 wasm)。失败返回 null(调用方回退)。 */
|
|
142
|
-
async function ensureInit() {
|
|
143
|
-
if (!initPromise) {
|
|
144
|
-
initPromise = (async () => {
|
|
145
|
-
const { Parser } = await loadModule();
|
|
146
|
-
// locateFile:告诉运行时去哪里取 web-tree-sitter.wasm(默认会按 URL 猜,容器里不可靠)。
|
|
147
|
-
// 目录来自 resolveDirs()(npm 包目录或 env 覆盖目录)——不能写死 ASSETS_DIR:
|
|
148
|
-
// 无 env 覆盖时它是空串,join('', f) 会退化成相对路径 ⇒ ENOENT(改这行时踩过)。
|
|
149
|
-
const { runtimeDir: rd } = resolveDirs();
|
|
150
|
-
await Parser.init({ locateFile: (f) => (rd ? join(rd, f) : f) });
|
|
151
|
-
return true;
|
|
152
|
-
})().catch(() => null);
|
|
153
|
-
}
|
|
154
|
-
return initPromise;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** 取(并缓存)某语言的 Parser;不可用返回 null。 */
|
|
158
|
-
async function getParser(grammar) {
|
|
159
|
-
const { grammarsDir: gd } = resolveDirs();
|
|
160
|
-
if (!grammar || !gd || !existsSync(join(gd, `tree-sitter-${grammar}.wasm`))) return null;
|
|
161
|
-
if (parserCache.has(grammar)) return parserCache.get(grammar);
|
|
162
|
-
try {
|
|
163
|
-
if (!(await ensureInit())) return null;
|
|
164
|
-
const { Parser, Language } = await loadModule();
|
|
165
|
-
let lang = langCache.get(grammar);
|
|
166
|
-
if (!lang) {
|
|
167
|
-
// 传**字节**而不是路径:0.27.x 的 load(路径) 会静默失败(Node 分支虽会 readFile,但 dylink 不兼容);
|
|
168
|
-
// 字节是唯一被实测验证可用的入口(0.25.10 ✓)
|
|
169
|
-
lang = await Language.load(readFileSync(join(gd, `tree-sitter-${grammar}.wasm`)));
|
|
170
|
-
langCache.set(grammar, lang);
|
|
171
|
-
}
|
|
172
|
-
const parser = new Parser();
|
|
173
|
-
parser.setLanguage(lang);
|
|
174
|
-
parserCache.set(grammar, parser);
|
|
175
|
-
return parser;
|
|
176
|
-
} catch {
|
|
177
|
-
return null; // 任何异常都退化为「不可用」⇒ 调用方回退 ✓
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/** 解析文本(按内容 hash 缓存语法树);失败返回 null。 */
|
|
182
|
-
export async function parseText(text, grammar) {
|
|
183
|
-
const src = String(text ?? '');
|
|
184
|
-
if (!grammar || src.length > MAX_PARSE_CHARS) return null;
|
|
185
|
-
const hash = `${grammar}:${createHash('sha1').update(src).digest('hex')}`;
|
|
186
|
-
if (treeCache.has(hash)) return treeCache.get(hash);
|
|
187
|
-
const parser = await getParser(grammar);
|
|
188
|
-
if (!parser) return null;
|
|
189
|
-
try {
|
|
190
|
-
const tree = parser.parse(src);
|
|
191
|
-
if (!tree || !tree.rootNode || tree.rootNode.hasError) return null; // 语法错误 ⇒ 不信任该树,回退 ✓
|
|
192
|
-
treeCache.set(hash, tree);
|
|
193
|
-
while (treeCache.size > TREE_CACHE_MAX) treeCache.delete(treeCache.keys().next().value);
|
|
194
|
-
return tree;
|
|
195
|
-
} catch {
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/** 节点或其祖先是否属于「不透明」构造(字符串/注释/模板/正则字面量)。 */
|
|
201
|
-
export function isOpaqueNode(node) {
|
|
202
|
-
for (let n = node; n; n = n.parent) {
|
|
203
|
-
const t = String(n.type || '');
|
|
204
|
-
if (/^(string|string_fragment|template_string|comment|line_comment|block_comment|regex|regex_pattern|interpreted_string_literal|raw_string_literal)$/.test(t)) return true;
|
|
205
|
-
if (/comment|string/.test(t)) return true; // 各语言命名差异的兜底
|
|
206
|
-
}
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* 用语法树确认一批命中是否为**真实代码**。
|
|
212
|
-
*
|
|
213
|
-
* @param {{text:string, ext?:string, grammar?:string, hits:Array<{line:number, col:number}>}} p
|
|
214
|
-
* @returns {Promise<{used:boolean, keep:boolean[], reason?:string}>}
|
|
215
|
-
* used=false ⇒ **调用方必须回退**到 token 级判定(keep 无意义);
|
|
216
|
-
* used=true ⇒ keep[i] 表示第 i 个命中是否为真代码(true=保留上报)。
|
|
217
|
-
*/
|
|
218
|
-
export async function confirmHits({ text, ext = '', grammar = '', hits = [] } = {}) {
|
|
219
|
-
const g = grammar || grammarForExt(ext);
|
|
220
|
-
if (!g || !hits.length) return { used: false, keep: [], reason: 'no-grammar-or-hits' };
|
|
221
|
-
const tree = await parseText(text, g);
|
|
222
|
-
if (!tree) return { used: false, keep: [], reason: 'parse-unavailable' };
|
|
223
|
-
try {
|
|
224
|
-
const keep = hits.map((h) => {
|
|
225
|
-
const line = Number(h?.line);
|
|
226
|
-
const col = Number(h?.col);
|
|
227
|
-
if (!Number.isFinite(line) || line < 1) return true; // 拿不到位置 ⇒ 不拦(宁可放行不误杀)
|
|
228
|
-
const column = Number.isFinite(col) && col > 0 ? col - 1 : 0;
|
|
229
|
-
const node = tree.rootNode.descendantForPosition({ row: line - 1, column });
|
|
230
|
-
if (!node) return true;
|
|
231
|
-
return !isOpaqueNode(node);
|
|
232
|
-
});
|
|
233
|
-
return { used: true, keep };
|
|
234
|
-
} catch {
|
|
235
|
-
return { used: false, keep: [], reason: 'confirm-failed' };
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* 把已解析的语法树包成**同步**确认函数(供同步的检查器 lib/checks/* 调用)。
|
|
241
|
-
*
|
|
242
|
-
* 为什么需要:检查器是同步的,而解析是异步的 —— 由编排层(async)**预解析**后,
|
|
243
|
-
* 把同步闭包传下去,避免把整条检查链改成 async ✗。
|
|
244
|
-
*
|
|
245
|
-
* @param {object|null} tree parseText 的返回值
|
|
246
|
-
* @returns {null|((line:number, col:number)=>boolean|null)} 返回 null 表示「无法判定」,
|
|
247
|
-
* 调用方应回退到 token 级判定(行级 + 列级)✓
|
|
248
|
-
*/
|
|
249
|
-
export function makeSyncConfirmer(tree) {
|
|
250
|
-
if (!tree || !tree.rootNode) return null;
|
|
251
|
-
const fn = (line, col) => {
|
|
252
|
-
try {
|
|
253
|
-
const l = Number(line);
|
|
254
|
-
if (!Number.isFinite(l) || l < 1) return null;
|
|
255
|
-
const c = Number(col);
|
|
256
|
-
const column = Number.isFinite(c) && c > 0 ? c - 1 : 0;
|
|
257
|
-
const node = tree.rootNode.descendantForPosition({ row: l - 1, column });
|
|
258
|
-
if (!node) return null;
|
|
259
|
-
return !isOpaqueNode(node);
|
|
260
|
-
} catch {
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
// 附带原始语法树:供「有树走树」的语义精筛(如凭据 credentialLinesFromTree)直接消费——
|
|
265
|
-
// 列级 opaque 确认与树级语义确认走同一棵预解析树,不重复解析(性能纪律)。
|
|
266
|
-
fn.tree = tree;
|
|
267
|
-
return fn;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* 用语法树提取「凭据标识符被直接赋字符串/字节字面量」的行(方向 E1「有树走树」)。
|
|
272
|
-
*
|
|
273
|
-
* 为什么用树而不是 token:token 级看不出「赋值」的语法结构——
|
|
274
|
-
* `def _icon(token="text.secondary")` 的参数默认值、`token="前缀:"+uuid` 的复合右值、
|
|
275
|
-
* `x="a" if c else "b"` 的三元分支,在 token 流里都是 `ident = str`,只能一律当硬编码
|
|
276
|
-
* (外部 Python 仓库实测:这一类全是误报)。语法树上它们分别是
|
|
277
|
-
* default_parameter / assignment_pattern(不是赋值语句)、binary_operator(右值非字面量)、
|
|
278
|
-
* conditional_expression(右值非字面量),一眼排除。
|
|
279
|
-
*
|
|
280
|
-
* 判定语汇(凭据名识别、值是否有意义)由调用方 credential.js 以谓词传入:
|
|
281
|
-
* 本模块不 import credential.js,避免反向依赖成环,也保证「什么算凭据」只有一份定义。
|
|
282
|
-
*
|
|
283
|
-
* @param {object} tree parseText 的返回值(无根节点/异常一律返回 null,调用方回退)
|
|
284
|
-
* @param {(name:string, raw:string)=>boolean} credHit 「名字+值」组合判据(credential.js
|
|
285
|
-
* 的 isHardcodedCredentialValue——强弱分级与值置信度只有一份定义)
|
|
286
|
-
* @returns {null|Set<number>} 命中行号集合;null = 树不可用,调用方必须回退 token 级
|
|
287
|
-
*/
|
|
288
|
-
export function credentialLinesFromTree(tree, credHit) {
|
|
289
|
-
if (!tree || !tree.rootNode || typeof credHit !== 'function') return null;
|
|
290
|
-
const out = new Set();
|
|
291
|
-
// 属性/成员访问左值(cfg.apikey、this.token、obj["secret"])在各语言的节点名。
|
|
292
|
-
const ATTRIBUTE_LHS = /^(attribute|member_expression|subscript|subscript_expression)$/;
|
|
293
|
-
// 字符串/字节字面量节点的类型名(各语言命名差异:string / string_literal /
|
|
294
|
-
// interpreted_string_literal(bytes/f-string) / raw_string_literal / character_literal)。
|
|
295
|
-
// 刻意不含 string_concat——`"a" + "b"` 的拼接值不是「直接字面量」,属复合右值。
|
|
296
|
-
const LIT = /^(string|string_literal|interpreted_string_literal|raw_string_literal|character_literal)$/;
|
|
297
|
-
// 字面量节点是否为「纯字面量」:f-string/插值串(children 含 interpolation /
|
|
298
|
-
// template_substitution / interpolation_expression)里值来自变量,不算硬编码内容。
|
|
299
|
-
const isPlainLiteral = (node) => {
|
|
300
|
-
if (!node || !LIT.test(node.type)) return false;
|
|
301
|
-
for (const c of node.children || []) {
|
|
302
|
-
if (/interpolation|substitution|expansion/i.test(String(c.type || ''))) return false;
|
|
303
|
-
}
|
|
304
|
-
return true;
|
|
305
|
-
};
|
|
306
|
-
// 遍历:收集「左值是凭据名、右值是单个字面量」的直接赋值行。
|
|
307
|
-
const walk = (node) => {
|
|
308
|
-
try {
|
|
309
|
-
// ① 真赋值语句(Python assignment / JS·TS assignment_expression):left=identifier,right=字面量
|
|
310
|
-
// 参数默认值(default_parameter/assignment_pattern)不在此类,天然排除。
|
|
311
|
-
if (node.type === 'assignment' || node.type === 'assignment_expression') {
|
|
312
|
-
const lhs = node.childForFieldName('left');
|
|
313
|
-
const rhs = node.childForFieldName('right');
|
|
314
|
-
// 左值名:裸标识符直接取;属性赋值(cfg.apikey = "…" / this.token = "…")取末段——
|
|
315
|
-
// 回退路径(token 级,`.` 允许跨越)对这类同样会报,树路径必须同等覆盖,否则改树反而漏报。
|
|
316
|
-
const name = lhs
|
|
317
|
-
? (lhs.type === 'identifier' || lhs.type === 'variable_declarator'
|
|
318
|
-
? String(lhs.text)
|
|
319
|
-
: String(lhs.text).split(/[.\[\]]/).pop().replace(/^['"]|['"]$/g, ''))
|
|
320
|
-
: '';
|
|
321
|
-
const lhsOk = lhs && (lhs.type === 'identifier' || ATTRIBUTE_LHS.test(lhs.type));
|
|
322
|
-
if (lhsOk && isPlainLiteral(rhs) && credHit(name, rhs.text)) {
|
|
323
|
-
out.add(node.startPosition.row + 1);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
// ② 变量声明初始化(const token = "…"):variable_declarator name=identifier value=字面量
|
|
327
|
-
else if (node.type === 'variable_declarator' || node.type === 'init_declarator') {
|
|
328
|
-
const nm = node.childForFieldName('name');
|
|
329
|
-
const val = node.childForFieldName('value');
|
|
330
|
-
if (nm && nm.type === 'identifier' && isPlainLiteral(val) && credHit(String(nm.text), val.text)) {
|
|
331
|
-
out.add(node.startPosition.row + 1);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
// ③ 对象字段({ token: "…" } / { apiKey: "…" }):pair,键名命中凭据词 + 值是字面量。
|
|
335
|
-
// f-string/插值字符串的值节点是 string 类型但含 interpolation 子节点——见 ③ 下的插值判定。
|
|
336
|
-
else if (node.type === 'pair' || node.type === 'property_assignment' || node.type === 'object_element') {
|
|
337
|
-
const keyNode = node.childForFieldName('key') || node.namedChildren[0];
|
|
338
|
-
const valNode = node.childForFieldName('value') || node.namedChildren[1];
|
|
339
|
-
const keyText = keyNode ? String(keyNode.text).replace(/^['"]|['"]$/g, '') : '';
|
|
340
|
-
if (keyNode && isPlainLiteral(valNode) && credHit(keyText, valNode.text)) {
|
|
341
|
-
out.add(node.startPosition.row + 1);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
for (const child of node.namedChildren) walk(child);
|
|
345
|
-
} catch {
|
|
346
|
-
// 单节点异常不打断整树:已收集的命中照常返回(部分成功优于全失败)。
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
try {
|
|
350
|
-
walk(tree.rootNode);
|
|
351
|
-
return out;
|
|
352
|
-
} catch {
|
|
353
|
-
return null;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* 用语法树收集「函数/方法定义名过短」的命中(方向 E 迁移第二条,short-func-name 树化)。
|
|
359
|
-
*
|
|
360
|
-
* 为什么必须用树(实测漏报):token 级只认「function 关键字后的 ident」,
|
|
361
|
-
* 于是 `class A { gh() {} }`、`const o = { ef() {} }` 这类**方法定义**完全查不到——
|
|
362
|
-
* 它们同样是「名字猜不出含义」的缺陷,却静默放行。
|
|
363
|
-
* 想在 token 级补齐只能靠「标识符 + ( 」近似,那会把 `ab(1)` 调用、`{ ef: ... }` 属性
|
|
364
|
-
* 全卷进来(误报换漏报,不划算)。语法树上它们是独立节点:
|
|
365
|
-
* function_declaration / generator_function_declaration / function_expression /
|
|
366
|
-
* method_definition / method_signature,且都带 name 字段;
|
|
367
|
-
* arrow_function、if_statement 无 name 字段 ⇒ 天然不误伤。
|
|
368
|
-
*
|
|
369
|
-
* @param {object} tree parseText 返回值
|
|
370
|
-
* @param {(name:string)=>boolean} isShort 名字判定(长度阈值 + 公认缩写白名单,由 naming.js 传入——判据只有一份)
|
|
371
|
-
* @returns {null|Array<{line:number, name:string}>} null = 树不可用,调用方回退 token 级
|
|
372
|
-
*/
|
|
373
|
-
export function shortFunctionNamesFromTree(tree, isShort) {
|
|
374
|
-
if (!tree || !tree.rootNode || typeof isShort !== 'function') return null;
|
|
375
|
-
const DECL = new Set([
|
|
376
|
-
'function_declaration', 'generator_function_declaration', 'function_expression',
|
|
377
|
-
'method_definition', 'method_signature',
|
|
378
|
-
]);
|
|
379
|
-
const out = [];
|
|
380
|
-
const walk = (node) => {
|
|
381
|
-
try {
|
|
382
|
-
if (DECL.has(node.type)) {
|
|
383
|
-
// 访问器(get ab() / set cd(v))跳过:它的 name 是**属性名**而非「做某事的函数名」,
|
|
384
|
-
// 且 get x / set x 配对是极常见惯例(框架存取器、计算属性)——按「函数名过短」报属语义错位。
|
|
385
|
-
// 刻意显式排除而非依赖初筛侥幸挡住:初筛放宽后这里不能变成误报源。
|
|
386
|
-
// 实测节点形态:method_definition 的 children[0].type 为 get/set(普通方法是 property_identifier)。
|
|
387
|
-
const lead = node.children && node.children[0];
|
|
388
|
-
const isAccessor = lead && /^(get|set)$/.test(String(lead.type));
|
|
389
|
-
const nm = node.childForFieldName('name');
|
|
390
|
-
// 仅裸标识符/属性名才算「定义名」;computed([x](){})等形态跳过,避免取到表达式文本
|
|
391
|
-
if (!isAccessor && nm && /^(identifier|property_identifier|private_property_identifier)$/.test(String(nm.type))) {
|
|
392
|
-
const name = String(nm.text);
|
|
393
|
-
if (isShort(name)) out.push({ line: nm.startPosition.row + 1, name });
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
for (const c of node.namedChildren) walk(c);
|
|
397
|
-
} catch { /* 单节点异常不打断整树 */ }
|
|
398
|
-
};
|
|
399
|
-
try {
|
|
400
|
-
walk(tree.rootNode);
|
|
401
|
-
return out;
|
|
402
|
-
} catch {
|
|
403
|
-
return null;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/** 清空全部缓存(测试与长驻进程内存回收用)。 */
|
|
408
|
-
export function resetTreeSitterCache() { modPromise = null;
|
|
409
|
-
initPromise = null;
|
|
410
|
-
langCache.clear();
|
|
411
|
-
parserCache.clear();
|
|
412
|
-
treeCache.clear();
|
|
413
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 分析覆盖率(**信息项,不参与评分**)
|
|
3
|
-
*
|
|
4
|
-
* 【为什么需要】审计可能「规则全过」但其实根本没解析到代码(比如解析器看不懂某种语法、
|
|
5
|
-
* 导入解析不到目标文件)——只看命中数与分数会被这种假绿误导。这里用符号索引给出三个数:
|
|
6
|
-
* ① 覆盖率 = 连边数 / 可解析调用数(成员调用 `x.y()` 不计入,它们本就不经符号索引解析)
|
|
7
|
-
* ② 未解析构成(unknown / ambiguous)与按文件的未解析 top
|
|
8
|
-
* ③ 被排除的成员调用量(说明分母口径,避免"看起来漏了很多"的误解)
|
|
9
|
-
*
|
|
10
|
-
* 【为什么不进评分】覆盖率高低受语言与工程风格影响很大(纯函数库天然高、框架代码天然低),
|
|
11
|
-
* 直接计分会把「语言差异」算成「代码质量问题」。先作为可见性指标输出,口径稳定后再议是否计分。
|
|
12
|
-
*
|
|
13
|
-
* 【口径限制】需要**完整文件集**才能解析跨文件导入;diff 范围只含变动文件时无法给出可信覆盖率,
|
|
14
|
-
* 此时返回 `{ skipped: 原因 }` 而不是给一个失真的数字。
|
|
15
|
-
*/
|
|
16
|
-
import { buildSymbolIndex } from '../ast/symbol-index.js';
|
|
17
|
-
import { collectTextFiles, readText } from './collector.js';
|
|
18
|
-
import { relative } from 'node:path';
|
|
19
|
-
|
|
20
|
-
/** 未解析 top 文件默认取前几个。 */
|
|
21
|
-
const DEFAULT_TOP_N = 5;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 取「相对路径 → 文件内容」的条目集。
|
|
25
|
-
* - 调用方直接给 `files: [{path, full}]`(含内容)时用它(单测/已读入场景,不再碰磁盘);
|
|
26
|
-
* - 否则按**审计同一套采集器**(collectTextFiles:gitignore/.auditignore 感知)从 repoPath 收集并读取,
|
|
27
|
-
* 保证覆盖率与审计看到的是同一批文件。
|
|
28
|
-
* @returns {Promise<Array<{path:string, full:string}>>}
|
|
29
|
-
*/
|
|
30
|
-
async function resolveEntries({ repoPath, files }) {
|
|
31
|
-
if (Array.isArray(files) && files.length) {
|
|
32
|
-
return files.map((f) => ({ path: String(f.path || f.rel || ''), full: String(f.full ?? '') })).filter((f) => f.path);
|
|
33
|
-
}
|
|
34
|
-
if (!repoPath) return [];
|
|
35
|
-
const collected = await collectTextFiles(repoPath, { gitIgnoreRoot: repoPath, includeIgnored: false });
|
|
36
|
-
const list = Array.isArray(collected) ? collected : (collected && collected.files) || [];
|
|
37
|
-
return list
|
|
38
|
-
.map((f) => ({ path: relative(repoPath, String(f.full || f.path || '')).replace(/\\/g, '/'), full: readText(String(f.full || '')) || '' }))
|
|
39
|
-
.filter((f) => f.path && f.full);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 计算分析覆盖率(信息项)。
|
|
44
|
-
* @param {{repoPath?:string, files?:Array<{path?:string, rel?:string, full?:string}>, topN?:number}} [opts]
|
|
45
|
-
* files:已读入的文件(含内容);未给则用 repoPath 按审计采集器现收现读
|
|
46
|
-
* @returns {Promise<object>} 覆盖率信息对象(不参与评分)
|
|
47
|
-
*/
|
|
48
|
-
export async function computeAnalysisCoverage({ repoPath = '', files = null, topN = DEFAULT_TOP_N } = {}) {
|
|
49
|
-
const entries = await resolveEntries({ repoPath, files });
|
|
50
|
-
if (!entries.length) return { files: 0, note: '无文件可分析' };
|
|
51
|
-
const byPath = new Map(entries.map((e) => [e.path, e.full]));
|
|
52
|
-
const index = buildSymbolIndex([...byPath.keys()], { readFile: (rel) => byPath.get(rel) || '' });
|
|
53
|
-
const s = index.stats;
|
|
54
|
-
return {
|
|
55
|
-
files: s.files,
|
|
56
|
-
declarations: s.declarations,
|
|
57
|
-
exports: s.exports,
|
|
58
|
-
calls: s.calls,
|
|
59
|
-
edges: s.edges,
|
|
60
|
-
edgesByVia: s.edgesByVia,
|
|
61
|
-
unresolved: s.unresolved,
|
|
62
|
-
unresolvedByReason: countByReason(index.unresolved),
|
|
63
|
-
memberCallsExcluded: s.skippedMemberCalls,
|
|
64
|
-
coverage: s.coverage,
|
|
65
|
-
topUnresolvedFiles: topUnresolvedFiles(index.unresolved, topN),
|
|
66
|
-
note: '信息项,不参与评分;覆盖率 = 连边 / 可解析调用(成员调用 x.y() 已排除并单独计数)',
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** 未解析原因计数。 */
|
|
71
|
-
function countByReason(unresolved) {
|
|
72
|
-
const out = {};
|
|
73
|
-
for (const u of unresolved) out[u.reason] = (out[u.reason] || 0) + 1;
|
|
74
|
-
return out;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** 按文件统计未解析调用数,取前 N(降序)。 */
|
|
78
|
-
function topUnresolvedFiles(unresolved, topN) {
|
|
79
|
-
const counts = new Map();
|
|
80
|
-
for (const u of unresolved) counts.set(u.file, (counts.get(u.file) || 0) + 1);
|
|
81
|
-
return [...counts.entries()]
|
|
82
|
-
.map(([file, count]) => ({ file, count }))
|
|
83
|
-
.sort((a, b) => b.count - a.count)
|
|
84
|
-
.slice(0, Math.max(0, topN));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* 覆盖率一行文本(审计输出里附在 apiGuide 后面)。
|
|
89
|
-
* @param {object} cov computeAnalysisCoverage 的结果(或 `{skipped}`)
|
|
90
|
-
* @returns {string}
|
|
91
|
-
*/
|
|
92
|
-
export function formatAnalysisCoverageLine(cov = {}) {
|
|
93
|
-
if (!cov || cov.skipped) return `分析覆盖率:跳过(${(cov && cov.skipped) || '未计算'})`;
|
|
94
|
-
if (!cov.files) return `分析覆盖率:${cov.note || '无文件'}`;
|
|
95
|
-
const reasons = Object.entries(cov.unresolvedByReason || {}).map(([k, v]) => `${k} ${v}`).join(' / ');
|
|
96
|
-
return `分析覆盖率 ${cov.coverage}%(连边 ${cov.edges} / 可解析调用 ${cov.calls};未解析 ${cov.unresolved}${reasons ? `:${reasons}` : ''};`
|
|
97
|
-
+ `已排除成员调用 ${cov.memberCallsExcluded})——信息项,不参与评分`;
|
|
98
|
-
}
|