@crown3/repo-doctor 0.0.0 → 0.2.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/LICENSE +7 -0
- package/README.md +40 -1
- package/UPSTREAM.md +20 -0
- package/bin/repo-doctor.mjs +9 -0
- package/dist/check-comments.d.ts +3 -0
- package/dist/check-docs.d.ts +16 -0
- package/dist/check-runs.d.ts +23 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.js +1743 -0
- package/dist/comments.d.ts +17 -0
- package/dist/config.d.ts +152 -0
- package/dist/file-kinds.d.ts +8 -0
- package/dist/files.d.ts +8 -0
- package/dist/format-sh.d.ts +6 -0
- package/dist/g.js +360 -0
- package/dist/git.d.ts +17 -0
- package/dist/go-comments.d.ts +7 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +16 -0
- package/dist/python.d.ts +18 -0
- package/dist/quality.d.ts +39 -0
- package/dist/review-comments.d.ts +14 -0
- package/dist/rules.d.ts +8 -0
- package/dist/run-if-main.d.ts +2 -0
- package/dist/scrub-git-hook-env.d.ts +1 -0
- package/dist/scrub-git-hook-env.js +2 -0
- package/dist/settings.d.ts +19 -0
- package/dist/shard.d.ts +10 -0
- package/dist/sites.d.ts +9 -0
- package/dist/units.d.ts +30 -0
- package/package.json +61 -3
- package/python/crapper/LICENSE +7 -0
- package/python/crapper/README.md +93 -0
- package/python/crapper/pyproject.toml +28 -0
- package/python/crapper/src/crapper/__init__.py +3 -0
- package/python/crapper/src/crapper/__main__.py +4 -0
- package/python/crapper/src/crapper/analyze.py +56 -0
- package/python/crapper/src/crapper/cli.py +334 -0
- package/python/crapper/src/crapper/coverage.py +596 -0
- package/python/crapper/src/crapper/crap.py +47 -0
- package/python/crapper/src/crapper/discover.py +116 -0
- package/python/crapper/src/crapper/languages/__init__.py +27 -0
- package/python/crapper/src/crapper/languages/clojure.py +451 -0
- package/python/crapper/src/crapper/languages/golang.py +143 -0
- package/python/crapper/src/crapper/languages/java.py +117 -0
- package/python/crapper/src/crapper/languages/python.py +133 -0
- package/python/crapper/src/crapper/languages/rust.py +190 -0
- package/python/crapper/src/crapper/languages/treesitter.py +82 -0
- package/python/crapper/src/crapper/languages/typescript.py +399 -0
- package/python/crapper/src/crapper/metrics.py +59 -0
- package/python/crapper/src/crapper/model.py +32 -0
- package/python/crapper/src/crapper/report.py +42 -0
- package/python/crapper/src/crapper/runners.py +596 -0
- package/python/dryer/LICENSE +7 -0
- package/python/dryer/README.md +115 -0
- package/python/dryer/pyproject.toml +29 -0
- package/python/dryer/src/dryer/__init__.py +3 -0
- package/python/dryer/src/dryer/__main__.py +4 -0
- package/python/dryer/src/dryer/astnorm.py +391 -0
- package/python/dryer/src/dryer/cli.py +324 -0
- package/python/dryer/src/dryer/clojure_read.py +519 -0
- package/python/dryer/src/dryer/discover.py +121 -0
- package/python/dryer/src/dryer/extract.py +204 -0
- package/python/dryer/src/dryer/model.py +34 -0
- package/python/dryer/src/dryer/report.py +74 -0
- package/python/dryer/src/dryer/scan.py +91 -0
- package/python/dryer/src/dryer/shape.py +108 -0
- package/python/dryer/src/dryer/treesitter.py +47 -0
- package/python/mutator/LICENSE +7 -0
- package/python/mutator/README.md +123 -0
- package/python/mutator/pyproject.toml +28 -0
- package/python/mutator/src/mutator/__init__.py +3 -0
- package/python/mutator/src/mutator/__main__.py +4 -0
- package/python/mutator/src/mutator/cli.py +591 -0
- package/python/mutator/src/mutator/coverage.py +233 -0
- package/python/mutator/src/mutator/crapper_link.py +36 -0
- package/python/mutator/src/mutator/edn.py +239 -0
- package/python/mutator/src/mutator/engine.py +356 -0
- package/python/mutator/src/mutator/functions.py +214 -0
- package/python/mutator/src/mutator/metrics.py +344 -0
- package/python/mutator/src/mutator/model.py +83 -0
- package/python/mutator/src/mutator/report.py +74 -0
- package/python/mutator/src/mutator/runner.py +248 -0
- package/python/mutator/src/mutator/sites.py +376 -0
- package/python/mutator/src/mutator/workers.py +446 -0
- package/python/requirements.lock +12 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** One comment of a source file. */
|
|
2
|
+
export interface Comment {
|
|
3
|
+
line: number;
|
|
4
|
+
text: string;
|
|
5
|
+
/** An own-line comment, which can continue an external(...) comment on the line above. */
|
|
6
|
+
chains: boolean;
|
|
7
|
+
/** A tool directive: biome-ignore, shellcheck, a triple-slash reference, `//go:`, `//nolint:`. */
|
|
8
|
+
directive: boolean;
|
|
9
|
+
/** A JSDoc block on an exported declaration of a public API. */
|
|
10
|
+
publicDoc: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** The lines that hold an external(...) comment or one of its own-line continuations. */
|
|
13
|
+
export declare function externalLines(comments: Comment[]): Set<number>;
|
|
14
|
+
/** The comments of a script, shell or Go file; undefined for a file of another kind. */
|
|
15
|
+
export declare function commentsOf(file: string, source: string, publicApi: boolean): Comment[] | undefined;
|
|
16
|
+
/** The lines of the comments the policy does not allow; none in a generated file. */
|
|
17
|
+
export declare function disallowedLines(file: string, source: string, publicApi?: boolean): number[];
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/** What a coverage or test command option sees about the unit it is for. */
|
|
2
|
+
export interface UnitInfo {
|
|
3
|
+
dir: string;
|
|
4
|
+
/** package.json scripts, when the unit has a package.json. */
|
|
5
|
+
scripts?: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
/** A shell command, or a function choosing one per unit; undefined keeps the default. */
|
|
8
|
+
export type CommandOption = string | ((unit: UnitInfo) => string | undefined);
|
|
9
|
+
/** crap settings. */
|
|
10
|
+
export interface CrapConfig {
|
|
11
|
+
/** crapper fails a function at or above this CRAP. Default 10. */
|
|
12
|
+
threshold?: number;
|
|
13
|
+
}
|
|
14
|
+
/** mutate settings. */
|
|
15
|
+
export interface MutateConfig {
|
|
16
|
+
/** mutate passes a unit scoring at least this percent; --min-score overrides it. Default: every mutant must die. */
|
|
17
|
+
minScore?: number;
|
|
18
|
+
}
|
|
19
|
+
/** dry settings; dryer runs over every unit at once. */
|
|
20
|
+
export interface DryConfig {
|
|
21
|
+
/** Similarity at which dryer reports a duplicate. Default 0.8. */
|
|
22
|
+
threshold?: number;
|
|
23
|
+
/** Whether dryer also reads tests. Default true. */
|
|
24
|
+
includeTests?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** The settings a repo can give one unit, or every unit in `quality`. */
|
|
27
|
+
export interface UnitConfig {
|
|
28
|
+
/** Directories, relative to the unit, whose code is checked. Default: the whole unit. */
|
|
29
|
+
paths?: string[];
|
|
30
|
+
/** Globs, relative to the repo root, of files no quality command reads. */
|
|
31
|
+
exclude?: string[];
|
|
32
|
+
/**
|
|
33
|
+
* Writes the coverage crapper and mutator read. Default: the unit's `coverage` script, else
|
|
34
|
+
* the tool's own command for the language.
|
|
35
|
+
*/
|
|
36
|
+
coverage?: CommandOption;
|
|
37
|
+
/**
|
|
38
|
+
* Runs the tests each mutant is checked against. Default: the unit's `test` script, else the
|
|
39
|
+
* tool's own command for the language.
|
|
40
|
+
*/
|
|
41
|
+
test?: CommandOption;
|
|
42
|
+
crap?: CrapConfig;
|
|
43
|
+
mutate?: MutateConfig;
|
|
44
|
+
}
|
|
45
|
+
/** crap, dry, mutate and ratio. */
|
|
46
|
+
export interface QualityConfig extends UnitConfig {
|
|
47
|
+
/**
|
|
48
|
+
* Per-directory unit settings; false leaves a directory's files unchecked (no parent unit takes
|
|
49
|
+
* them). A directory named here is a unit even when it is not a workspace.
|
|
50
|
+
*/
|
|
51
|
+
units?: Record<string, UnitConfig | false>;
|
|
52
|
+
dry?: DryConfig;
|
|
53
|
+
}
|
|
54
|
+
/** Which CI system's pipeline files check-runs reads. */
|
|
55
|
+
export type Platform = 'github' | 'codebase';
|
|
56
|
+
/** The CI pipelines check-runs reads, and what a step in them may run. */
|
|
57
|
+
export interface CiConfig {
|
|
58
|
+
platform: Platform;
|
|
59
|
+
/** Pipeline files, or globs, relative to the repo root. */
|
|
60
|
+
files: string[];
|
|
61
|
+
/**
|
|
62
|
+
* A CI command passes when it matches; its one capture group names the package.json script.
|
|
63
|
+
* No g or y flag. Default for github `/^pnpm (\S+)[^\n]*$/`; required for codebase.
|
|
64
|
+
*/
|
|
65
|
+
entry?: RegExp;
|
|
66
|
+
/** Whole commands a step may run as they are, outside the script check; each matches as `^(?:source)$`. */
|
|
67
|
+
allow?: RegExp[];
|
|
68
|
+
/** How a failing CI step should be written instead, in the error message. Default: derived from entry. */
|
|
69
|
+
hint?: string;
|
|
70
|
+
}
|
|
71
|
+
/** check-runs: hooks and CI call only package.json scripts, and, with a table, the docs table says where. */
|
|
72
|
+
export interface PipelinesConfig {
|
|
73
|
+
/** The hk config, relative to the repo root. Default `hk.pkl`. */
|
|
74
|
+
hooks?: string;
|
|
75
|
+
/** The page with the "## Where checks run" table. Omitted: no table is kept in sync. */
|
|
76
|
+
table?: string;
|
|
77
|
+
ci?: CiConfig;
|
|
78
|
+
}
|
|
79
|
+
/** Where AGENTS.md and CLAUDE.md may sit besides the repo root and skill trees. */
|
|
80
|
+
export type AgentFiles = 'root' | 'workspaces' | 'anywhere';
|
|
81
|
+
/** check-comments and review-comments. */
|
|
82
|
+
export interface CommentsConfig {
|
|
83
|
+
/** Globs, relative to the repo root, of files check-comments skips besides `node_modules/` and `fixtures/`. */
|
|
84
|
+
exclude?: string[];
|
|
85
|
+
/** Directory prefixes whose exported declarations may carry JSDoc, besides the `src/` of every package under `packages/` not marked private. */
|
|
86
|
+
publicApi?: string[];
|
|
87
|
+
}
|
|
88
|
+
/** check-docs. */
|
|
89
|
+
export interface DocsConfig {
|
|
90
|
+
/** Directories walked for Markdown besides `docs/`; their files are link- and overlap-checked only. */
|
|
91
|
+
dirs?: string[];
|
|
92
|
+
/** Also read each workspace's AGENTS.md, GLOSSARY.md, README.md and docs/. Default false. */
|
|
93
|
+
workspaceDocs?: boolean;
|
|
94
|
+
/** Default `root`: only the repo root and skill trees. `workspaces` also allows a workspace root; `anywhere` turns the check off. */
|
|
95
|
+
agentFiles?: AgentFiles;
|
|
96
|
+
/** Directories no doc may link into, such as archives the docs check does not read. */
|
|
97
|
+
noLinksInto?: string[];
|
|
98
|
+
/** Directory names the walks skip, besides the built-in build and cache directories. */
|
|
99
|
+
skip?: string[];
|
|
100
|
+
}
|
|
101
|
+
/** The config a repo writes in repo-doctor.config.mjs. */
|
|
102
|
+
export interface Config {
|
|
103
|
+
/** The ref review-comments diffs against when none is given. Default `origin/main`. */
|
|
104
|
+
baseRef?: string;
|
|
105
|
+
/** Globs of workspace directories. Default: discovered from the pnpm, npm, go.work and Cargo workspace files. */
|
|
106
|
+
workspaces?: string[];
|
|
107
|
+
/** Globs, relative to the repo root, of files no check reads. */
|
|
108
|
+
exclude?: string[];
|
|
109
|
+
comments?: false | CommentsConfig;
|
|
110
|
+
docs?: false | DocsConfig;
|
|
111
|
+
/** Omit, or false, to leave check-runs off. */
|
|
112
|
+
pipelines?: false | PipelinesConfig;
|
|
113
|
+
quality?: false | QualityConfig;
|
|
114
|
+
}
|
|
115
|
+
/** Identity, so a config module gets type checking: `export default defineConfig({ ... })`. */
|
|
116
|
+
export declare const defineConfig: (config: Config) => Config;
|
|
117
|
+
export declare class ConfigError extends Error {
|
|
118
|
+
}
|
|
119
|
+
export interface Comments {
|
|
120
|
+
exclude: string[];
|
|
121
|
+
publicApi: string[];
|
|
122
|
+
}
|
|
123
|
+
export interface Docs {
|
|
124
|
+
dirs: string[];
|
|
125
|
+
workspaceDocs: boolean;
|
|
126
|
+
agentFiles: AgentFiles;
|
|
127
|
+
noLinksInto: string[];
|
|
128
|
+
skip: string[];
|
|
129
|
+
}
|
|
130
|
+
export interface Ci {
|
|
131
|
+
platform: Platform;
|
|
132
|
+
files: string[];
|
|
133
|
+
entry: RegExp;
|
|
134
|
+
allow: RegExp[];
|
|
135
|
+
hint: string;
|
|
136
|
+
}
|
|
137
|
+
export interface Pipelines {
|
|
138
|
+
hooks: string;
|
|
139
|
+
table: string | undefined;
|
|
140
|
+
ci: Ci | undefined;
|
|
141
|
+
}
|
|
142
|
+
export interface Checked {
|
|
143
|
+
baseRef: string;
|
|
144
|
+
workspaces?: string[];
|
|
145
|
+
exclude: string[];
|
|
146
|
+
comments: false | Comments;
|
|
147
|
+
docs: false | Docs;
|
|
148
|
+
pipelines: false | Pipelines;
|
|
149
|
+
quality: false | QualityConfig;
|
|
150
|
+
}
|
|
151
|
+
/** Checks a loaded config, naming the key path of anything wrong, and fills the defaults that need no repo. */
|
|
152
|
+
export declare function check(config?: unknown): Checked;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Unit } from './units.js';
|
|
2
|
+
export type Kind = 'source' | 'test';
|
|
3
|
+
export declare function kind(file: string): Kind | undefined;
|
|
4
|
+
export declare function owner(units: Unit[], file: string): Unit | undefined;
|
|
5
|
+
export declare const excluded: (unit: Unit, file: string) => boolean;
|
|
6
|
+
export declare const local: (unit: Unit, file: string) => string;
|
|
7
|
+
export declare function selects(units: Unit[], unit: Unit, file: string): boolean;
|
|
8
|
+
export declare const isScript: (file: string) => boolean;
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** A `.sh` file, or an extensionless one whose first line is a sh or bash shebang. */
|
|
2
|
+
export declare function isShell(file: string, firstLine: string): boolean;
|
|
3
|
+
/** Whether a glob matches file, a `<dir>/**` glob taking every file under a matching directory, dotfiles too. */
|
|
4
|
+
export declare const matchesAny: (file: string, globs: string[]) => boolean;
|
|
5
|
+
/** Every file git does not ignore, tracked or new, relative to the repo root. */
|
|
6
|
+
export declare const repoFiles: (root: string) => string[];
|
|
7
|
+
/** During a merge, drops the files that arrive unchanged from the merged branch; otherwise returns files as given. */
|
|
8
|
+
export declare function ownChanges(root: string, files: string[]): string[];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface FormatResult {
|
|
2
|
+
changed: string[];
|
|
3
|
+
errors: string[];
|
|
4
|
+
}
|
|
5
|
+
/** Runs shfmt on the shell files among files: lists those it would change, and rewrites them with write. */
|
|
6
|
+
export declare function formatFiles(root: string, files: string[], write: boolean): FormatResult;
|
package/dist/g.js
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import node_path from "node:path";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import * as __rspack_external_node_fs_1b05aee1 from "node:fs";
|
|
4
|
+
const defineConfig = (config)=>config;
|
|
5
|
+
class ConfigError extends Error {
|
|
6
|
+
}
|
|
7
|
+
const isString = (v)=>'string' == typeof v;
|
|
8
|
+
const isPercent = (v)=>'number' == typeof v && Number.isInteger(v) && v >= 0 && v <= 100;
|
|
9
|
+
const STRING = {
|
|
10
|
+
ok: isString,
|
|
11
|
+
what: 'a string'
|
|
12
|
+
};
|
|
13
|
+
const STRINGS = {
|
|
14
|
+
ok: (v)=>Array.isArray(v) && v.every(isString),
|
|
15
|
+
what: 'a list of strings'
|
|
16
|
+
};
|
|
17
|
+
const BOOLEAN = {
|
|
18
|
+
ok: (v)=>'boolean' == typeof v,
|
|
19
|
+
what: 'true or false'
|
|
20
|
+
};
|
|
21
|
+
const NUMBER = {
|
|
22
|
+
ok: (v)=>'number' == typeof v && Number.isFinite(v) && v > 0,
|
|
23
|
+
what: 'a positive number'
|
|
24
|
+
};
|
|
25
|
+
const PERCENT = {
|
|
26
|
+
ok: isPercent,
|
|
27
|
+
what: 'an integer 0-100'
|
|
28
|
+
};
|
|
29
|
+
const REGEXP = {
|
|
30
|
+
ok: (v)=>v instanceof RegExp,
|
|
31
|
+
what: 'a RegExp'
|
|
32
|
+
};
|
|
33
|
+
const COMMAND = {
|
|
34
|
+
ok: (v)=>isString(v) || 'function' == typeof v,
|
|
35
|
+
what: 'a string or a function'
|
|
36
|
+
};
|
|
37
|
+
const REGEXPS = {
|
|
38
|
+
ok: (v)=>Array.isArray(v) && v.every((r)=>r instanceof RegExp),
|
|
39
|
+
what: 'a list of RegExps'
|
|
40
|
+
};
|
|
41
|
+
const oneOf = (...values)=>({
|
|
42
|
+
ok: (v)=>values.includes(v),
|
|
43
|
+
what: values.map((v)=>JSON.stringify(v)).join(' or ')
|
|
44
|
+
});
|
|
45
|
+
const join = (at, key)=>at ? `${at}.${key}` : key;
|
|
46
|
+
function object(value, at, keys) {
|
|
47
|
+
if ('object' != typeof value || null === value || Array.isArray(value)) throw new ConfigError(`${at || 'the config'} must be an object`);
|
|
48
|
+
const unknown = keys && Object.keys(value).find((k)=>!keys.includes(k));
|
|
49
|
+
if (void 0 !== unknown) throw new ConfigError(`${join(at, unknown)} is not a config key`);
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
function field(raw, at, key, rule, fallback) {
|
|
53
|
+
const value = raw[key];
|
|
54
|
+
if (void 0 === value) return fallback;
|
|
55
|
+
if (!rule.ok(value)) throw new ConfigError(`${join(at, key)} must be ${rule.what}, got ${shown(value)}`);
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
function shown(value) {
|
|
59
|
+
if ('function' == typeof value) return 'a function';
|
|
60
|
+
if (value instanceof RegExp) return String(value);
|
|
61
|
+
return JSON.stringify(value) ?? String(value);
|
|
62
|
+
}
|
|
63
|
+
function section(raw, key, absent, parse) {
|
|
64
|
+
const value = raw[key];
|
|
65
|
+
if (false === value) return false;
|
|
66
|
+
if (void 0 === value) return false === absent ? false : parse({}, key);
|
|
67
|
+
return parse(value, key);
|
|
68
|
+
}
|
|
69
|
+
function comments(value, at) {
|
|
70
|
+
const raw = object(value, at, [
|
|
71
|
+
'exclude',
|
|
72
|
+
'publicApi'
|
|
73
|
+
]);
|
|
74
|
+
return {
|
|
75
|
+
exclude: field(raw, at, 'exclude', STRINGS, []),
|
|
76
|
+
publicApi: field(raw, at, 'publicApi', STRINGS, [])
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function docs(value, at) {
|
|
80
|
+
const raw = object(value, at, [
|
|
81
|
+
'dirs',
|
|
82
|
+
'workspaceDocs',
|
|
83
|
+
'agentFiles',
|
|
84
|
+
'noLinksInto',
|
|
85
|
+
'skip'
|
|
86
|
+
]);
|
|
87
|
+
return {
|
|
88
|
+
dirs: field(raw, at, 'dirs', STRINGS, []),
|
|
89
|
+
workspaceDocs: field(raw, at, 'workspaceDocs', BOOLEAN, false),
|
|
90
|
+
agentFiles: field(raw, at, 'agentFiles', oneOf('root', 'workspaces', 'anywhere'), 'root'),
|
|
91
|
+
noLinksInto: field(raw, at, 'noLinksInto', STRINGS, []),
|
|
92
|
+
skip: field(raw, at, 'skip', STRINGS, [])
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const GITHUB_ENTRY = /^pnpm (\S+)[^\n]*$/;
|
|
96
|
+
const GITHUB_HINT = "call a package.json script instead, or move setup into .github/actions/setup";
|
|
97
|
+
const REMOVED = {
|
|
98
|
+
runner: "match the CI command with pipelines.ci.entry, whose one capture group names the package.json script",
|
|
99
|
+
setup: 'list whole setup commands in pipelines.ci.allow'
|
|
100
|
+
};
|
|
101
|
+
function required(raw, at, key, rule) {
|
|
102
|
+
const value = field(raw, at, key, rule, void 0);
|
|
103
|
+
if (void 0 === value) throw new ConfigError(`${at}.${key} is required`);
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
function plain(pattern, at) {
|
|
107
|
+
if (/[gy]/.test(pattern.flags)) throw new ConfigError(`${at} must not have the g or y flag, got ${pattern}`);
|
|
108
|
+
return pattern;
|
|
109
|
+
}
|
|
110
|
+
const groups = (pattern)=>(new RegExp(`${pattern.source}|`, pattern.flags).exec('')?.length ?? 1) - 1;
|
|
111
|
+
function entryOf(raw, at, platform) {
|
|
112
|
+
const entry = field(raw, at, 'entry', REGEXP, void 0);
|
|
113
|
+
if (void 0 === entry && 'github' === platform) return GITHUB_ENTRY;
|
|
114
|
+
if (void 0 === entry) throw new ConfigError(`${at}.entry is required for platform "codebase"`);
|
|
115
|
+
plain(entry, `${at}.entry`);
|
|
116
|
+
const count = groups(entry);
|
|
117
|
+
if (1 !== count) throw new ConfigError(`${at}.entry must have exactly one capture group, the package.json script name; ${entry} has ${count}`);
|
|
118
|
+
return entry;
|
|
119
|
+
}
|
|
120
|
+
const allowOf = (raw, at)=>field(raw, at, 'allow', REGEXPS, []).map((pattern, i)=>new RegExp(`^(?:${plain(pattern, `${at}.allow[${i}]`).source})$`, pattern.flags));
|
|
121
|
+
function ci(value, at) {
|
|
122
|
+
if (void 0 === value) return;
|
|
123
|
+
const given = object(value, at);
|
|
124
|
+
const gone = Object.keys(REMOVED).find((key)=>key in given);
|
|
125
|
+
if (void 0 !== gone) throw new ConfigError(`${at}.${gone} was removed in 0.2.0: ${REMOVED[gone]}`);
|
|
126
|
+
const raw = object(value, at, [
|
|
127
|
+
'platform',
|
|
128
|
+
'files',
|
|
129
|
+
'entry',
|
|
130
|
+
'allow',
|
|
131
|
+
'hint'
|
|
132
|
+
]);
|
|
133
|
+
const platform = required(raw, at, 'platform', oneOf('github', 'codebase'));
|
|
134
|
+
const files = required(raw, at, 'files', STRINGS);
|
|
135
|
+
const entry = entryOf(raw, at, platform);
|
|
136
|
+
const fallback = void 0 === raw.entry ? GITHUB_HINT : `call a package.json script with a command pipelines.ci.entry matches: ${entry}`;
|
|
137
|
+
const hint = field(raw, at, 'hint', STRING, fallback);
|
|
138
|
+
return {
|
|
139
|
+
platform,
|
|
140
|
+
files,
|
|
141
|
+
entry,
|
|
142
|
+
allow: allowOf(raw, at),
|
|
143
|
+
hint
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function pipelines(value, at) {
|
|
147
|
+
const raw = object(value, at, [
|
|
148
|
+
'hooks',
|
|
149
|
+
'table',
|
|
150
|
+
'ci'
|
|
151
|
+
]);
|
|
152
|
+
return {
|
|
153
|
+
hooks: field(raw, at, 'hooks', STRING, 'hk.pkl'),
|
|
154
|
+
table: field(raw, at, 'table', STRING, void 0),
|
|
155
|
+
ci: ci(raw.ci, `${at}.ci`)
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const UNIT_KEYS = [
|
|
159
|
+
'paths',
|
|
160
|
+
'exclude',
|
|
161
|
+
'coverage',
|
|
162
|
+
'test',
|
|
163
|
+
'crap',
|
|
164
|
+
'mutate'
|
|
165
|
+
];
|
|
166
|
+
function nested(raw, at, key, rules) {
|
|
167
|
+
if (void 0 === raw[key]) return;
|
|
168
|
+
const own = object(raw[key], join(at, key), Object.keys(rules));
|
|
169
|
+
for (const [name, rule] of Object.entries(rules))field(own, join(at, key), name, rule, void 0);
|
|
170
|
+
}
|
|
171
|
+
function unitConfig(raw, at) {
|
|
172
|
+
field(raw, at, 'paths', STRINGS, void 0);
|
|
173
|
+
field(raw, at, 'exclude', STRINGS, void 0);
|
|
174
|
+
field(raw, at, 'coverage', COMMAND, void 0);
|
|
175
|
+
field(raw, at, 'test', COMMAND, void 0);
|
|
176
|
+
nested(raw, at, 'crap', {
|
|
177
|
+
threshold: NUMBER
|
|
178
|
+
});
|
|
179
|
+
nested(raw, at, 'mutate', {
|
|
180
|
+
minScore: PERCENT
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function quality(value, at) {
|
|
184
|
+
const raw = object(value, at, [
|
|
185
|
+
...UNIT_KEYS,
|
|
186
|
+
'units',
|
|
187
|
+
'dry'
|
|
188
|
+
]);
|
|
189
|
+
unitConfig(raw, at);
|
|
190
|
+
nested(raw, at, 'dry', {
|
|
191
|
+
threshold: NUMBER,
|
|
192
|
+
includeTests: BOOLEAN
|
|
193
|
+
});
|
|
194
|
+
const units = void 0 === raw.units ? {} : object(raw.units, `${at}.units`);
|
|
195
|
+
for (const [dir, unit] of Object.entries(units)){
|
|
196
|
+
if (false === unit) continue;
|
|
197
|
+
const where = `${at}.units[${JSON.stringify(dir)}]`;
|
|
198
|
+
unitConfig(object(unit, where, UNIT_KEYS), where);
|
|
199
|
+
}
|
|
200
|
+
return raw;
|
|
201
|
+
}
|
|
202
|
+
function check(config = {}) {
|
|
203
|
+
const raw = object(config, '', [
|
|
204
|
+
'baseRef',
|
|
205
|
+
'workspaces',
|
|
206
|
+
'exclude',
|
|
207
|
+
'comments',
|
|
208
|
+
'docs',
|
|
209
|
+
'pipelines',
|
|
210
|
+
'quality'
|
|
211
|
+
]);
|
|
212
|
+
return {
|
|
213
|
+
baseRef: field(raw, '', 'baseRef', STRING, 'origin/main'),
|
|
214
|
+
workspaces: field(raw, '', 'workspaces', STRINGS, void 0),
|
|
215
|
+
exclude: field(raw, '', 'exclude', STRINGS, []),
|
|
216
|
+
comments: section(raw, 'comments', 'on', comments),
|
|
217
|
+
docs: section(raw, 'docs', 'on', docs),
|
|
218
|
+
pipelines: section(raw, 'pipelines', false, pipelines),
|
|
219
|
+
quality: section(raw, 'quality', 'on', quality)
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function withoutGitHookEnv(env = process.env) {
|
|
223
|
+
return Object.fromEntries(Object.entries(env).filter(([k])=>!k.startsWith('GIT_')));
|
|
224
|
+
}
|
|
225
|
+
function git(root, args, { hookEnv = false } = {}) {
|
|
226
|
+
try {
|
|
227
|
+
return execFileSync('git', [
|
|
228
|
+
'-c',
|
|
229
|
+
'core.quotePath=false',
|
|
230
|
+
...args
|
|
231
|
+
], {
|
|
232
|
+
cwd: root,
|
|
233
|
+
env: hookEnv ? process.env : withoutGitHookEnv(),
|
|
234
|
+
encoding: 'utf8',
|
|
235
|
+
stdio: [
|
|
236
|
+
'ignore',
|
|
237
|
+
'pipe',
|
|
238
|
+
'pipe'
|
|
239
|
+
],
|
|
240
|
+
maxBuffer: 1073741824
|
|
241
|
+
});
|
|
242
|
+
} catch (error) {
|
|
243
|
+
const { stderr, message } = error;
|
|
244
|
+
const why = stderr?.trim().split('\n')[0] || message.split('\n')[0];
|
|
245
|
+
throw new Error(`git ${args.join(' ')}: ${why}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const gitLines = (root, args, options)=>git(root, args, options).split('\n').filter(Boolean);
|
|
249
|
+
const since = (root, base)=>base ? gitLines(root, [
|
|
250
|
+
'merge-base',
|
|
251
|
+
base,
|
|
252
|
+
'HEAD'
|
|
253
|
+
])[0] ?? base : 'HEAD';
|
|
254
|
+
const untracked = (root)=>gitLines(root, [
|
|
255
|
+
'ls-files',
|
|
256
|
+
'--others',
|
|
257
|
+
'--exclude-standard'
|
|
258
|
+
]);
|
|
259
|
+
function listFiles(root, { changed, base }) {
|
|
260
|
+
const files = changed ? [
|
|
261
|
+
...gitLines(root, [
|
|
262
|
+
'diff',
|
|
263
|
+
'--name-only',
|
|
264
|
+
'--diff-filter=AMR',
|
|
265
|
+
since(root, base)
|
|
266
|
+
]),
|
|
267
|
+
...untracked(root)
|
|
268
|
+
] : gitLines(root, [
|
|
269
|
+
'ls-files',
|
|
270
|
+
'--cached',
|
|
271
|
+
'--others',
|
|
272
|
+
'--exclude-standard'
|
|
273
|
+
]);
|
|
274
|
+
return [
|
|
275
|
+
...new Set(files)
|
|
276
|
+
].filter((f)=>__rspack_external_node_fs_1b05aee1.existsSync(node_path.join(root, f))).sort();
|
|
277
|
+
}
|
|
278
|
+
const HUNK = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/;
|
|
279
|
+
function addedLines(diff) {
|
|
280
|
+
const lines = new Map();
|
|
281
|
+
let added;
|
|
282
|
+
for (const line of diff){
|
|
283
|
+
if (line.startsWith('+++ ')) {
|
|
284
|
+
added = new Set();
|
|
285
|
+
lines.set(line.slice(4), added);
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
const hunk = HUNK.exec(line);
|
|
289
|
+
if (!hunk || !added) continue;
|
|
290
|
+
const start = Number(hunk[1]);
|
|
291
|
+
const size = void 0 === hunk[2] ? 1 : Number(hunk[2]);
|
|
292
|
+
for(let n = start; n < start + size; n++)added.add(n);
|
|
293
|
+
}
|
|
294
|
+
return lines;
|
|
295
|
+
}
|
|
296
|
+
function changedLines(root, { base }) {
|
|
297
|
+
const lines = addedLines(gitLines(root, [
|
|
298
|
+
'diff',
|
|
299
|
+
'-U0',
|
|
300
|
+
'--no-color',
|
|
301
|
+
'--no-prefix',
|
|
302
|
+
since(root, base)
|
|
303
|
+
]));
|
|
304
|
+
const fresh = new Set(untracked(root));
|
|
305
|
+
return (file, line)=>fresh.has(file) || (lines.get(file)?.has(line) ?? false);
|
|
306
|
+
}
|
|
307
|
+
const repoRoot = (cwd)=>gitLines(cwd, [
|
|
308
|
+
'rev-parse',
|
|
309
|
+
'--show-toplevel'
|
|
310
|
+
])[0] ?? cwd;
|
|
311
|
+
const SHEBANG = /^#!.*\b(?:ba)?sh(?:\s|$)/;
|
|
312
|
+
function isShell(file, firstLine) {
|
|
313
|
+
if (file.endsWith('.sh')) return true;
|
|
314
|
+
return '' === node_path.extname(file) && SHEBANG.test(firstLine);
|
|
315
|
+
}
|
|
316
|
+
const HOOK = {
|
|
317
|
+
hookEnv: true
|
|
318
|
+
};
|
|
319
|
+
const files_lines = (out)=>out.split('\n').filter(Boolean);
|
|
320
|
+
function matches(file, glob) {
|
|
321
|
+
if (node_path.matchesGlob(file, glob)) return true;
|
|
322
|
+
if (!glob.endsWith('/**')) return false;
|
|
323
|
+
const dir = glob.slice(0, -3);
|
|
324
|
+
const parts = file.split('/');
|
|
325
|
+
return parts.slice(1).some((_, i)=>node_path.matchesGlob(parts.slice(0, i + 1).join('/'), dir));
|
|
326
|
+
}
|
|
327
|
+
const matchesAny = (file, globs)=>globs.some((glob)=>matches(file, glob));
|
|
328
|
+
const repoFiles = (root)=>files_lines(git(root, [
|
|
329
|
+
'ls-files',
|
|
330
|
+
'--cached',
|
|
331
|
+
'--others',
|
|
332
|
+
'--exclude-standard'
|
|
333
|
+
], HOOK));
|
|
334
|
+
function merging(root) {
|
|
335
|
+
try {
|
|
336
|
+
git(root, [
|
|
337
|
+
'rev-parse',
|
|
338
|
+
'-q',
|
|
339
|
+
'--verify',
|
|
340
|
+
'MERGE_HEAD'
|
|
341
|
+
], HOOK);
|
|
342
|
+
return true;
|
|
343
|
+
} catch {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
function ownChanges(root, files) {
|
|
348
|
+
if (!files.length || !merging(root)) return files;
|
|
349
|
+
const differ = new Set(files_lines(git(root, [
|
|
350
|
+
'diff',
|
|
351
|
+
'--cached',
|
|
352
|
+
'--name-only',
|
|
353
|
+
'--no-renames',
|
|
354
|
+
'MERGE_HEAD',
|
|
355
|
+
'--',
|
|
356
|
+
...files
|
|
357
|
+
])));
|
|
358
|
+
return files.filter((f)=>differ.has(f));
|
|
359
|
+
}
|
|
360
|
+
export { ConfigError, changedLines, check, defineConfig, git, isShell, listFiles, matchesAny, ownChanges, repoFiles, repoRoot, withoutGitHookEnv };
|
package/dist/git.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare function withoutGitHookEnv(env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
2
|
+
export interface GitOptions {
|
|
3
|
+
/** Keep the GIT_* variables a hook exports, so git reads the index being committed. */
|
|
4
|
+
hookEnv?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/** Runs git in root and returns its stdout; a failure throws one line naming the command and git's first error line. */
|
|
7
|
+
export declare function git(root: string, args: string[], { hookEnv }?: GitOptions): string;
|
|
8
|
+
/** git's stdout as its non-empty lines. */
|
|
9
|
+
export declare const gitLines: (root: string, args: string[], options?: GitOptions) => string[];
|
|
10
|
+
export interface Scope {
|
|
11
|
+
changed: boolean;
|
|
12
|
+
base?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function listFiles(root: string, { changed, base }: Scope): string[];
|
|
15
|
+
export declare function addedLines(diff: string[]): Map<string, Set<number>>;
|
|
16
|
+
export declare function changedLines(root: string, { base }: Scope): (file: string, line: number) => boolean;
|
|
17
|
+
export declare const repoRoot: (cwd: string) => string;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { AgentFiles, CiConfig, CommandOption, CommentsConfig, Config, CrapConfig, DocsConfig, DryConfig, MutateConfig, PipelinesConfig, Platform, QualityConfig, UnitConfig, UnitInfo, } from './config.js';
|
|
2
|
+
export { defineConfig } from './config.js';
|
|
3
|
+
export { isShell, ownChanges, repoFiles } from './files.js';
|
|
4
|
+
export { runIfMain } from './run-if-main.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import * as __rspack_external_node_fs_1b05aee1 from "node:fs";
|
|
3
|
+
function isEntry(moduleUrl) {
|
|
4
|
+
try {
|
|
5
|
+
return __rspack_external_node_fs_1b05aee1.realpathSync(process.argv[1] ?? '') === fileURLToPath(moduleUrl);
|
|
6
|
+
} catch {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function runIfMain(moduleUrl, main) {
|
|
11
|
+
if (!isEntry(moduleUrl)) return;
|
|
12
|
+
const code = main(process.argv);
|
|
13
|
+
if (code) process.exit(code);
|
|
14
|
+
}
|
|
15
|
+
export { defineConfig, isShell, ownChanges, repoFiles } from "./g.js";
|
|
16
|
+
export { runIfMain };
|
package/dist/python.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type Env = NodeJS.ProcessEnv;
|
|
2
|
+
export declare function home(env: Env): string;
|
|
3
|
+
export declare function envDir(base: string): string;
|
|
4
|
+
export declare function ensureEnv(env: Env): string;
|
|
5
|
+
export declare function toolEnv(env: Env): Env;
|
|
6
|
+
export type Tool = 'crapper' | 'dryer' | 'mutator';
|
|
7
|
+
export interface ToolRun {
|
|
8
|
+
cwd: string;
|
|
9
|
+
env: Env;
|
|
10
|
+
log?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ToolResult {
|
|
13
|
+
code: number;
|
|
14
|
+
output: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function runTool(tool: Tool, args: string[], { cwd, env, log }: ToolRun): Promise<ToolResult>;
|
|
17
|
+
export declare function setup(env: Env): Promise<string>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Shard } from './shard.js';
|
|
2
|
+
import { type Touched } from './sites.js';
|
|
3
|
+
import type { Choice, Unit } from './units.js';
|
|
4
|
+
export interface Context {
|
|
5
|
+
root: string;
|
|
6
|
+
env: NodeJS.ProcessEnv;
|
|
7
|
+
units: Unit[];
|
|
8
|
+
dry: {
|
|
9
|
+
threshold: number;
|
|
10
|
+
includeTests: boolean;
|
|
11
|
+
};
|
|
12
|
+
changed: boolean;
|
|
13
|
+
minScore?: number;
|
|
14
|
+
shard?: Shard;
|
|
15
|
+
extra: string[];
|
|
16
|
+
list: (changed: boolean) => string[];
|
|
17
|
+
touched: () => Touched;
|
|
18
|
+
}
|
|
19
|
+
export type ToolCommand = {
|
|
20
|
+
kind: 'run';
|
|
21
|
+
command: string;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'tool default';
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'missing npm script';
|
|
26
|
+
};
|
|
27
|
+
export declare function commandFor(choice: Choice, files: string[]): ToolCommand;
|
|
28
|
+
export declare function crap(ctx: Context): Promise<number>;
|
|
29
|
+
export declare function dry(ctx: Context): Promise<number>;
|
|
30
|
+
export declare function mutationScore(output: string): number | undefined;
|
|
31
|
+
export interface Verdict {
|
|
32
|
+
ok: boolean;
|
|
33
|
+
score?: number;
|
|
34
|
+
}
|
|
35
|
+
export declare function judge(code: number, output: string, minScore: number | undefined): Verdict;
|
|
36
|
+
export declare function mutate(ctx: Context): Promise<number>;
|
|
37
|
+
export declare function ratio(ctx: Context): number;
|
|
38
|
+
export declare function prepare(env: NodeJS.ProcessEnv): Promise<number>;
|
|
39
|
+
export declare const QUALITY: Record<string, (ctx: Context) => number | Promise<number>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Added {
|
|
2
|
+
line: number;
|
|
3
|
+
text: string;
|
|
4
|
+
}
|
|
5
|
+
export interface FileAdded {
|
|
6
|
+
file: string;
|
|
7
|
+
added: Added[];
|
|
8
|
+
}
|
|
9
|
+
/** Of the added lines, those holding an external(...) comment, whose claim a person must check. */
|
|
10
|
+
export declare function reviewLines(file: string, source: string, added: number[]): number[];
|
|
11
|
+
/** The added lines of each file in a `git diff --unified=0`, with their new line numbers. */
|
|
12
|
+
export declare function parseDiff(diff: string): FileAdded[];
|
|
13
|
+
/** `file:line` for each external(...) comment added since the merge base with against, new files included, outside the exclude globs. */
|
|
14
|
+
export declare function reviewComments(root: string, against: string, exclude?: string[]): string[];
|