@nodeve/checks 1.2.1 → 1.3.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 +46 -18
- package/dist/bin/catalog.js +3 -93
- package/dist/bin/catalog.js.map +1 -1
- package/dist/bin/check.d.ts +3 -0
- package/dist/bin/check.d.ts.map +1 -0
- package/dist/bin/check.js +69 -0
- package/dist/bin/check.js.map +1 -0
- package/dist/bin/clones.js +3 -58
- package/dist/bin/clones.js.map +1 -1
- package/dist/bin/commit-msg.js +3 -81
- package/dist/bin/commit-msg.js.map +1 -1
- package/dist/bin/doc-tokens.js +3 -66
- package/dist/bin/doc-tokens.js.map +1 -1
- package/dist/bin/file-size.js +3 -64
- package/dist/bin/file-size.js.map +1 -1
- package/dist/bin/helper-collisions.js +3 -92
- package/dist/bin/helper-collisions.js.map +1 -1
- package/dist/bin/inline-dupes.js +3 -77
- package/dist/bin/inline-dupes.js.map +1 -1
- package/dist/bin/page-size.js +3 -43
- package/dist/bin/page-size.js.map +1 -1
- package/dist/bin/require-deps.js +3 -47
- package/dist/bin/require-deps.js.map +1 -1
- package/dist/bin/reshape.js +3 -139
- package/dist/bin/reshape.js.map +1 -1
- package/dist/checks/catalog.d.ts +3 -0
- package/dist/checks/catalog.d.ts.map +1 -0
- package/dist/checks/catalog.js +100 -0
- package/dist/checks/catalog.js.map +1 -0
- package/dist/checks/clones.d.ts +3 -0
- package/dist/checks/clones.d.ts.map +1 -0
- package/dist/checks/clones.js +107 -0
- package/dist/checks/clones.js.map +1 -0
- package/dist/checks/commit-msg.d.ts +3 -0
- package/dist/checks/commit-msg.d.ts.map +1 -0
- package/dist/checks/commit-msg.js +88 -0
- package/dist/checks/commit-msg.js.map +1 -0
- package/dist/checks/doc-tokens.d.ts +13 -0
- package/dist/checks/doc-tokens.d.ts.map +1 -0
- package/dist/checks/doc-tokens.js +40 -0
- package/dist/checks/doc-tokens.js.map +1 -0
- package/dist/checks/file-size.d.ts +14 -0
- package/dist/checks/file-size.d.ts.map +1 -0
- package/dist/checks/file-size.js +36 -0
- package/dist/checks/file-size.js.map +1 -0
- package/dist/checks/helper-collisions.d.ts +3 -0
- package/dist/checks/helper-collisions.d.ts.map +1 -0
- package/dist/checks/helper-collisions.js +105 -0
- package/dist/checks/helper-collisions.js.map +1 -0
- package/dist/checks/inline-dupes.d.ts +3 -0
- package/dist/checks/inline-dupes.d.ts.map +1 -0
- package/dist/checks/inline-dupes.js +87 -0
- package/dist/checks/inline-dupes.js.map +1 -0
- package/dist/checks/page-size.d.ts +15 -0
- package/dist/checks/page-size.d.ts.map +1 -0
- package/dist/checks/page-size.js +32 -0
- package/dist/checks/page-size.js.map +1 -0
- package/dist/checks/require-deps.d.ts +19 -0
- package/dist/checks/require-deps.d.ts.map +1 -0
- package/dist/checks/require-deps.js +48 -0
- package/dist/checks/require-deps.js.map +1 -0
- package/dist/checks/reshape.d.ts +3 -0
- package/dist/checks/reshape.d.ts.map +1 -0
- package/dist/checks/reshape.js +138 -0
- package/dist/checks/reshape.js.map +1 -0
- package/dist/lib/bin.d.ts +9 -2
- package/dist/lib/bin.d.ts.map +1 -1
- package/dist/lib/bin.js +9 -4
- package/dist/lib/bin.js.map +1 -1
- package/dist/lib/config.d.ts +9 -39
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +12 -5
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/defaults.d.ts +22 -11
- package/dist/lib/defaults.d.ts.map +1 -1
- package/dist/lib/defaults.js +18 -16
- package/dist/lib/defaults.js.map +1 -1
- package/dist/lib/length.d.ts +62 -0
- package/dist/lib/length.d.ts.map +1 -0
- package/dist/lib/length.js +121 -0
- package/dist/lib/length.js.map +1 -0
- package/dist/lib/registry.d.ts +6 -0
- package/dist/lib/registry.d.ts.map +1 -0
- package/dist/lib/registry.js +34 -0
- package/dist/lib/registry.js.map +1 -0
- package/dist/lib/report.d.ts +40 -0
- package/dist/lib/report.d.ts.map +1 -0
- package/dist/lib/report.js +28 -0
- package/dist/lib/report.js.map +1 -0
- package/dist/lib/runner.d.ts +43 -0
- package/dist/lib/runner.d.ts.map +1 -0
- package/dist/lib/runner.js +41 -0
- package/dist/lib/runner.js.map +1 -0
- package/lefthook.checks.yml +31 -25
- package/nodeve.checks.defaults.js +18 -16
- package/package.json +3 -2
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type CheckResult } from './report.js';
|
|
2
|
+
/** A length budget. An omitted axis is unbounded — the check doesn't bound it. */
|
|
3
|
+
export type Budget = {
|
|
4
|
+
maxLines?: number;
|
|
5
|
+
maxTokens?: number;
|
|
6
|
+
};
|
|
7
|
+
/** A file's budget split into the soft (warn) and hard (fail) tiers; either may be absent. */
|
|
8
|
+
export type Tiers = {
|
|
9
|
+
warn?: Budget;
|
|
10
|
+
fail?: Budget;
|
|
11
|
+
};
|
|
12
|
+
/** Severity of a budget breach. `fail` blocks the commit; `warn` is a nudge. */
|
|
13
|
+
export type Severity = 'warn' | 'fail';
|
|
14
|
+
/**
|
|
15
|
+
* One per-glob budget adjustment. Files matching `glob` (a git pathspec, so `*`
|
|
16
|
+
* matches `/`) take `tiers` merged per-axis over the check's default tiers — set
|
|
17
|
+
* only the axis you change. `'exempt'` drops the file from the gate entirely (the
|
|
18
|
+
* old fileSize `allowlist`). Later overrides win where they overlap.
|
|
19
|
+
*/
|
|
20
|
+
export type Override = {
|
|
21
|
+
glob: string;
|
|
22
|
+
tiers: Tiers | 'exempt';
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The uniform config every length check reads. `globs` is the scope; `warn`/`fail`
|
|
26
|
+
* are the default tiers (omit an axis to leave it unbounded, omit a whole tier to
|
|
27
|
+
* drop it). A check with no default `fail` and `globs: []` is opt-in: only files
|
|
28
|
+
* matched by an override glob get a budget (page-size).
|
|
29
|
+
*/
|
|
30
|
+
export type LengthConfig = {
|
|
31
|
+
globs: string[];
|
|
32
|
+
warn?: Budget;
|
|
33
|
+
fail?: Budget;
|
|
34
|
+
overrides?: Override[];
|
|
35
|
+
};
|
|
36
|
+
export type Offender = {
|
|
37
|
+
path: string;
|
|
38
|
+
severity: Severity;
|
|
39
|
+
/** Per-axis `actual/limit` labels for the breached tier, e.g. `['392/300L']` or `['180/150L', '4200/3000T']`. */
|
|
40
|
+
breaches: string[];
|
|
41
|
+
/** The worst breached axis's actual count, for worst-first sorting. */
|
|
42
|
+
weight: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Measure each in-scope file and classify it against its resolved tiers — `fail`
|
|
46
|
+
* takes precedence over `warn`. `only` (lefthook `{staged_files}`) narrows the
|
|
47
|
+
* scan to staged paths when non-empty. Offenders come back sorted worst-first.
|
|
48
|
+
*/
|
|
49
|
+
export declare function measureBudgets(root: string, config: LengthConfig, only?: string[]): Offender[];
|
|
50
|
+
/** Uniform offender row: the breach labels, left-justified, then the path. */
|
|
51
|
+
export declare const lengthRow: (o: Offender) => string;
|
|
52
|
+
/**
|
|
53
|
+
* The warn/fail grading every blocking length check shares: `fail` offenders block
|
|
54
|
+
* (with a tail count of the soft-budget ones), else `warn` offenders nudge, else
|
|
55
|
+
* pass. `labels` supplies the three summaries.
|
|
56
|
+
*/
|
|
57
|
+
export declare function gradeOffenders(offenders: Offender[], labels: {
|
|
58
|
+
fail: (n: number) => string;
|
|
59
|
+
warn: (n: number) => string;
|
|
60
|
+
pass: string;
|
|
61
|
+
}): CheckResult;
|
|
62
|
+
//# sourceMappingURL=length.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"length.d.ts","sourceRoot":"","sources":["../../src/lib/length.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,kFAAkF;AAClF,MAAM,MAAM,MAAM,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/D,8FAA8F;AAC9F,M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
1
|
+
/**
|
|
2
|
+
* The shared length-budget engine behind file-size, page-size and doc-tokens.
|
|
3
|
+
* Each of those checks is the same shape — measure every file in a scope, compare
|
|
4
|
+
* it to a per-file budget, report the offenders worst-first — and differed only
|
|
5
|
+
* in which axes they bound (lines, tokens), whether they carry a soft tier, and
|
|
6
|
+
* how they override the default per path. Three override vocabularies
|
|
7
|
+
* (`allowlist`, `rules`, per-path `overrides`) collapsed into one here: a check
|
|
8
|
+
* supplies a `LengthConfig` and maps the returned offenders to its CheckResult.
|
|
9
|
+
*/
|
|
10
|
+
import { getEncoding } from 'js-tiktoken';
|
|
11
|
+
import { readFileSync } from 'node:fs';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import {} from './report.js';
|
|
14
|
+
import { gitFiles, lineCount } from './repo.js';
|
|
15
|
+
/** Merge `over` per-axis onto `base`; an absent `over` leaves `base` untouched. */
|
|
16
|
+
const mergeBudget = (base, over) => over ? { ...base, ...over } : base;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve every in-scope file to its tiers: start at the default warn/fail, apply
|
|
19
|
+
* each matching override in order (later wins, `'exempt'` drops it), and keep the
|
|
20
|
+
* survivors. The target set is `globs` ∪ every override glob, so a file matched
|
|
21
|
+
* only by an override (page-size's `*+page.svelte`) is still measured. Each
|
|
22
|
+
* override's match set is globbed once, not per file.
|
|
23
|
+
*/
|
|
24
|
+
function resolveTargets(root, config) {
|
|
25
|
+
const overrides = (config.overrides ?? []).map((o) => ({
|
|
26
|
+
match: new Set(gitFiles(root, [o.glob])),
|
|
27
|
+
tiers: o.tiers,
|
|
28
|
+
}));
|
|
29
|
+
const scope = new Set(gitFiles(root, config.globs));
|
|
30
|
+
for (const o of overrides)
|
|
31
|
+
for (const path of o.match)
|
|
32
|
+
scope.add(path);
|
|
33
|
+
const out = [];
|
|
34
|
+
for (const path of scope) {
|
|
35
|
+
// `null` = exempt. A later tier override re-budgets from scratch (the `?? {}`),
|
|
36
|
+
// so exemption isn't sticky if a more specific glob deliberately re-adds one.
|
|
37
|
+
let tiers = { warn: config.warn, fail: config.fail };
|
|
38
|
+
for (const o of overrides) {
|
|
39
|
+
if (!o.match.has(path))
|
|
40
|
+
continue;
|
|
41
|
+
if (o.tiers === 'exempt') {
|
|
42
|
+
tiers = null;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const cur = tiers ?? {};
|
|
46
|
+
tiers = { warn: mergeBudget(cur.warn, o.tiers.warn), fail: mergeBudget(cur.fail, o.tiers.fail) };
|
|
47
|
+
}
|
|
48
|
+
if (tiers)
|
|
49
|
+
out.push({ path, tiers });
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/** The breached axes of `budget`, with the actual count for sorting; empty if within budget. */
|
|
54
|
+
function breachesOf(lines, tokens, budget) {
|
|
55
|
+
if (!budget)
|
|
56
|
+
return [];
|
|
57
|
+
const out = [];
|
|
58
|
+
if (budget.maxLines !== undefined && lines > budget.maxLines)
|
|
59
|
+
out.push({ label: `${lines}/${budget.maxLines}L`, actual: lines });
|
|
60
|
+
// `tokens()` is only invoked when an axis actually bounds tokens, so a
|
|
61
|
+
// lines-only check (file-size, page-size) never pays the tiktoken encode.
|
|
62
|
+
if (budget.maxTokens !== undefined && tokens() > budget.maxTokens)
|
|
63
|
+
out.push({ label: `${tokens()}/${budget.maxTokens}T`, actual: tokens() });
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Measure each in-scope file and classify it against its resolved tiers — `fail`
|
|
68
|
+
* takes precedence over `warn`. `only` (lefthook `{staged_files}`) narrows the
|
|
69
|
+
* scan to staged paths when non-empty. Offenders come back sorted worst-first.
|
|
70
|
+
*/
|
|
71
|
+
export function measureBudgets(root, config, only = []) {
|
|
72
|
+
const onlySet = only.length > 0 ? new Set(only) : null;
|
|
73
|
+
const targets = resolveTargets(root, config).filter((t) => !onlySet || onlySet.has(t.path));
|
|
74
|
+
// One encoder for the whole run; per-file token counts are memoized in `tokens`.
|
|
75
|
+
let enc = null;
|
|
76
|
+
const offenders = [];
|
|
77
|
+
for (const { path, tiers } of targets) {
|
|
78
|
+
const lines = lineCount(root, path);
|
|
79
|
+
let counted = null;
|
|
80
|
+
const tokens = () => {
|
|
81
|
+
if (counted === null) {
|
|
82
|
+
enc ??= getEncoding('o200k_base');
|
|
83
|
+
counted = enc.encode(readFileSync(join(root, path), 'utf8')).length;
|
|
84
|
+
}
|
|
85
|
+
return counted;
|
|
86
|
+
};
|
|
87
|
+
const breaches = breachesOf(lines, tokens, tiers.fail);
|
|
88
|
+
const severity = breaches.length > 0 ? 'fail' : 'warn';
|
|
89
|
+
const hits = breaches.length > 0 ? breaches : breachesOf(lines, tokens, tiers.warn);
|
|
90
|
+
if (hits.length === 0)
|
|
91
|
+
continue;
|
|
92
|
+
offenders.push({
|
|
93
|
+
path,
|
|
94
|
+
severity,
|
|
95
|
+
breaches: hits.map((h) => h.label),
|
|
96
|
+
weight: Math.max(...hits.map((h) => h.actual)),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return offenders.sort((a, b) => b.weight - a.weight);
|
|
100
|
+
}
|
|
101
|
+
/** Uniform offender row: the breach labels, left-justified, then the path. */
|
|
102
|
+
export const lengthRow = (o) => `${o.breaches.join(' ').padEnd(22)} ${o.path}`;
|
|
103
|
+
/**
|
|
104
|
+
* The warn/fail grading every blocking length check shares: `fail` offenders block
|
|
105
|
+
* (with a tail count of the soft-budget ones), else `warn` offenders nudge, else
|
|
106
|
+
* pass. `labels` supplies the three summaries.
|
|
107
|
+
*/
|
|
108
|
+
export function gradeOffenders(offenders, labels) {
|
|
109
|
+
const failing = offenders.filter((o) => o.severity === 'fail');
|
|
110
|
+
const warning = offenders.filter((o) => o.severity === 'warn');
|
|
111
|
+
if (failing.length > 0) {
|
|
112
|
+
const rows = failing.map(lengthRow);
|
|
113
|
+
if (warning.length > 0)
|
|
114
|
+
rows.push(`… plus ${warning.length} over the soft budget`);
|
|
115
|
+
return { status: 'fail', summary: labels.fail(failing.length), rows };
|
|
116
|
+
}
|
|
117
|
+
if (warning.length > 0)
|
|
118
|
+
return { status: 'warn', summary: labels.warn(warning.length), rows: warning.map(lengthRow) };
|
|
119
|
+
return { status: 'pass', summary: labels.pass };
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=length.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"length.js","sourceRoot":"","sources":["../../src/lib/length.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAoB,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAyChD,mFAAmF;AACnF,MAAM,WAAW,GAAG,CAAC,IAAwB,EAAE,IAAwB,EAAsB,EAAE,CAC9F,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAEpC;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,IAAY,EAAE,MAAoB;IACzD,MAAM,SAAS,GAAG,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACtD,KAAK,EAAE,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACxC,KAAK,EAAE,CAAC,CAAC,KAAK;KACd,CAAC,CAAC,CAAC;IAEJ,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACpD,KAAK,MAAM,CA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AI,EAAE,CAAC;AAEjG;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC7B,SAAqB,EACrB,MAAkF;IAElF,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC;IAC/D,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC;IAE/D,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACpC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;YAAE,IAAI,CAAC,IAAI,CAAC,UAAU,OAAO,CAAC,MAAM,uBAAuB,CAAC,CAAC;QACnF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;IACvE,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QACrB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;IAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Check } from './runner.js';
|
|
2
|
+
export declare const CHECKS: Check[];
|
|
3
|
+
/** Checks the bare-`nodeve-check` suite runs — every pre-commit check. */
|
|
4
|
+
export declare const PRE_COMMIT: Check[];
|
|
5
|
+
export declare const byName: Map<string, Check>;
|
|
6
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/lib/registry.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,eAAO,MAAM,MAAM,EAAE,KAAK,EAWzB,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,UAAU,SAAkD,CAAC;AAE1E,eAAO,MAAM,MAAM,oBAA0C,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The check registry — every check the gate knows about, in a sensible run
|
|
3
|
+
* order. The `nodeve-check` dispatcher resolves a subcommand against `byName`
|
|
4
|
+
* and runs the whole `pre-commit` set for a bare `nodeve-check`. `commit-msg`
|
|
5
|
+
* lives here too but runs on its own hook (it needs the message file), so the
|
|
6
|
+
* suite run skips it.
|
|
7
|
+
*/
|
|
8
|
+
import { catalog } from '../checks/catalog.js';
|
|
9
|
+
import { clones } from '../checks/clones.js';
|
|
10
|
+
import { commitMsg } from '../checks/commit-msg.js';
|
|
11
|
+
import { docTokens } from '../checks/doc-tokens.js';
|
|
12
|
+
import { fileSize } from '../checks/file-size.js';
|
|
13
|
+
import { helperCollisions } from '../checks/helper-collisions.js';
|
|
14
|
+
import { inlineDupes } from '../checks/inline-dupes.js';
|
|
15
|
+
import { pageSize } from '../checks/page-size.js';
|
|
16
|
+
import { requireDeps } from '../checks/require-deps.js';
|
|
17
|
+
import { reshape } from '../checks/reshape.js';
|
|
18
|
+
import {} from './runner.js';
|
|
19
|
+
export const CHECKS = [
|
|
20
|
+
docTokens,
|
|
21
|
+
reshape,
|
|
22
|
+
fileSize,
|
|
23
|
+
pageSize,
|
|
24
|
+
inlineDupes,
|
|
25
|
+
helperCollisions,
|
|
26
|
+
clones,
|
|
27
|
+
catalog,
|
|
28
|
+
requireDeps,
|
|
29
|
+
commitMsg,
|
|
30
|
+
];
|
|
31
|
+
/** Checks the bare-`nodeve-check` suite runs — every pre-commit check. */
|
|
32
|
+
export const PRE_COMMIT = CHECKS.filter((c) => c.name !== commitMsg.name);
|
|
33
|
+
export const byName = new Map(CHECKS.map((c) => [c.name, c]));
|
|
34
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/lib/registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAc,MAAM,aAAa,CAAC;AAEzC,MAAM,CAAC,MAAM,MAAM,GAAY;IAC9B,SAAS;IACT,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,WAAW;IACX,gBAAgB;IAChB,MAAM;IACN,OAAO;IACP,WAAW;IACX,SAAS;CACT,CAAC;AAEF,0EAA0E;AAC1E,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAC,CAAC;AAE1E,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Uniform reporting for every check. A check no longer prints its own ad-hoc
|
|
3
|
+
* format and calls `process.exit` — it RETURNS a `CheckResult`, and this one
|
|
4
|
+
* reporter renders every check the same way. That's the fix for the gate's
|
|
5
|
+
* failure dump being a wall of per-check formats: each block now opens with the
|
|
6
|
+
* same `<glyph> <name> — <summary>` headline and indents its detail rows by a
|
|
7
|
+
* fixed amount. The multi-paragraph remediation essay lives on `Check.explain`,
|
|
8
|
+
* kept out of the default output and surfaced only under `--explain`.
|
|
9
|
+
*/
|
|
10
|
+
export type CheckStatus = 'pass' | 'warn' | 'fail' | 'skip';
|
|
11
|
+
export type CheckResult = {
|
|
12
|
+
status: CheckStatus;
|
|
13
|
+
/** One-line headline shown after the glyph + check name (no leading glyph). */
|
|
14
|
+
summary: string;
|
|
15
|
+
/**
|
|
16
|
+
* Detail lines, one per visual line; the reporter indents each by two spaces.
|
|
17
|
+
* A grouped listing uses its own relative indent on top of that (e.g. a
|
|
18
|
+
* sub-item leads with two more spaces). Empty/omitted for a bare headline.
|
|
19
|
+
*/
|
|
20
|
+
rows?: string[];
|
|
21
|
+
};
|
|
22
|
+
/** The status glyph, for callers that lay out their own summary (the dispatcher). */
|
|
23
|
+
export declare const glyph: (status: CheckStatus) => string;
|
|
24
|
+
/**
|
|
25
|
+
* Render one check's result as a single uniform block (no surrounding blank
|
|
26
|
+
* lines — the caller owns spacing between blocks).
|
|
27
|
+
*
|
|
28
|
+
* `explain` is the check's remediation prose. It prints inline on a failing or
|
|
29
|
+
* warning block — that's the WHY/HOW a developer hitting the gate needs, and
|
|
30
|
+
* gating it behind a flag (or a rerun pointer) means it's never read. Separately,
|
|
31
|
+
* the `--explain` flag expands each check's bulky per-finding DETAIL (clones
|
|
32
|
+
* code fragments, inline-dupes file lists) — handled in the check's own `run`,
|
|
33
|
+
* not here.
|
|
34
|
+
*/
|
|
35
|
+
export declare function render(name: string, r: CheckResult, opts?: {
|
|
36
|
+
explain?: string;
|
|
37
|
+
}): string;
|
|
38
|
+
/** A check fails the gate only on `fail`, and `--warn` downgrades even that. */
|
|
39
|
+
export declare function exitCode(r: CheckResult, warn: boolean): number;
|
|
40
|
+
//# sourceMappingURL=report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../src/lib/report.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAE5D,MAAM,MAAM,WAAW,GAAG;IACzB,MAAM,EAAE,WAAW,CAAC;IACpB,+EAA+E;IAC/E,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAIF,qFAAqF;AACrF,eAAO,MAAM,KAAK,GAAI,QAAQ,WAAW,KAAG,MAAuB,CAAC;AAIpE;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,EAAE,IAAI,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,MAAM,CAM5F;AAED,gFAAgF;AAChF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAE9D"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const GLYPH = { pass: '✓', warn: '⚠', fail: '✖', skip: '·' };
|
|
2
|
+
/** The status glyph, for callers that lay out their own summary (the dispatcher). */
|
|
3
|
+
export const glyph = (status) => GLYPH[status];
|
|
4
|
+
const indent = (text, pad = ' ') => text.replace(/^/gm, pad).replace(/\s+$/, '');
|
|
5
|
+
/**
|
|
6
|
+
* Render one check's result as a single uniform block (no surrounding blank
|
|
7
|
+
* lines — the caller owns spacing between blocks).
|
|
8
|
+
*
|
|
9
|
+
* `explain` is the check's remediation prose. It prints inline on a failing or
|
|
10
|
+
* warning block — that's the WHY/HOW a developer hitting the gate needs, and
|
|
11
|
+
* gating it behind a flag (or a rerun pointer) means it's never read. Separately,
|
|
12
|
+
* the `--explain` flag expands each check's bulky per-finding DETAIL (clones
|
|
13
|
+
* code fragments, inline-dupes file lists) — handled in the check's own `run`,
|
|
14
|
+
* not here.
|
|
15
|
+
*/
|
|
16
|
+
export function render(name, r, opts = {}) {
|
|
17
|
+
const lines = [`${GLYPH[r.status]} ${name} — ${r.summary}`];
|
|
18
|
+
for (const row of r.rows ?? [])
|
|
19
|
+
lines.push(indent(row));
|
|
20
|
+
if ((r.status === 'fail' || r.status === 'warn') && opts.explain)
|
|
21
|
+
lines.push('', indent(opts.explain.trim()));
|
|
22
|
+
return lines.join('\n');
|
|
23
|
+
}
|
|
24
|
+
/** A check fails the gate only on `fail`, and `--warn` downgrades even that. */
|
|
25
|
+
export function exitCode(r, warn) {
|
|
26
|
+
return r.status === 'fail' && !warn ? 1 : 0;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.js","sourceRoot":"","sources":["../../src/lib/report.ts"],"names":[],"mappings":"AAuBA,MAAM,KAAK,GAAgC,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AAE1F,qFAAqF;AACrF,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,MAAmB,EAAU,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAEpE,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,GAAG,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAE1F;;;;;;;;;;GAUG;AACH,MAAM,UAAU,MAAM,CAAC,IAAY,EAAE,CAAc,EAAE,OAA6B,EAAE;IACnF,MAAM,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5D,KAAK,MAAM,GAAG,IAAI,CAAC,CAAC,IAAI,IAAI,EAAE;QAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACxD,IAAI,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO;QAC/D,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC7C,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,QAAQ,CAAC,CAAc,EAAE,IAAa;IACrD,OAAO,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The check contract and the glue that runs one. Each check is a `Check` object:
|
|
3
|
+
* it declares its `name`, the config `section` it reads, its `explain` prose, and
|
|
4
|
+
* a `run(gate)` that RETURNS a `CheckResult` instead of printing and exiting. The
|
|
5
|
+
* per-check bins (`nodeve-check-file-size` …) and the `nodeve-check` dispatcher
|
|
6
|
+
* both drive checks through here, so output and exit codes are identical however
|
|
7
|
+
* a check is invoked.
|
|
8
|
+
*/
|
|
9
|
+
import { type Config } from './config.js';
|
|
10
|
+
import { type Gate } from './bin.js';
|
|
11
|
+
import { type CheckResult } from './report.js';
|
|
12
|
+
export type Check<K extends keyof Config = keyof Config> = {
|
|
13
|
+
/** CLI / lefthook-job name, e.g. `file-size`. */
|
|
14
|
+
name: string;
|
|
15
|
+
/** Config section the check reads (drives `loadGate`). */
|
|
16
|
+
section: K;
|
|
17
|
+
/** Full remediation prose, surfaced only on `--explain`. */
|
|
18
|
+
explain: string;
|
|
19
|
+
/** Inspect the gate, return a result. No printing, no `process.exit`. */
|
|
20
|
+
run(gate: Gate<K>): CheckResult | Promise<CheckResult>;
|
|
21
|
+
};
|
|
22
|
+
/** Run a check against an explicit argv, returning its result and gate. */
|
|
23
|
+
export declare function runCheck<K extends keyof Config>(check: Check<K>, argv: string[]): Promise<{
|
|
24
|
+
result: CheckResult;
|
|
25
|
+
gate: Gate<K>;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Print one check's block to stderr, unless it passed/skipped silently. A clean
|
|
29
|
+
* run stays quiet (the gate shouldn't log on every commit) except under
|
|
30
|
+
* `--verbose`. Spacing around the block is owned here so the caller doesn't have
|
|
31
|
+
* to pad.
|
|
32
|
+
*/
|
|
33
|
+
export declare function emit(check: Check, result: CheckResult, flags: {
|
|
34
|
+
verbose: boolean;
|
|
35
|
+
explain: boolean;
|
|
36
|
+
}): void;
|
|
37
|
+
/**
|
|
38
|
+
* Entry point for a per-check bin: parse `process.argv`, run the check, emit its
|
|
39
|
+
* block, exit. `--explain` with no other work still runs the check (so the prose
|
|
40
|
+
* sits under a live result).
|
|
41
|
+
*/
|
|
42
|
+
export declare function runBin<K extends keyof Config>(check: Check<K>): Promise<never>;
|
|
43
|
+
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/lib/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAY,KAAK,IAAI,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,KAAK,WAAW,EAAoB,MAAM,aAAa,CAAC;AAEjE,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,MAAM,MAAM,GAAG,MAAM,MAAM,IAAI;IAC1D,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,OAAO,EAAE,CAAC,CAAC;IACX,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACvD,CAAC;AAEF,2EAA2E;AAC3E,wBAAsB,QAAQ,CAAC,CAAC,SAAS,MAAM,MAAM,EACpD,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,IAAI,EAAE,MAAM,EAAE,GACZ,OAAO,CAAC;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC,CAGjD;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CACnB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAC3C,IAAI,CAKN;AAED;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAKpF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The check contract and the glue that runs one. Each check is a `Check` object:
|
|
3
|
+
* it declares its `name`, the config `section` it reads, its `explain` prose, and
|
|
4
|
+
* a `run(gate)` that RETURNS a `CheckResult` instead of printing and exiting. The
|
|
5
|
+
* per-check bins (`nodeve-check-file-size` …) and the `nodeve-check` dispatcher
|
|
6
|
+
* both drive checks through here, so output and exit codes are identical however
|
|
7
|
+
* a check is invoked.
|
|
8
|
+
*/
|
|
9
|
+
import {} from './config.js';
|
|
10
|
+
import { loadGate } from './bin.js';
|
|
11
|
+
import { exitCode, render } from './report.js';
|
|
12
|
+
/** Run a check against an explicit argv, returning its result and gate. */
|
|
13
|
+
export async function runCheck(check, argv) {
|
|
14
|
+
const gate = await loadGate(check.section, argv);
|
|
15
|
+
return { result: await check.run(gate), gate };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Print one check's block to stderr, unless it passed/skipped silently. A clean
|
|
19
|
+
* run stays quiet (the gate shouldn't log on every commit) except under
|
|
20
|
+
* `--verbose`. Spacing around the block is owned here so the caller doesn't have
|
|
21
|
+
* to pad.
|
|
22
|
+
*/
|
|
23
|
+
export function emit(check, result, flags) {
|
|
24
|
+
const quiet = (result.status === 'pass' || result.status === 'skip') && !flags.verbose;
|
|
25
|
+
if (quiet)
|
|
26
|
+
return;
|
|
27
|
+
const block = render(check.name, result, { explain: check.explain });
|
|
28
|
+
process.stderr.write(`\n${block}\n\n`);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Entry point for a per-check bin: parse `process.argv`, run the check, emit its
|
|
32
|
+
* block, exit. `--explain` with no other work still runs the check (so the prose
|
|
33
|
+
* sits under a live result).
|
|
34
|
+
*/
|
|
35
|
+
export async function runBin(check) {
|
|
36
|
+
const argv = process.argv.slice(2);
|
|
37
|
+
const { result, gate } = await runCheck(check, argv);
|
|
38
|
+
emit(check, result, gate);
|
|
39
|
+
process.exit(exitCode(result, gate.warn));
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/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,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3C,CAAC"}
|
package/lefthook.checks.yml
CHANGED
|
@@ -13,17 +13,23 @@
|
|
|
13
13
|
# this one as-is. Either way it's one `extends` line and all the standard checks
|
|
14
14
|
# come along together.
|
|
15
15
|
#
|
|
16
|
-
# Each job shells
|
|
17
|
-
# pnpm and bun, and resolvable since
|
|
18
|
-
# does NOT add node_modules/.bin to
|
|
19
|
-
#
|
|
20
|
-
#
|
|
16
|
+
# Each job shells the `nodeve-check` dispatcher with the check's name via its
|
|
17
|
+
# node_modules/.bin path — portable across pnpm and bun, and resolvable since
|
|
18
|
+
# lefthook runs from the repo root (lefthook does NOT add node_modules/.bin to
|
|
19
|
+
# PATH). Every check renders the SAME uniform block (`<glyph> <name> — <summary>`
|
|
20
|
+
# + indented rows + an `--explain` pointer), so when the parallel group surfaces a
|
|
21
|
+
# failure the captured output is scannable instead of a wall of per-check formats.
|
|
22
|
+
# The dispatcher reads the repo's optional `nodeve.checks.js` for
|
|
23
|
+
# budgets/globs/allowlists and derives the repo root from git, so a check behaves
|
|
24
|
+
# the same whatever cwd lefthook uses.
|
|
21
25
|
#
|
|
22
26
|
# `{staged_files}` scopes path-aware checks to what's being committed; the dup and
|
|
23
27
|
# catalog jobs scan their full configured scope because a duplicate (or an
|
|
24
28
|
# un-cataloged pin) is a property of the whole tree, not one file. Bypass with
|
|
25
29
|
# `git commit --no-verify`. Run a single check by hand any time, e.g.
|
|
26
|
-
# `node_modules/.bin/nodeve-check
|
|
30
|
+
# `node_modules/.bin/nodeve-check doc-tokens --report`, or the whole suite at once
|
|
31
|
+
# with `nodeve-check` (summary-first). The per-check `nodeve-check-<name>` bins
|
|
32
|
+
# remain for direct invocation.
|
|
27
33
|
pre-commit:
|
|
28
34
|
jobs:
|
|
29
35
|
# Fixer, runs before the `checks` group so the gates see formatted, re-staged
|
|
@@ -33,7 +39,7 @@ pre-commit:
|
|
|
33
39
|
# `.prettierignore`. It skips symlinked docs itself, so no `file_types` filter
|
|
34
40
|
# is needed here.
|
|
35
41
|
- name: format-markdown
|
|
36
|
-
glob:
|
|
42
|
+
glob: '*.md'
|
|
37
43
|
run: node_modules/.bin/nodeve-format-markdown {staged_files}
|
|
38
44
|
stage_fixed: true
|
|
39
45
|
|
|
@@ -42,47 +48,47 @@ pre-commit:
|
|
|
42
48
|
parallel: true
|
|
43
49
|
jobs:
|
|
44
50
|
- name: doc-tokens
|
|
45
|
-
glob:
|
|
46
|
-
run: node_modules/.bin/nodeve-check
|
|
51
|
+
glob: '*.md'
|
|
52
|
+
run: node_modules/.bin/nodeve-check doc-tokens {staged_files}
|
|
47
53
|
|
|
48
54
|
- name: reshape
|
|
49
|
-
glob:
|
|
50
|
-
run: node_modules/.bin/nodeve-check
|
|
55
|
+
glob: '*.ts'
|
|
56
|
+
run: node_modules/.bin/nodeve-check reshape {staged_files}
|
|
51
57
|
|
|
52
58
|
- name: page-size
|
|
53
|
-
run: node_modules/.bin/nodeve-check
|
|
59
|
+
run: node_modules/.bin/nodeve-check page-size {staged_files}
|
|
54
60
|
|
|
55
61
|
- name: file-size
|
|
56
|
-
glob:
|
|
57
|
-
run: node_modules/.bin/nodeve-check
|
|
62
|
+
glob: '*.ts'
|
|
63
|
+
run: node_modules/.bin/nodeve-check file-size {staged_files}
|
|
58
64
|
|
|
59
65
|
# Whole-tree property — every manifest's deps must single-source from a
|
|
60
66
|
# catalog. No-ops on repos without one, so it's safe to always run.
|
|
61
67
|
- name: catalog
|
|
62
|
-
glob:
|
|
63
|
-
run: node_modules/.bin/nodeve-check
|
|
68
|
+
glob: '**/package.json'
|
|
69
|
+
run: node_modules/.bin/nodeve-check catalog
|
|
64
70
|
|
|
65
71
|
# Whole-tree property — the workspace catalog must define the org-required
|
|
66
72
|
# deps (remeda by default). No-ops where deps aren't configured.
|
|
67
73
|
- name: require-deps
|
|
68
|
-
glob:
|
|
69
|
-
run: node_modules/.bin/nodeve-check
|
|
74
|
+
glob: '{**/package.json,pnpm-workspace.yaml}'
|
|
75
|
+
run: node_modules/.bin/nodeve-check require-deps
|
|
70
76
|
|
|
71
77
|
# Whole-tree relationships — scan the full configured scope, not just staged.
|
|
72
78
|
- name: inline-dupes
|
|
73
|
-
glob:
|
|
74
|
-
run: node_modules/.bin/nodeve-check
|
|
79
|
+
glob: '*.ts'
|
|
80
|
+
run: node_modules/.bin/nodeve-check inline-dupes
|
|
75
81
|
|
|
76
82
|
# Whole-tree property — structural copy-paste (jscpd). A clone is a
|
|
77
83
|
# relationship between two places, so it scans the full configured scope.
|
|
78
84
|
# No-ops if the jscpd binary isn't installed.
|
|
79
85
|
- name: clones
|
|
80
|
-
glob:
|
|
81
|
-
run: node_modules/.bin/nodeve-check
|
|
86
|
+
glob: '*.{ts,js}'
|
|
87
|
+
run: node_modules/.bin/nodeve-check clones
|
|
82
88
|
|
|
83
89
|
- name: helper-collisions
|
|
84
|
-
glob:
|
|
85
|
-
run: node_modules/.bin/nodeve-check
|
|
90
|
+
glob: '*.ts'
|
|
91
|
+
run: node_modules/.bin/nodeve-check helper-collisions {staged_files}
|
|
86
92
|
|
|
87
93
|
# The commit-msg hook fires after pre-commit, once a message exists. lefthook
|
|
88
94
|
# passes the message file path as `{1}`. The gate gives it Conventional-Commits
|
|
@@ -91,4 +97,4 @@ pre-commit:
|
|
|
91
97
|
commit-msg:
|
|
92
98
|
jobs:
|
|
93
99
|
- name: commit-msg
|
|
94
|
-
run: node_modules/.bin/nodeve-check
|
|
100
|
+
run: node_modules/.bin/nodeve-check commit-msg {1}
|
|
@@ -9,17 +9,17 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Merge semantics (see `loadConfig`): your config is deep-merged OVER these
|
|
11
11
|
* defaults. Nested records merge key-by-key, but ARRAYS REPLACE wholesale — so
|
|
12
|
-
* if you set an array field (e.g. `docTokens.
|
|
13
|
-
* entry you want to keep, not just the ones you're adding.
|
|
12
|
+
* if you set an array field (e.g. `docTokens.globs` or any `overrides`) you must
|
|
13
|
+
* restate every entry you want to keep, not just the ones you're adding.
|
|
14
14
|
*/
|
|
15
15
|
export default {
|
|
16
|
+
// Guarded markdown (CLAUDE.md + READMEs + guide/ + docs/) bounded on both lines
|
|
17
|
+
// and tokens. No default `warn` tier — add one per repo to nudge before the
|
|
18
|
+
// hard fail. Per-path bumps go in `overrides` (glob → tiers).
|
|
16
19
|
docTokens: {
|
|
17
|
-
|
|
18
|
-
maxTokens: 3000,
|
|
19
|
-
|
|
20
|
-
enforce: ['CLAUDE.md', 'README.md', '*/README.md', 'guide/*.md', 'docs/*.md'],
|
|
21
|
-
// Per-file budget bumps, keyed by repo-root-relative path.
|
|
22
|
-
overrides: {},
|
|
20
|
+
globs: ['CLAUDE.md', 'README.md', '*/README.md', 'guide/*.md', 'docs/*.md'],
|
|
21
|
+
fail: { maxLines: 150, maxTokens: 3000 },
|
|
22
|
+
overrides: [],
|
|
23
23
|
},
|
|
24
24
|
// On by default: Conventional Commits header + a body for non-trivial changes.
|
|
25
25
|
// Runs on the commit-msg hook. `bodyRequiredOverLines` measures the STAGED diff
|
|
@@ -68,16 +68,18 @@ export default {
|
|
|
68
68
|
mode: 'mild',
|
|
69
69
|
threshold: 0,
|
|
70
70
|
},
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
// no SvelteKit pages, so this
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
// Opt-in (empty `globs` → scope comes only from override globs): SvelteKit
|
|
72
|
+
// pages over 280 lines should rip inline components out into their own files.
|
|
73
|
+
// The `*+page.svelte` glob is a no-op in repos with no SvelteKit pages, so this
|
|
74
|
+
// stays harmless org-wide. Override per repo.
|
|
75
|
+
pageSize: { globs: [], overrides: [{ glob: '*+page.svelte', tiers: { fail: { maxLines: 280 } } }] },
|
|
76
|
+
// On by default: warn past 225 lines, block past 300. Give a long-but-cohesive
|
|
77
|
+
// file a bigger budget (or `tiers: 'exempt'`) via `overrides`, per repo.
|
|
76
78
|
fileSize: {
|
|
77
79
|
globs: ['apps/*.ts', 'packages/*.ts'],
|
|
78
|
-
|
|
79
|
-
maxLines: 300,
|
|
80
|
-
|
|
80
|
+
warn: { maxLines: 225 },
|
|
81
|
+
fail: { maxLines: 300 },
|
|
82
|
+
overrides: [],
|
|
81
83
|
},
|
|
82
84
|
// On by default: a workspace must declare a catalog (set enforce:false to opt out).
|
|
83
85
|
catalog: { enforce: true, allowlist: [] },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nodeve/checks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Org-wide commit-gate checks (doc budgets, reshape/dup/helper smells, page size) and helper-index generators, driven by a per-repo config file and wired through lefthook.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"./lefthook": "./lefthook.checks.yml"
|
|
30
30
|
},
|
|
31
31
|
"bin": {
|
|
32
|
+
"nodeve-check": "./dist/bin/check.js",
|
|
32
33
|
"nodeve-check-doc-tokens": "./dist/bin/doc-tokens.js",
|
|
33
34
|
"nodeve-check-commit-msg": "./dist/bin/commit-msg.js",
|
|
34
35
|
"nodeve-check-reshape": "./dist/bin/reshape.js",
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
57
|
"@types/node": "^22.0.0",
|
|
57
|
-
"@nodeve/config": "0.
|
|
58
|
+
"@nodeve/config": "0.4.1"
|
|
58
59
|
},
|
|
59
60
|
"scripts": {
|
|
60
61
|
"build": "tsc -p tsconfig.json && cp dist/lib/defaults.js nodeve.checks.defaults.js",
|