dsh-git-push 2.9.3 → 2.9.4
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 +1 -0
- package/lib/audit/finding.js +29 -0
- package/lib/audit/index.js +1 -1
- package/lib/audit/orchestrate.js +6 -1
- package/lib/checks/regex.js +7 -3
- package/lib/exempt/index.js +72 -26
- package/lib/self/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -577,6 +577,7 @@ dsh-git-push/
|
|
|
577
577
|
│ ├── test-empty-catch-promise.mjs — (待注释)
|
|
578
578
|
│ ├── test-empty-catch-single-source.mjs — (待注释)
|
|
579
579
|
│ ├── test-exempt-hint-classify.mjs — (待注释)
|
|
580
|
+
│ ├── test-exempt-hint-effective.mjs — (待注释)
|
|
580
581
|
│ ├── test-exempt.mjs — 豁免总入口测试(7 标记 + 位置语义)
|
|
581
582
|
│ ├── test-ext-variable-min-length.mjs — (待注释)
|
|
582
583
|
│ ├── test-false-positive-fixes.mjs — 误报修复回归测试
|
package/lib/audit/finding.js
CHANGED
|
@@ -1,8 +1,37 @@
|
|
|
1
|
+
import { exemptHintForFinding, exemptMarkerCovers } from '../exempt/index.js';
|
|
2
|
+
|
|
1
3
|
/** 统一问题对象构造器(所有审计检查的出口)。 */
|
|
2
4
|
export function makeFinding({ file, line, rule, kind, severity = 'warning', message, dimensions = [], exemptHint = '', scoreImpact = 0 }) {
|
|
3
5
|
return { file, line, rule, kind, severity, message, dimensions, exemptHint, scoreImpact };
|
|
4
6
|
}
|
|
5
7
|
|
|
8
|
+
/**
|
|
9
|
+
* 豁免提示「可信化」:把每个 finding 的 exemptHint 校正为**真能豁免它**的标记。
|
|
10
|
+
*
|
|
11
|
+
* 背景(2026-10-17 由「有人反应文件头豁免措辞无效」触发):exemptHint 是各检查器里**写死**的
|
|
12
|
+
* 字符串,而能否生效取决于 lib/exempt/index.js 的 blocked/细分清单。两者不一致时,用户照
|
|
13
|
+
* 提示写了文件头标记**仍然照报**(全量自证实测 24 种组合,如 readability/vague-function-name
|
|
14
|
+
* 提示 dsh-skip-residue、maintainability/max-cyclomatic-complexity 提示 dsh-skip-quality)。
|
|
15
|
+
* 做法:统一在这一处(所有 finding 的汇集点)用注册表反查校正——
|
|
16
|
+
* · 原提示的标记确实覆盖 ⇒ **保留**(不打扰已熟悉的措辞与既有豁免统计)
|
|
17
|
+
* · 不覆盖 ⇒ 换成真能豁免的标记 + 该标记的官方 hint
|
|
18
|
+
* · 一个都没有 ⇒ 如实说明「当前无可用标记」(不再给一个写了不生效的 ✗)
|
|
19
|
+
* 幂等:同一 finding 反复校正结果不变;对新规则同样生效(无需逐个检查器去改提示)。
|
|
20
|
+
* @param {Array} findings 统一问题对象数组(原地修正 exemptHint)
|
|
21
|
+
*/
|
|
22
|
+
export function normalizeExemptHints(findings = []) {
|
|
23
|
+
const MARKER_RE = /dsh-skip-[a-z-]+/;
|
|
24
|
+
for (const f of findings) {
|
|
25
|
+
if (!f) continue;
|
|
26
|
+
const hit = String(f.exemptHint || '').match(MARKER_RE);
|
|
27
|
+
if (hit && exemptMarkerCovers(hit[0], f)) continue; // 原提示有效 ⇒ 保留
|
|
28
|
+
const truth = exemptHintForFinding(f);
|
|
29
|
+
if (truth) f.exemptHint = `${truth.marker}(${truth.hint})`;
|
|
30
|
+
else if (hit) f.exemptHint = '(当前无可用豁免标记:该 kind 不在任何 dsh-skip-* 的 blocked 清单里)';
|
|
31
|
+
}
|
|
32
|
+
return findings;
|
|
33
|
+
}
|
|
34
|
+
|
|
6
35
|
/**
|
|
7
36
|
* 扫描智能提示(1.0.8):对 warning/blocker 且文件路径或文件名带 test 特征的 finding,
|
|
8
37
|
* 在 message 末尾附加「测试文件夹可用 .test 空文件豁免」提示(告知而非自动豁免——
|
package/lib/audit/index.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
import '../rule/compilers.js'; // 副作用:注册 13 种编译函数
|
|
26
26
|
|
|
27
|
-
export { makeFinding, decorateTestExemptHint, summarize, CODE_EXTS } from './finding.js';
|
|
27
|
+
export { makeFinding, decorateTestExemptHint, normalizeExemptHints, summarize, CODE_EXTS } from './finding.js';
|
|
28
28
|
export { slotStatsFromFindings, buildRuleSlotMap, countRulesBySlot } from './slot.js';
|
|
29
29
|
export { repoLevelSemanticRuleIds, pickRepoLevelAnchorFile } from './repo-level.js';
|
|
30
30
|
export { hasMkdirInSameFunction, hasExternalCallTimeout, detectRepoJsYamlImport, isVersionInPathContext } from './file-context.js';
|
package/lib/audit/orchestrate.js
CHANGED
|
@@ -9,7 +9,7 @@ import { compileAllRules } from '../rule/registry.js';
|
|
|
9
9
|
import { auditFile } from './audit-file.js';
|
|
10
10
|
import { grammarForExt, parseText, makeSyncConfirmer } from '../ast/treesitter.js';
|
|
11
11
|
import { detectRepoJsYamlImport } from './file-context.js';
|
|
12
|
-
import { decorateTestExemptHint, makeFinding, summarize } from './finding.js';
|
|
12
|
+
import { decorateTestExemptHint, makeFinding, summarize, normalizeExemptHints } from './finding.js';
|
|
13
13
|
import { pickRepoLevelAnchorFile, repoLevelSemanticRuleIds } from './repo-level.js';
|
|
14
14
|
import { checkDocsScore } from '../score/docs-score.js';
|
|
15
15
|
import { runAuditExt } from './ext-runner.js';
|
|
@@ -285,6 +285,11 @@ async function auditFiles(repoPath, files, opts = {}) {
|
|
|
285
285
|
try {
|
|
286
286
|
findings.push(...(await runAuditExt(repoPath, { dir: opts.auditExtDir, log: opts.log })));
|
|
287
287
|
} catch (e) { log?.warn?.(`审计扩展执行失败:${e?.message || e}`); }
|
|
288
|
+
// 豁免提示可信化(2026-10-17)—— **必须放在所有 finding 追加完之后**:
|
|
289
|
+
// 此前放在文件循环附近,后面还有 tree-doc/func-doc/split-docs/ignore/ext 五处追加 ⇒
|
|
290
|
+
// 那些 finding 绕过校正,自证里仍能看到「提示 dsh-skip-quality 却没有标记能豁免」✗。
|
|
291
|
+
// 统一校正为「真能豁免该 finding」的标记(提示与判定口径分离曾致 24 种组合写了不生效)。
|
|
292
|
+
normalizeExemptHints(findings);
|
|
288
293
|
// 按规则包聚合命中数(侧边栏规则包列表的「拦截/警告/通过」= 实际命中数)
|
|
289
294
|
const slotStats = slotStatsFromFindings(findings, buildRuleSlotMap(compiled), countRulesBySlot(compiled));
|
|
290
295
|
// 文档加分制(0 分起、上限 10)——结构信号 + 交叉验证,**不进 findings**
|
package/lib/checks/regex.js
CHANGED
|
@@ -38,15 +38,19 @@ export function pickExemptHint(rule) {
|
|
|
38
38
|
}
|
|
39
39
|
if (hit(residue.residueRules)) return 'dsh-skip-residue(行尾=本行)';
|
|
40
40
|
if (hit(style.styleRules)) return 'dsh-skip-style(文件头=整文件)';
|
|
41
|
-
//
|
|
42
|
-
|
|
41
|
+
// 三套清单都没命中:**不能**再沿用一个写了不生效的标记 ✗(2026-10-17「措辞无效」的根因之一:
|
|
42
|
+
// 这里原样返回 dsh-skip-residue,而 residue 只管 debugger/todo/console/io-risk 等窄集合,
|
|
43
|
+
// 其余 regex 规则(vague-function-name / timeout-on-external-api …)写了完全不生效)。
|
|
44
|
+
// 改为按注册表反查:真能豁免给出真标记,否则如实留空(由 finding 出口统一校正兜底)。
|
|
45
|
+
const truth = exemptHintForFinding({ kind: kind || 'regex', rule: id });
|
|
46
|
+
return truth ? `${truth.marker}(${truth.hint})` : '';
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
import { makeFinding } from '../audit/index.js';
|
|
46
50
|
import { safeRe } from '../rule/compilers.js';
|
|
47
51
|
import { capSeverity } from './common.js';
|
|
48
52
|
// 豁免提示按规则名前缀选关键词——分类清单复用豁免注册表(单一来源,避免两处各写一份清单)
|
|
49
|
-
import { EXEMPT_MARKERS } from '../exempt/index.js';
|
|
53
|
+
import { EXEMPT_MARKERS, exemptHintForFinding } from '../exempt/index.js';
|
|
50
54
|
import { credentialValueLines, placeholderCredentialLines, shortFuncNameLines, smallFileReadLines, consoleLogJsonLines, loopFullCollectionLines, repeatIdenticalCallLines, loopNoFallbackReturnLines, loopFullRewriteCallLines, nestedLinearScanLines, longSyncLoopLines, smartHitLines, shellCdDynamicLines, writeIntoGitignoredLines, ioRiskLines, ioRiskDetail } from './common.js';
|
|
51
55
|
|
|
52
56
|
/** 检查文本是否符合 regex 型规则(regex / secret / credential-ref)。
|
package/lib/exempt/index.js
CHANGED
|
@@ -14,7 +14,10 @@ import { statSync } from 'node:fs';
|
|
|
14
14
|
export const EXEMPT_MARKERS = {
|
|
15
15
|
'dsh-skip-sensitive': {
|
|
16
16
|
dimensions: ['安全性'],
|
|
17
|
-
|
|
17
|
+
// 2026-10-17 补 'semantic':security/* 的语义类 finding(如 security/no-path-traversal)
|
|
18
|
+
// 此前既不在 sensitive.blocked、又被 quality 的安全排除挡掉 ⇒ 任何标记都豁免不了 ✗
|
|
19
|
+
// (自证第 24 种)。细分词表同时作用于 semantic(见 markerCovers)。
|
|
20
|
+
blocked: ['[FUNC]', 'credential-file', 'credential-ref', 'path-regex', 'regex', 'semantic'], // path-regex 含私钥路径类;regex 是宽声明(安全类按 rule 名细分)
|
|
18
21
|
// regex 宽声明:security/* 规则带 pattern 字段编译成 regex kind,
|
|
19
22
|
// 需按 rule 名细分(含 security/credential/secret/password/hardcoded 等安全词才算敏感类)
|
|
20
23
|
sensitiveRules: ['security', 'credential', 'credref', 'credfile', 'secret', 'password', 'hardcoded'],
|
|
@@ -66,8 +69,17 @@ export const EXEMPT_MARKERS = {
|
|
|
66
69
|
// comment-density / file-health:这两类 finding 一直提示 dsh-skip-quality,
|
|
67
70
|
// 但它们的 kind 也不在任何标记的 blocked 里(同 blacklist/magic-number-smart 一类 bug:
|
|
68
71
|
// 提示写了不生效)⇒ 一并补进本条(注释密度与文件健康度都属「质量评分」语义)。
|
|
72
|
+
// 2026-10-17 补齐(起因:「有人反应文件头豁免措辞无效」⇒ 全量自证查出 24 种组合
|
|
73
|
+
// **按 finding 提示写了文件头标记仍照报** ✗)。两类缺口:
|
|
74
|
+
// ① semantic / dataflow / duplicate-const / repeated-string —— 此前**没有任何标记**
|
|
75
|
+
// 能豁免这些 kind,而规则自身却提示用 dsh-skip-quality ⇒ 写了不生效;
|
|
76
|
+
// ② regex —— 兜底覆盖**非安全类**的 regex finding(安全类由 excludeRules 排除,
|
|
77
|
+
// 仍必须写 dsh-skip-sensitive,避免用质量标记顺手静默掉安全问题 ✗)。
|
|
69
78
|
blocked: ['func-lines', 'empty-catch', 'sync-fs', 'magic-number-smart', 'blacklist',
|
|
70
|
-
'comment-density', 'file-health'
|
|
79
|
+
'comment-density', 'file-health',
|
|
80
|
+
'semantic', 'dataflow', 'duplicate-const', 'repeated-string', 'regex'],
|
|
81
|
+
// regex 兜底时**排除**安全类规则名(这些必须走 dsh-skip-sensitive,不能靠质量标记吞掉)
|
|
82
|
+
excludeRules: ['security', 'credential', 'credref', 'credfile', 'secret', 'password', 'hardcoded'],
|
|
71
83
|
lineLevel: false,
|
|
72
84
|
hint: '文件头=整文件免质量评分(func-lines/empty-catch/sync-fs/magic-number-smart/blacklist 措辞/comment-density/file-health)',
|
|
73
85
|
},
|
|
@@ -84,7 +96,11 @@ export const EXEMPT_MARKERS = {
|
|
|
84
96
|
},
|
|
85
97
|
'dsh-skip-style': {
|
|
86
98
|
dimensions: ['可读性'],
|
|
87
|
-
|
|
99
|
+
// 需按 rule 前缀细分(style-* 数值风格规则);min-occurrences 是 lib/audit/orchestrate.js 分体文档提示用的非 regex kind。
|
|
100
|
+
// 2026-10-17 补 min-length / max-lines / max-complexity / max-depth / repeated-string 这些**直接 kind**:
|
|
101
|
+
// styleRules 里本来就列了它们(文档表也写「style-* 数值风格(min-length/max-lines/max-complexity/max-depth)→ 只能文件头」),
|
|
102
|
+
// 但 blocked 只列了 'min-occurrences' ⇒ kind=min-length 等 finding 提示 dsh-skip-quality 时**无任何标记可豁免** ✗(自证抓到)。
|
|
103
|
+
blocked: ['regex', 'min-occurrences', 'min-length', 'max-lines', 'max-complexity', 'max-depth', 'repeated-string'],
|
|
88
104
|
styleRules: ['min-length', 'max-lines', 'max-complexity', 'max-depth', 'min-occurrences', 'repeated-string'],
|
|
89
105
|
lineLevel: false,
|
|
90
106
|
hint: '文件头=整文件免全部 styleRules',
|
|
@@ -136,11 +152,62 @@ export function isCategoryExempt(finding = {}) {
|
|
|
136
152
|
return false;
|
|
137
153
|
}
|
|
138
154
|
|
|
155
|
+
/**
|
|
156
|
+
* 单个标记是否覆盖该 kind/rule —— **唯一判定口径**(exemptForFinding 与反查提示共用)。
|
|
157
|
+
*
|
|
158
|
+
* 为什么抽出来:此前「判定是否豁免」与「生成 exemptHint」两处各写一套口径 ⇒
|
|
159
|
+
* 提示的标记与实际能否豁免会不一致(2026-10-17 全量自证实测 24 种组合:
|
|
160
|
+
* 用户按 finding 提示写了文件头标记仍然照报,即「措辞无效」✗)。
|
|
161
|
+
*/
|
|
162
|
+
function markerCovers(meta, kind, rule) {
|
|
163
|
+
if (!meta || !Array.isArray(meta.blocked) || !meta.blocked.includes(kind)) return false;
|
|
164
|
+
const r = String(rule || '').toLowerCase();
|
|
165
|
+
const has = (a) => Array.isArray(a) && a.length > 0;
|
|
166
|
+
// 残留/风格/国际化:只对 regex 宽声明做「规则名细分」
|
|
167
|
+
if (kind === 'regex') {
|
|
168
|
+
if (has(meta.residueRules)) return meta.residueRules.some((w) => r.includes(w));
|
|
169
|
+
if (has(meta.styleRules)) return meta.styleRules.some((w) => r.includes(w));
|
|
170
|
+
if (has(meta.i18nRules)) return meta.i18nRules.some((w) => r.includes(w));
|
|
171
|
+
}
|
|
172
|
+
// 安全类细分:regex 与 semantic 两类**宽 kind** 都要按词表判;
|
|
173
|
+
// ⚠️ 不可推广到 path-regex / [FUNC] / credential-* —— 那些是**直接 kind 命中**,
|
|
174
|
+
// 不受规则名词表约束(原语义;扩展 semantic 时曾误伤 path-private-key-location ⇒ 回归)。
|
|
175
|
+
if ((kind === 'regex' || kind === 'semantic') && has(meta.sensitiveRules)) {
|
|
176
|
+
return meta.sensitiveRules.some((w) => r.includes(w));
|
|
177
|
+
}
|
|
178
|
+
// 质量兜底对 regex 的覆盖:排除安全类(安全 finding 不许被质量标记吞掉 ✗)
|
|
179
|
+
if (kind === 'regex' && has(meta.excludeRules)) return !meta.excludeRules.some((w) => r.includes(w));
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** 指定标记是否覆盖该 finding(供提示校正判断「原提示是否仍然有效」)。 */
|
|
184
|
+
export function exemptMarkerCovers(marker, finding = {}) {
|
|
185
|
+
return markerCovers(EXEMPT_MARKERS[marker], finding.kind || '', finding.rule || '');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 反查「真能豁免该 finding 的标记」——按与 exemptForFinding **同一口径**判定。
|
|
190
|
+
* 优先级:先非 dsh-skip-quality(专用标记更贴切),最后才是质量类兜底。
|
|
191
|
+
* @param {object} finding 需含 kind/rule
|
|
192
|
+
* @returns {{marker:string, hint:string}|null} 无可豁免标记时返回 null(调用方应如实提示)
|
|
193
|
+
*/
|
|
194
|
+
export function exemptHintForFinding(finding = {}) {
|
|
195
|
+
const kind = finding.kind || '';
|
|
196
|
+
const rule = finding.rule || '';
|
|
197
|
+
const pinned = ['dsh-skip-quality'];
|
|
198
|
+
const order = [...Object.keys(EXEMPT_MARKERS).filter((m) => !pinned.includes(m)), ...pinned];
|
|
199
|
+
for (const marker of order) {
|
|
200
|
+
const meta = EXEMPT_MARKERS[marker];
|
|
201
|
+
if (markerCovers(meta, kind, rule)) return { marker, hint: meta.hint };
|
|
202
|
+
}
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
|
|
139
206
|
/**
|
|
140
207
|
* 判定单个 finding 是否被豁免。
|
|
141
208
|
* 整文件豁免(文件头前 3 行含标记)→ 该 finding 的 kind 命中 blocked 即豁免;
|
|
142
209
|
* 行级豁免(finding.line 所在行含标记,且标记支持 lineLevel)→ 豁免。
|
|
143
|
-
* residue/style 走 rule
|
|
210
|
+
* residue/style/i18n/sensitive 走 rule 前缀细分(口径统一在 markerCovers)。
|
|
144
211
|
* @param {object} finding 统一问题对象
|
|
145
212
|
* @param {string} text 文件全文(用于取文件头与行)
|
|
146
213
|
* @returns {boolean} true=豁免(应丢弃该 finding)
|
|
@@ -152,28 +219,7 @@ export function exemptForFinding(finding, text = '') { // dsh-skip-complexity:
|
|
|
152
219
|
const kind = finding.kind || '';
|
|
153
220
|
const rule = finding.rule || '';
|
|
154
221
|
for (const [marker, meta] of Object.entries(EXEMPT_MARKERS)) {
|
|
155
|
-
|
|
156
|
-
// residue/style:blocked 里的 'regex' 是**宽声明**,需按 rule 前缀细分;
|
|
157
|
-
// 但细分支必须只在 kind === 'regex' 时生效——否则 blocked 里直接列的非 regex kind
|
|
158
|
-
// (如 style 的 'min-occurrences',orchestrate.js 的分体文档提示用它做 kind)
|
|
159
|
-
// 会被 rule 名细分误杀:规则名不含 styleRules 词 ⇒ 写了标记也不豁免(实测复现)。
|
|
160
|
-
// sensitive/i18n 两个分支本就带 kind === 'regex' 前置,这里补齐一致。
|
|
161
|
-
let kindHit = blockedHit;
|
|
162
|
-
if (kind === 'regex' && blockedHit && meta.residueRules && meta.residueRules.length) {
|
|
163
|
-
kindHit = meta.residueRules.some((r) => rule.toLowerCase().includes(r));
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (kind === 'regex' && blockedHit && meta.styleRules && meta.styleRules.length) {
|
|
167
|
-
kindHit = meta.styleRules.some((r) => rule.toLowerCase().includes(r));
|
|
168
|
-
}
|
|
169
|
-
if (kind === 'regex' && meta.i18nRules && meta.i18nRules.length) {
|
|
170
|
-
kindHit = meta.i18nRules.some((r) => rule.toLowerCase().includes(r));
|
|
171
|
-
}
|
|
172
|
-
// sensitive 细分只在 regex 宽声明时生效(直接 kind 命中如 [FUNC]/credential-*/path-regex 不受 rule 名约束)
|
|
173
|
-
if (kind === 'regex' && meta.sensitiveRules && meta.sensitiveRules.length) {
|
|
174
|
-
kindHit = meta.sensitiveRules.some((r) => rule.toLowerCase().includes(r));
|
|
175
|
-
}
|
|
176
|
-
if (!kindHit) continue;
|
|
222
|
+
if (!markerCovers(meta, kind, rule)) continue;
|
|
177
223
|
// 整文件豁免(文件头前 3 行)
|
|
178
224
|
if (hasHeaderExempt(lines.slice(0, 3).join('\n'), marker)) return true;
|
|
179
225
|
// 行级豁免(支持 lineLevel 且本行含标记)
|
package/lib/self/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
export const VERSION = '2.9.
|
|
12
|
+
export const VERSION = '2.9.4'; // 2.9.4:修「文件头豁免提示的标记写了不生效」——判定口径抽成唯一函数(exemptForFinding 与反查提示共用)+ 补齐注册表缺口(quality 增加 semantic/dataflow/duplicate-const/repeated-string 与非安全类 regex 兜底、style 补 min-length/max-lines/max-complexity/max-depth、sensitive 补 semantic)+ 所有 finding 产出后统一校正提示为「真能豁免的标记」;自证:写了不生效的组合 24 → 0。历史:2.9.3:FS 热点扫描并入审计(判据②扩到函数体 + 仓库级 multi-file-scanners + 独立 CLI)。
|
|
13
13
|
// 实测后果:该目录有 package.json ⇒ npm 去打包整棵 DSH 树、输出 2.1MB > spawnSync 默认 maxBuffer 1MB ⇒ ENOBUFS(npm_publish 的体检与真发全部失败);
|
|
14
14
|
// 该目录没有 package.json 时报 ENOENT。现 publish 的两个调用点显式传 cwd=目标包目录,并给 runNpm 加 16MB maxBuffer。
|
|
15
15
|
// 2.8.3:文案修正——「零改动 / 无新提交」明确为**正常成功路径**(注入用法、工具描述、README、skill 同批改),并修 job 输出自相矛盾(cleanSkipCommit 路径补 committed:false,不再显示「已提交,未推送」)
|