@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,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commit gate: structural copy-paste detector over the repo's own sources,
|
|
3
|
+
* backed by jscpd v5. It flags duplicated *blocks* living in function bodies,
|
|
4
|
+
* which the name-based gates (`inline-dupes`, `helper-collisions`) can't see. A
|
|
5
|
+
* clone is a whole-tree property, so this scans the configured `paths` in full.
|
|
6
|
+
*
|
|
7
|
+
* jscpd does the detection; we own the REPORTING. Its `consoleFull` reporter
|
|
8
|
+
* buries the one thing that matters — *where* the duplicated blocks are. So we
|
|
9
|
+
* run it `--silent` with the `json` reporter and parse that, surfacing each
|
|
10
|
+
* clone's two locations by default (the bulky shared fragment only under
|
|
11
|
+
* `--explain`, so a multi-clone repo doesn't bury the gate). jscpd's binary ships
|
|
12
|
+
* as an optionalDependency, so a partial/offline install can leave it absent —
|
|
13
|
+
* then this skips rather than blocking the commit.
|
|
14
|
+
*/
|
|
15
|
+
import { spawnSync } from 'node:child_process';
|
|
16
|
+
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
17
|
+
import { createRequire } from 'node:module';
|
|
18
|
+
import { tmpdir } from 'node:os';
|
|
19
|
+
import { join, relative } from 'node:path';
|
|
20
|
+
import {} from '../lib/runner.js';
|
|
21
|
+
export const clones = {
|
|
22
|
+
name: 'clones',
|
|
23
|
+
section: 'clones',
|
|
24
|
+
explain: `Structural copy-paste (jscpd) flags duplicated blocks the name-based gates
|
|
25
|
+
can't see. Extract the shared logic, or narrow scope with clones.ignore globs.
|
|
26
|
+
--warn downgrades the gate to report-only.`,
|
|
27
|
+
run({ root, cfg, explain }) {
|
|
28
|
+
let launcher;
|
|
29
|
+
try {
|
|
30
|
+
launcher = createRequire(import.meta.url).resolve('jscpd/run-jscpd.js');
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return { status: 'skip', summary: 'jscpd binary not installed — skipping' };
|
|
34
|
+
}
|
|
35
|
+
// jscpd's `json` reporter writes `<output>/jscpd-report.json`; `--silent`
|
|
36
|
+
// keeps its progress bar, stats table, and footer off our stdout. Missing
|
|
37
|
+
// dirs are tolerated, so the configured paths go through as-is. `--absolute`
|
|
38
|
+
// makes report paths unambiguous; we re-relativize them for the listing.
|
|
39
|
+
const outDir = mkdtempSync(join(tmpdir(), 'nodeve-clones-'));
|
|
40
|
+
const jscpdRun = spawnSync(process.execPath, [
|
|
41
|
+
launcher,
|
|
42
|
+
...cfg.paths,
|
|
43
|
+
'--absolute',
|
|
44
|
+
'--min-tokens',
|
|
45
|
+
String(cfg.minTokens),
|
|
46
|
+
'--min-lines',
|
|
47
|
+
String(cfg.minLines),
|
|
48
|
+
'--mode',
|
|
49
|
+
cfg.mode,
|
|
50
|
+
'--format',
|
|
51
|
+
cfg.formats.join(','),
|
|
52
|
+
'--ignore',
|
|
53
|
+
cfg.ignore.join(','),
|
|
54
|
+
'--reporters',
|
|
55
|
+
'json',
|
|
56
|
+
'--output',
|
|
57
|
+
outDir,
|
|
58
|
+
'--silent',
|
|
59
|
+
'--threshold',
|
|
60
|
+
String(cfg.threshold),
|
|
61
|
+
], { cwd: root, encoding: 'utf8' });
|
|
62
|
+
// jscpd exits non-zero only when duplication crosses `--threshold`.
|
|
63
|
+
if (jscpdRun.status === 0) {
|
|
64
|
+
rmSync(outDir, { recursive: true, force: true });
|
|
65
|
+
return { status: 'pass', summary: 'no duplicated blocks over threshold' };
|
|
66
|
+
}
|
|
67
|
+
const rel = (p) => relative(root, p);
|
|
68
|
+
try {
|
|
69
|
+
let duplicates;
|
|
70
|
+
try {
|
|
71
|
+
const report = JSON.parse(readFileSync(join(outDir, 'jscpd-report.json'), 'utf8'));
|
|
72
|
+
duplicates = report.duplicates ?? [];
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// No report written → jscpd failed before detection (bad args, crash).
|
|
76
|
+
// Surface its own output so the failure isn't swallowed.
|
|
77
|
+
const out = [jscpdRun.stdout ?? '', jscpdRun.stderr ?? '']
|
|
78
|
+
.filter((s) => s.length > 0)
|
|
79
|
+
.join('\n')
|
|
80
|
+
.split('\n')
|
|
81
|
+
.filter((l) => l.length > 0);
|
|
82
|
+
return { status: 'fail', summary: 'jscpd failed before detection', rows: out };
|
|
83
|
+
}
|
|
84
|
+
const rows = [];
|
|
85
|
+
for (const d of duplicates) {
|
|
86
|
+
rows.push(`${rel(d.firstFile.name)}:${d.firstFile.start}-${d.firstFile.end}\n` +
|
|
87
|
+
`↔ ${rel(d.secondFile.name)}:${d.secondFile.start}-${d.secondFile.end}` +
|
|
88
|
+
` (${d.lines} lines, ${d.format})`);
|
|
89
|
+
// The shared code fragment is the bulky part (one clone can be 60+
|
|
90
|
+
// lines); a repo with several clones would bury the whole gate in code.
|
|
91
|
+
// Default to just the two locations + size; surface the fragments only
|
|
92
|
+
// under --explain, which the failure's pointer already advertises.
|
|
93
|
+
if (explain && d.fragment)
|
|
94
|
+
rows.push(d.fragment.replace(/^/gm, ' ').replace(/\s+$/, ''));
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
status: 'fail',
|
|
98
|
+
summary: `${duplicates.length} duplicated block(s) — extract the shared logic`,
|
|
99
|
+
rows,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
rmSync(outDir, { recursive: true, force: true });
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=clones.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clones.js","sourceRoot":"","sources":["../../src/checks/clones.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,SAAS,EAAE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AAO,EAAE,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAG9C,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,WAAW,CA6ExC,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commit-msg gate (on by default): the commit message must follow Conventional
|
|
3
|
+
* Commits, and a non-trivial change must carry a body explaining it.
|
|
4
|
+
*
|
|
5
|
+
* Unlike the other checks this runs on the `commit-msg` hook, not `pre-commit`:
|
|
6
|
+
* lefthook passes the path to the message file as `{1}`, which arrives here as
|
|
7
|
+
* `gate.paths[0]`. The header is matched against `<type>(<scope>)!: <subject>`;
|
|
8
|
+
* `type` must be one of `commitMsg.types` (the standard Conventional set by
|
|
9
|
+
* default) and the subject is length-capped.
|
|
10
|
+
*
|
|
11
|
+
* WHY a conditional body: a one-line subject is fine for a small, self-evident
|
|
12
|
+
* change, but past `commitMsg.bodyRequiredOverLines` changed lines (measured
|
|
13
|
+
* from the STAGED diff via `git diff --cached --numstat`) the "what" no longer
|
|
14
|
+
* implies the "why" — those commits must include a body. Size, not the declared
|
|
15
|
+
* type, is what decides a change needs explaining.
|
|
16
|
+
*
|
|
17
|
+
* Skipped automatically: merge commits, reverts, and fixup!/squash!/amend!
|
|
18
|
+
* autosquash messages — git or rebase authors and consumes those. An empty
|
|
19
|
+
* message is left alone too, since git aborts that commit on its own.
|
|
20
|
+
*
|
|
21
|
+
* `commitMsg.enforce: false` opts a repo out; `--warn` downgrades to report-only.
|
|
22
|
+
*/
|
|
23
|
+
import { readFileSync } from 'node:fs';
|
|
24
|
+
import {} from '../lib/runner.js';
|
|
25
|
+
import { stagedDiffLines } from '../lib/repo.js';
|
|
26
|
+
export const commitMsg = {
|
|
27
|
+
name: 'commit-msg',
|
|
28
|
+
section: 'commitMsg',
|
|
29
|
+
explain: `Conventional Commits — format <type>(<optional scope>): <subject>.
|
|
30
|
+
The type must be one of the configured types, and the subject is length-capped.
|
|
31
|
+
Example:
|
|
32
|
+
feat(checks): add commit-message gate
|
|
33
|
+
|
|
34
|
+
Sizeable changes need a body: leave a blank line after the subject, then
|
|
35
|
+
explain WHY the change is needed.`,
|
|
36
|
+
run({ root, cfg, paths }) {
|
|
37
|
+
if (!cfg.enforce)
|
|
38
|
+
return { status: 'skip', summary: 'disabled (commitMsg.enforce: false)' };
|
|
39
|
+
// lefthook passes the message file path as `{1}` → first positional arg.
|
|
40
|
+
const msgPath = paths[0];
|
|
41
|
+
if (!msgPath)
|
|
42
|
+
return { status: 'fail', summary: 'no message file path given (expected lefthook `{1}`)' };
|
|
43
|
+
const raw = readFileSync(msgPath, 'utf8');
|
|
44
|
+
// git ignores comment lines and everything after the `# >8` scissors line
|
|
45
|
+
// (added by `commit --verbose`), so strip both before reading — otherwise the
|
|
46
|
+
// diff dump would read as a body and the comment hints would skew the header.
|
|
47
|
+
const scissors = raw.indexOf('\n# ------------------------ >8');
|
|
48
|
+
const lines = (scissors === -1 ? raw : raw.slice(0, scissors))
|
|
49
|
+
.split('\n')
|
|
50
|
+
.filter((l) => !l.startsWith('#'));
|
|
51
|
+
const headerIdx = lines.findIndex((l) => l.trim().length > 0);
|
|
52
|
+
const header = headerIdx === -1 ? '' : lines[headerIdx].trim();
|
|
53
|
+
// Empty message → the user is aborting; git rejects it without our help.
|
|
54
|
+
if (header === '')
|
|
55
|
+
return { status: 'skip', summary: 'empty message' };
|
|
56
|
+
// Messages git or an autosquash rebase generates and later consumes — not ours to gate.
|
|
57
|
+
if (/^(merge |revert "|fixup!|squash!|amend!)/i.test(header))
|
|
58
|
+
return {
|
|
59
|
+
status: 'skip',
|
|
60
|
+
summary: 'generated message (merge/revert/autosquash) — not gated',
|
|
61
|
+
};
|
|
62
|
+
const problems = [];
|
|
63
|
+
const m = header.match(/^(?<type>\w+)(?:\((?<scope>[^)]+)\))?(?<bang>!)?: (?<subject>.+)$/);
|
|
64
|
+
if (!m?.groups) {
|
|
65
|
+
problems.push(`header doesn't match "<type>(<scope>): <subject>" — got ${JSON.stringify(header)}`);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const { type, scope, subject } = m.groups;
|
|
69
|
+
if (cfg.types.length > 0 && !cfg.types.includes(type))
|
|
70
|
+
problems.push(`type "${type}" is not allowed — use one of: ${cfg.types.join(', ')}`);
|
|
71
|
+
if (cfg.requireScope && !scope)
|
|
72
|
+
problems.push('a scope is required: <type>(<scope>): <subject>');
|
|
73
|
+
if (subject.length > cfg.maxSubjectLength)
|
|
74
|
+
problems.push(`subject is ${subject.length} chars, over the ${cfg.maxSubjectLength}-char limit`);
|
|
75
|
+
}
|
|
76
|
+
// A body is any non-empty content separated from the header by a blank line.
|
|
77
|
+
const after = lines.slice(headerIdx + 1);
|
|
78
|
+
const hasBody = after.length > 1 && after[0].trim() === '' && after.slice(1).some((l) => l.trim().length > 0);
|
|
79
|
+
const changed = stagedDiffLines(root);
|
|
80
|
+
if (changed > cfg.bodyRequiredOverLines && !hasBody)
|
|
81
|
+
problems.push(`this commit changes ${changed} lines (> ${cfg.bodyRequiredOverLines}) and needs a body — ` +
|
|
82
|
+
'add a blank line after the subject, then explain WHY the change is needed');
|
|
83
|
+
if (problems.length === 0)
|
|
84
|
+
return { status: 'pass', summary: 'ok' };
|
|
85
|
+
return { status: 'fail', summary: 'commit message', rows: problems.map((p) => `• ${p}`) };
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=commit-msg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-msg.js","sourceRoot":"","sources":["../../src/checks/commit-msg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,CAAC,MAAM,SAAS,GAAuB;IAC5C,IAAI,EAAE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AI,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAE/F,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,OAAO,GAAG,GAAG,CAAC,qBAAqB,IAAI,CAAC,OAAO;YAClD,QAAQ,CAAC,IAAI,CACZ,uBAAuB,OAAO,aAAa,GAAG,CAAC,qBAAqB,uBAAuB;gBAC1F,2EAA2E,CAC5E,CAAC;QAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAEpE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;IAC3F,CAAC;CACD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commit gate: guarded markdown over its line or token budget.
|
|
3
|
+
*
|
|
4
|
+
* WHY: always-loaded / frequently-linked docs cost tokens and attention, so both
|
|
5
|
+
* dimensions are bounded. Tokenizer is js-tiktoken `o200k_base` — Claude's is
|
|
6
|
+
* unpublished and differs, so this is a stable *proxy* for budgeting, not an
|
|
7
|
+
* exact count: good enough to catch bloat, consistent run-to-run. Measure and
|
|
8
|
+
* classify are shared with file-size and page-size in `lib/length.ts`; this check
|
|
9
|
+
* owns the markdown scope, the two-axis default, and `--report` backlog mode.
|
|
10
|
+
*/
|
|
11
|
+
import { type Check } from '../lib/runner.js';
|
|
12
|
+
export declare const docTokens: Check<'docTokens'>;
|
|
13
|
+
//# sourceMappingURL=doc-tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-tokens.d.ts","sourceRoot":"","sources":["../../src/checks/doc-tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAG9C,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,WAAW,CA4BxC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commit gate: guarded markdown over its line or token budget.
|
|
3
|
+
*
|
|
4
|
+
* WHY: always-loaded / frequently-linked docs cost tokens and attention, so both
|
|
5
|
+
* dimensions are bounded. Tokenizer is js-tiktoken `o200k_base` — Claude's is
|
|
6
|
+
* unpublished and differs, so this is a stable *proxy* for budgeting, not an
|
|
7
|
+
* exact count: good enough to catch bloat, consistent run-to-run. Measure and
|
|
8
|
+
* classify are shared with file-size and page-size in `lib/length.ts`; this check
|
|
9
|
+
* owns the markdown scope, the two-axis default, and `--report` backlog mode.
|
|
10
|
+
*/
|
|
11
|
+
import {} from '../lib/runner.js';
|
|
12
|
+
import { gradeOffenders, lengthRow, measureBudgets } from '../lib/length.js';
|
|
13
|
+
export const docTokens = {
|
|
14
|
+
name: 'doc-tokens',
|
|
15
|
+
section: 'docTokens',
|
|
16
|
+
explain: `Guarded markdown (CLAUDE.md, READMEs, guide/, docs/) has line and token
|
|
17
|
+
budgets so always-loaded docs stay terse. Past the budget, don't trim to the
|
|
18
|
+
edge — split the doc into a directory with an index page plus detail pages, then
|
|
19
|
+
repoint inbound links at the new locations. --report lists the whole backlog
|
|
20
|
+
without failing, so you can work it down over time rather than at commit time.`,
|
|
21
|
+
run({ root, cfg, paths, report }) {
|
|
22
|
+
const offenders = measureBudgets(root, cfg, paths);
|
|
23
|
+
// `--report`: backlog mode — list every over-budget file, never fail.
|
|
24
|
+
if (report) {
|
|
25
|
+
if (offenders.length === 0)
|
|
26
|
+
return { status: 'pass', summary: 'no docs over budget' };
|
|
27
|
+
return {
|
|
28
|
+
status: 'warn',
|
|
29
|
+
summary: `backlog — ${offenders.length} over budget`,
|
|
30
|
+
rows: offenders.map(lengthRow),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return gradeOffenders(offenders, {
|
|
34
|
+
fail: (n) => `${n} markdown file(s) over budget — split into a dir with an index`,
|
|
35
|
+
warn: (n) => `${n} markdown file(s) approaching budget`,
|
|
36
|
+
pass: 'all docs within budget',
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=doc-tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-tokens.js","sourceRoot":"","sources":["../../src/checks/doc-tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE7E,MAAM,CAAC,MAAM,SAAS,GAAuB;IAC5C,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,WAAW;IACpB,OAAO,EAAE;;;;+EAIqE;IAE9E,GAAG,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE;QAC/B,MAAM,SAAS,GAAG,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QAEnD,sEAAsE;QACtE,IAAI,MAAM,EAAE,CAAC;YACZ,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,EAAE,CAAC;YACtF,OAAO;gBACN,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,aAAa,SAAS,CAAC,MAAM,cAAc;gBACpD,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;aAC9B,CAAC;QACH,CAAC;QAED,OAAO,cAAc,CAAC,SAAS,EAAE;YAChC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,gEAAgE;YACjF,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,sCAAsC;YACvD,IAAI,EAAE,wBAAwB;SAC9B,CAAC,CAAC;IACJ,CAAC;CACD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commit gate (on by default): TS source files in `apps/` and `packages/` have a
|
|
3
|
+
* line budget. Over the `warn` tier is a non-blocking nudge; over `fail` blocks
|
|
4
|
+
* the commit.
|
|
5
|
+
*
|
|
6
|
+
* Scope: `fileSize.globs` (default `apps/`, `packages/` `.ts`). Unlike the other
|
|
7
|
+
* `.ts` checks this does NOT auto-skip tests or declaration files — a long file
|
|
8
|
+
* is a long file. A file that genuinely runs long gets a bigger budget (or an
|
|
9
|
+
* exemption) via `fileSize.overrides` with a WHY comment. The measure/classify
|
|
10
|
+
* machinery is shared with page-size and doc-tokens in `lib/length.ts`.
|
|
11
|
+
*/
|
|
12
|
+
import { type Check } from '../lib/runner.js';
|
|
13
|
+
export declare const fileSize: Check<'fileSize'>;
|
|
14
|
+
//# sourceMappingURL=file-size.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-size.d.ts","sourceRoot":"","sources":["../../src/checks/file-size.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAG9C,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,UAAU,CAsBtC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commit gate (on by default): TS source files in `apps/` and `packages/` have a
|
|
3
|
+
* line budget. Over the `warn` tier is a non-blocking nudge; over `fail` blocks
|
|
4
|
+
* the commit.
|
|
5
|
+
*
|
|
6
|
+
* Scope: `fileSize.globs` (default `apps/`, `packages/` `.ts`). Unlike the other
|
|
7
|
+
* `.ts` checks this does NOT auto-skip tests or declaration files — a long file
|
|
8
|
+
* is a long file. A file that genuinely runs long gets a bigger budget (or an
|
|
9
|
+
* exemption) via `fileSize.overrides` with a WHY comment. The measure/classify
|
|
10
|
+
* machinery is shared with page-size and doc-tokens in `lib/length.ts`.
|
|
11
|
+
*/
|
|
12
|
+
import {} from '../lib/runner.js';
|
|
13
|
+
import { gradeOffenders, measureBudgets } from '../lib/length.js';
|
|
14
|
+
export const fileSize = {
|
|
15
|
+
name: 'file-size',
|
|
16
|
+
section: 'fileSize',
|
|
17
|
+
explain: `A large file usually means one file is doing several jobs. Step back:
|
|
18
|
+
• Name the distinct responsibilities — can each move to its own module
|
|
19
|
+
(one reason to change per file)?
|
|
20
|
+
• Pull pure helpers into a file that can be unit-tested on its own.
|
|
21
|
+
• Group the related files in a directory, but only if the split doesn't add
|
|
22
|
+
friction at the call sites.
|
|
23
|
+
If it's genuinely one responsibility that just runs long (a schema, a lookup
|
|
24
|
+
table, a table-driven test), give it a bigger budget or 'exempt' via
|
|
25
|
+
fileSize.overrides in nodeve.checks.js with a WHY comment. --warn downgrades
|
|
26
|
+
this to report-only.`,
|
|
27
|
+
run({ root, cfg, paths }) {
|
|
28
|
+
const offenders = measureBudgets(root, cfg, paths);
|
|
29
|
+
return gradeOffenders(offenders, {
|
|
30
|
+
fail: (n) => `${n} file(s) over the line budget`,
|
|
31
|
+
warn: (n) => `${n} file(s) over the soft budget — worth a look`,
|
|
32
|
+
pass: 'all files within budget',
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=file-size.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-size.js","sourceRoot":"","sources":["../../src/checks/file-size.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElE,MAAM,CAAC,MAAM,QAAQ,GAAsB;IAC1C,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,UAAU;IACnB,OAAO,EAAE;;;;;;;;;qBASW;IAEpB,GAAG,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE;QACvB,MAAM,SAAS,GAAG,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QACnD,OAAO,cAAc,CAAC,SAAS,EAAE;YAChC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,+BAA+B;YAChD,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,8CAA8C;YAC/D,IAAI,EAAE,yBAAyB;SAC/B,CAAC,CAAC;IACJ,CAAC;CACD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper-collisions.d.ts","sourceRoot":"","sources":["../../src/checks/helper-collisions.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAiD9C,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,kBAAkB,CAoDtD,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commit gate (advisory): flag a locally-declared function whose name fuzzily
|
|
3
|
+
* matches a dependency export — a likely reinvention of a lib function (e.g.
|
|
4
|
+
* local `clamp255` ≈ remeda `clamp`). Token-set matching catches transpositions
|
|
5
|
+
* like `byGroup`/`groupBy` where edit-distance fails.
|
|
6
|
+
*/
|
|
7
|
+
import { identifierSimilarityMatch } from '@nodeve/text/similarity';
|
|
8
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
import ts from 'typescript';
|
|
11
|
+
import { parseSource } from '../lib/ast.js';
|
|
12
|
+
import { tsSources } from '../lib/bin.js';
|
|
13
|
+
import {} from '../lib/config.js';
|
|
14
|
+
import {} from '../lib/runner.js';
|
|
15
|
+
function loadLibIndex(root, cfg) {
|
|
16
|
+
const path = join(root, cfg.libNamesPath);
|
|
17
|
+
// Missing index → no-op (clean), not a crash: a repo that hasn't run
|
|
18
|
+
// `nodeve-build-lib-names` yet shouldn't fail the commit on this advisory gate.
|
|
19
|
+
if (!existsSync(path))
|
|
20
|
+
return [];
|
|
21
|
+
const { names } = JSON.parse(readFileSync(path, 'utf8'));
|
|
22
|
+
return Object.entries(names).flatMap(([lib, list]) => list.map((name) => ({ lib, name })));
|
|
23
|
+
}
|
|
24
|
+
/** Top-level `function` / arrow-const declaration names in a source file. */
|
|
25
|
+
function declaredFunctionNames(absPath) {
|
|
26
|
+
const src = parseSource(absPath);
|
|
27
|
+
const out = [];
|
|
28
|
+
for (const stmt of src.statements) {
|
|
29
|
+
if (ts.isFunctionDeclaration(stmt) && stmt.name)
|
|
30
|
+
out.push(stmt.name.text);
|
|
31
|
+
else if (ts.isVariableStatement(stmt))
|
|
32
|
+
for (const d of stmt.declarationList.declarations)
|
|
33
|
+
if (ts.isIdentifier(d.name) &&
|
|
34
|
+
d.initializer &&
|
|
35
|
+
(ts.isArrowFunction(d.initializer) || ts.isFunctionExpression(d.initializer)))
|
|
36
|
+
out.push(d.name.text);
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
function bestMatch(name, libIndex, cfg) {
|
|
41
|
+
let best = null;
|
|
42
|
+
for (const lib of libIndex) {
|
|
43
|
+
const match = identifierSimilarityMatch(name, lib.name, {
|
|
44
|
+
keywords: cfg.libKeywords[lib.lib],
|
|
45
|
+
aliases: cfg.aliases[lib.name],
|
|
46
|
+
});
|
|
47
|
+
const matched = match.matchedAs === lib.name ? lib : { ...lib, matchedAs: match.matchedAs };
|
|
48
|
+
const score = match.score;
|
|
49
|
+
if (!best || score > best.score)
|
|
50
|
+
best = { lib: matched, score };
|
|
51
|
+
}
|
|
52
|
+
return best && best.score >= cfg.threshold ? best : null;
|
|
53
|
+
}
|
|
54
|
+
export const helperCollisions = {
|
|
55
|
+
name: 'helper-collisions',
|
|
56
|
+
section: 'helperCollisions',
|
|
57
|
+
explain: `A locally-declared function whose name fuzzily matches a dependency
|
|
58
|
+
export is a likely reinvention of a lib function. Routing a hit is a JUDGEMENT
|
|
59
|
+
call — resolve per case:
|
|
60
|
+
• delete the local and import the dependency export;
|
|
61
|
+
• wrap the lib (keep a project-specific name, delegate the body);
|
|
62
|
+
• rename the local for specificity if it genuinely does something different;
|
|
63
|
+
• or allowlist it as \`relPath::local→lib\`.
|
|
64
|
+
Matching is against the committed lib-names index (helperCollisions.libNamesPath);
|
|
65
|
+
regen with \`nodeve-build-lib-names\`. --warn downgrades this to report-only.`,
|
|
66
|
+
run({ root, cfg, paths, allowlist }) {
|
|
67
|
+
const libIndex = loadLibIndex(root, cfg);
|
|
68
|
+
const collisions = new Map();
|
|
69
|
+
for (const rel of tsSources(root, cfg.globs, paths)) {
|
|
70
|
+
const abs = join(root, rel);
|
|
71
|
+
for (const name of declaredFunctionNames(abs)) {
|
|
72
|
+
const m = bestMatch(name, libIndex, cfg);
|
|
73
|
+
if (!m)
|
|
74
|
+
continue;
|
|
75
|
+
const pairKey = `${name}→${m.lib.name}`;
|
|
76
|
+
if (allowlist.has(`${rel}::${pairKey}`))
|
|
77
|
+
continue;
|
|
78
|
+
const found = collisions.get(pairKey) ?? {
|
|
79
|
+
name,
|
|
80
|
+
lib: m.lib,
|
|
81
|
+
score: m.score,
|
|
82
|
+
files: new Set(),
|
|
83
|
+
};
|
|
84
|
+
found.files.add(rel);
|
|
85
|
+
collisions.set(pairKey, found);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const sorted = [...collisions.values()].sort((a, b) => b.score - a.score);
|
|
89
|
+
if (sorted.length === 0)
|
|
90
|
+
return { status: 'pass', summary: `clean (${libIndex.length} lib fns checked)` };
|
|
91
|
+
const rows = [];
|
|
92
|
+
for (const f of sorted) {
|
|
93
|
+
const matchedAs = f.lib.matchedAs ? ` (matched ${f.lib.matchedAs})` : '';
|
|
94
|
+
rows.push(`${f.score.toFixed(2)} ${f.name} ≈ ${f.lib.lib}.${f.lib.name}${matchedAs}`);
|
|
95
|
+
for (const file of f.files)
|
|
96
|
+
rows.push(` ${file}`);
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
status: 'fail',
|
|
100
|
+
summary: `${sorted.length} local function(s) may reinvent a dependency export`,
|
|
101
|
+
rows,
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=helper-collisions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper-collisions.js","sourceRoot":"","sources":["../../src/checks/helper-collisions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAc,MAAM,kBAAkB,CAAC;AAI9C,SAAS,YAAY,CAAC,IAAY,EAAE,GAA+B;IAClE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;IAC1C,qEAAqE;IACrE,gFAAgF;IAChF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IACjC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EA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AC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,GAAG,SAAS,EAAE,CAAC,CAAC;YACzF,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC,KAAK;gBAAE,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,OAAO;YACN,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,qDAAqD;YAC9E,IAAI;SACJ,CAAC;IACH,CAAC;CACD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-dupes.d.ts","sourceRoot":"","sources":["../../src/checks/inline-dupes.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAC;AA6B9C,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,aAAa,CA+C5C,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commit gate: flag a top-level name (non-exported const or function) that
|
|
3
|
+
* appears in 2+ tracked source files — a sign it should live in a shared
|
|
4
|
+
* package and be imported instead.
|
|
5
|
+
*
|
|
6
|
+
* Scope: `inlineDupes.globs` (default `apps/`, `packages/`). Note this always
|
|
7
|
+
* scans the full configured scope, not just staged files — a dupe is a
|
|
8
|
+
* relationship between two files, so the second file landing must see the first.
|
|
9
|
+
*/
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import ts from 'typescript';
|
|
12
|
+
import {} from '../lib/runner.js';
|
|
13
|
+
import { parseSource } from '../lib/ast.js';
|
|
14
|
+
import { tsSources } from '../lib/bin.js';
|
|
15
|
+
/**
|
|
16
|
+
* Non-exported top-level names in a source file: private `const` and
|
|
17
|
+
* `function` declarations. Exported names (SvelteKit `load`, `actions`,
|
|
18
|
+
* HTTP verbs, etc.) are skipped — they're legitimately repeated per route.
|
|
19
|
+
*/
|
|
20
|
+
function topLevelNames(absPath) {
|
|
21
|
+
const src = parseSource(absPath);
|
|
22
|
+
const out = [];
|
|
23
|
+
for (const stmt of src.statements) {
|
|
24
|
+
const isExported = ts.canHaveModifiers(stmt) &&
|
|
25
|
+
(ts.getModifiers(stmt)?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) ?? false);
|
|
26
|
+
if (isExported)
|
|
27
|
+
continue;
|
|
28
|
+
if (ts.isFunctionDeclaration(stmt) && stmt.name) {
|
|
29
|
+
out.push(stmt.name.text);
|
|
30
|
+
}
|
|
31
|
+
else if (ts.isVariableStatement(stmt)) {
|
|
32
|
+
for (const d of stmt.declarationList.declarations) {
|
|
33
|
+
if (ts.isIdentifier(d.name))
|
|
34
|
+
out.push(d.name.text);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
export const inlineDupes = {
|
|
41
|
+
name: 'inline-dupes',
|
|
42
|
+
section: 'inlineDupes',
|
|
43
|
+
explain: `A top-level name declared in 2+ files should live in a shared package
|
|
44
|
+
and be imported instead. Clear it by:
|
|
45
|
+
• a uniform SET of names recurring together (a shared prologue, the same
|
|
46
|
+
handful of locals) → extract them into one shared module and give the
|
|
47
|
+
bundle a TS type/interface, then import it (see lib/bin.ts#Gate);
|
|
48
|
+
• a single helper duplicated → move it to a shared package and import;
|
|
49
|
+
• a confirmed false positive → add the bare name to inlineDupes.allowlist
|
|
50
|
+
with a WHY comment.
|
|
51
|
+
--warn downgrades this to report-only.`,
|
|
52
|
+
run({ root, cfg, allowlist, explain }) {
|
|
53
|
+
const nameToFiles = new Map();
|
|
54
|
+
// paths ignored: always scan full scope (see header) regardless of staged files.
|
|
55
|
+
for (const rel of tsSources(root, cfg.globs)) {
|
|
56
|
+
const abs = join(root, rel);
|
|
57
|
+
for (const name of topLevelNames(abs)) {
|
|
58
|
+
if (allowlist.has(name))
|
|
59
|
+
continue;
|
|
60
|
+
const files = nameToFiles.get(name) ?? new Set();
|
|
61
|
+
files.add(rel);
|
|
62
|
+
nameToFiles.set(name, files);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const dupes = [...nameToFiles.entries()]
|
|
66
|
+
.filter(([, files]) => files.size >= 2)
|
|
67
|
+
.sort((a, b) => b[1].size - a[1].size || a[0].localeCompare(b[0]));
|
|
68
|
+
if (dupes.length === 0)
|
|
69
|
+
return { status: 'pass', summary: 'clean' };
|
|
70
|
+
// One row per duplicated name + its file count; the per-name file list is the
|
|
71
|
+
// bulk (a 30-name repo = hundreds of paths), so it only expands under
|
|
72
|
+
// --explain, which the failure's pointer advertises.
|
|
73
|
+
const rows = [];
|
|
74
|
+
for (const [name, files] of dupes) {
|
|
75
|
+
rows.push(`${name} (${files.size} files)`);
|
|
76
|
+
if (explain)
|
|
77
|
+
for (const file of files)
|
|
78
|
+
rows.push(` ${file}`);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
status: 'fail',
|
|
82
|
+
summary: `${dupes.length} name(s) declared in multiple files`,
|
|
83
|
+
rows,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=inline-dupes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-dupes.js","sourceRoot":"","sources":["../../src/checks/inline-dupes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C;;;;GAIG;AACH,SAAS,aAAa,CAAC,OAAe;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AAI,OAAO;gBAAE,KAAK,MAAM,IAAI,IAAI,KAAK;oBAAE,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,OAAO;YACN,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,GAAG,KAAK,CAAC,MAAM,qCAAqC;YAC7D,IAAI;SACJ,CAAC;IACH,CAAC;CACD,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commit gate: fail when a file matching one of `pageSize.overrides` exceeds that
|
|
3
|
+
* override's budget. Opt-in — the default scope (`globs`) is empty, so only files
|
|
4
|
+
* a configured override glob matches get a budget.
|
|
5
|
+
*
|
|
6
|
+
* WHY: an oversized template/module is a signal the unit is doing work that
|
|
7
|
+
* belongs in dedicated files — most often a SvelteKit `+page.svelte` with
|
|
8
|
+
* components defined inline that should be ripped out into their own files.
|
|
9
|
+
* Defaults to one override, `{ glob: '*+page.svelte', tiers: { fail: { maxLines:
|
|
10
|
+
* 280 } } }`; any glob → budget works, and a `warn` tier nudges before it blocks.
|
|
11
|
+
* Measure/classify is shared with file-size and doc-tokens in `lib/length.ts`.
|
|
12
|
+
*/
|
|
13
|
+
import { type Check } from '../lib/runner.js';
|
|
14
|
+
export declare const pageSize: Check<'pageSize'>;
|
|
15
|
+
//# sourceMappingURL=page-size.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-size.d.ts","sourceRoot":"","sources":["../../src/checks/page-size.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAG9C,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,UAAU,CAkBtC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commit gate: fail when a file matching one of `pageSize.overrides` exceeds that
|
|
3
|
+
* override's budget. Opt-in — the default scope (`globs`) is empty, so only files
|
|
4
|
+
* a configured override glob matches get a budget.
|
|
5
|
+
*
|
|
6
|
+
* WHY: an oversized template/module is a signal the unit is doing work that
|
|
7
|
+
* belongs in dedicated files — most often a SvelteKit `+page.svelte` with
|
|
8
|
+
* components defined inline that should be ripped out into their own files.
|
|
9
|
+
* Defaults to one override, `{ glob: '*+page.svelte', tiers: { fail: { maxLines:
|
|
10
|
+
* 280 } } }`; any glob → budget works, and a `warn` tier nudges before it blocks.
|
|
11
|
+
* Measure/classify is shared with file-size and doc-tokens in `lib/length.ts`.
|
|
12
|
+
*/
|
|
13
|
+
import {} from '../lib/runner.js';
|
|
14
|
+
import { gradeOffenders, measureBudgets } from '../lib/length.js';
|
|
15
|
+
export const pageSize = {
|
|
16
|
+
name: 'page-size',
|
|
17
|
+
section: 'pageSize',
|
|
18
|
+
explain: `An oversized template/module — most often a SvelteKit \`+page.svelte\` with
|
|
19
|
+
components defined inline — should rip those components out into their own
|
|
20
|
+
files. Configure the line budgets via \`pageSize.overrides\` in nodeve.checks.js.`,
|
|
21
|
+
run({ root, cfg, paths }) {
|
|
22
|
+
if (cfg.globs.length === 0 && (cfg.overrides?.length ?? 0) === 0)
|
|
23
|
+
return { status: 'pass', summary: 'no rules configured' };
|
|
24
|
+
const offenders = measureBudgets(root, cfg, paths);
|
|
25
|
+
return gradeOffenders(offenders, {
|
|
26
|
+
fail: (n) => `${n} file(s) over line budget — rip inline components out into their own files`,
|
|
27
|
+
warn: (n) => `${n} file(s) approaching the line budget`,
|
|
28
|
+
pass: 'all files within budget',
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=page-size.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-size.js","sourceRoot":"","sources":["../../src/checks/page-size.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElE,MAAM,CAAC,MAAM,QAAQ,GAAsB;IAC1C,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,UAAU;IACnB,OAAO,EAAE;;kFAEwE;IAEjF,GAAG,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE;QACvB,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC;YAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,EAAE,CAAC;QAE3D,MAAM,SAAS,GAAG,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QACnD,OAAO,cAAc,CAAC,SAAS,EAAE;YAChC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,4EAA4E;YAC7F,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,sCAAsC;YACvD,IAAI,EAAE,yBAAyB;SAC/B,CAAC,CAAC;IACJ,CAAC;CACD,CAAC"}
|