@mark1russell7/conventions 0.8.1 → 0.9.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 +19 -2
- package/build/cli.js +1 -1
- package/build/index.d.ts +37 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/{run-B7ftggFF.js → run-CRjXzR_6.js} +449 -78
- package/build/run-CRjXzR_6.js.map +1 -0
- package/package.json +1 -1
- package/build/run-B7ftggFF.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { spawnSync } from "node:child_process";
|
|
3
|
-
import { appendFileSync, existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
4
|
-
import { dirname, extname, join, posix, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { basename, dirname, extname, join, posix, relative, resolve, sep } from "node:path";
|
|
5
5
|
// src/config.ts
|
|
6
6
|
/** The fields of the configuration of a rule that are not options. */
|
|
7
7
|
const RULE_FIELDS = [
|
|
@@ -211,6 +211,13 @@ function packageFolders(root, globs = workspaceGlobs(root)) {
|
|
|
211
211
|
/**
|
|
212
212
|
* The shape of a rule, the facts that a rule reads (the context), and small helpers for the rules.
|
|
213
213
|
*/
|
|
214
|
+
/** This function gives `text` with the line `line` (from 1) replaced by `lines`, with the line ends of `text`. An empty `lines` removes the line. */
|
|
215
|
+
function replaceLine(text, line, lines) {
|
|
216
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
217
|
+
const all = text.split(/\r?\n/);
|
|
218
|
+
all.splice(line - 1, 1, ...lines);
|
|
219
|
+
return all.join(eol);
|
|
220
|
+
}
|
|
214
221
|
/** The fields of `package.json` that hold dependencies. */
|
|
215
222
|
const DEPENDENCY_FIELDS = [
|
|
216
223
|
"dependencies",
|
|
@@ -1750,7 +1757,7 @@ const roadmapParses = {
|
|
|
1750
1757
|
const WORKFLOW = /^\.github\/workflows\/[^/]+\.ya?ml$/;
|
|
1751
1758
|
const indentOf = (line) => line.length - line.trimStart().length;
|
|
1752
1759
|
/** This function removes a comment at the end of a value, and the quotes around it. */
|
|
1753
|
-
function valueOf(raw) {
|
|
1760
|
+
function valueOf$1(raw) {
|
|
1754
1761
|
const comment = raw.indexOf(" #");
|
|
1755
1762
|
let value = (comment >= 0 ? raw.slice(0, comment) : raw).trim();
|
|
1756
1763
|
const quote = value.charAt(0);
|
|
@@ -1762,7 +1769,7 @@ function keyValue(line, key) {
|
|
|
1762
1769
|
let text = line.trimStart();
|
|
1763
1770
|
if (text.startsWith("- ")) text = text.slice(2).trimStart();
|
|
1764
1771
|
if (!text.startsWith(`${key}:`)) return void 0;
|
|
1765
|
-
return valueOf(text.slice(key.length + 1));
|
|
1772
|
+
return valueOf$1(text.slice(key.length + 1));
|
|
1766
1773
|
}
|
|
1767
1774
|
/** This function gives the lines of the block under the line `index`: the next lines with a larger indent. */
|
|
1768
1775
|
function blockEnd(lines, index) {
|
|
@@ -1844,11 +1851,33 @@ function jobsOf(lines) {
|
|
|
1844
1851
|
}
|
|
1845
1852
|
const hasTopGroup = (lines) => lines.some((line) => indentOf(line) === 0 && line.startsWith("concurrency:"));
|
|
1846
1853
|
/**
|
|
1854
|
+
* This function gives the edit that adds a concurrency group at the top of a workflow, before `jobs:`. A new run of a pull
|
|
1855
|
+
* request stops the old run. A run of another event waits for the old run, so that no release or scheduled run stops.
|
|
1856
|
+
*/
|
|
1857
|
+
function groupEdits(file, text, lines) {
|
|
1858
|
+
const jobs = lines.findIndex((line) => indentOf(line) === 0 && line.startsWith("jobs:"));
|
|
1859
|
+
if (jobs < 0) return [];
|
|
1860
|
+
const pad = " ".repeat(childIndent(lines, jobs) ?? 2);
|
|
1861
|
+
const original = text.split(/\r?\n/)[jobs] ?? "jobs:";
|
|
1862
|
+
const group = [
|
|
1863
|
+
"concurrency:",
|
|
1864
|
+
pad + "group: ${{ github.workflow }}-${{ github.ref }}",
|
|
1865
|
+
pad + "cancel-in-progress: ${{ github.event_name == 'pull_request' }}",
|
|
1866
|
+
"",
|
|
1867
|
+
original
|
|
1868
|
+
];
|
|
1869
|
+
return [{
|
|
1870
|
+
file,
|
|
1871
|
+
before: text,
|
|
1872
|
+
after: replaceLine(text, jobs + 1, group)
|
|
1873
|
+
}];
|
|
1874
|
+
}
|
|
1875
|
+
/**
|
|
1847
1876
|
* This function gives the breaks of the concurrency groups. A workflow with no group at the top needs one in each job.
|
|
1848
1877
|
* A job that calls a shared workflow of `grouped` gets its group from the jobs of that workflow. A shared workflow gets
|
|
1849
1878
|
* its group from its caller, but a shared workflow of `grouped` has a group in each job.
|
|
1850
1879
|
*/
|
|
1851
|
-
function concurrencyBreaks(file, lines, grouped) {
|
|
1880
|
+
function concurrencyBreaks(file, text, lines, grouped) {
|
|
1852
1881
|
const name = file.slice(file.lastIndexOf("/") + 1);
|
|
1853
1882
|
const jobs = jobsOf(lines);
|
|
1854
1883
|
if (isShared(lines)) {
|
|
@@ -1860,32 +1889,55 @@ function concurrencyBreaks(file, lines, grouped) {
|
|
|
1860
1889
|
}));
|
|
1861
1890
|
}
|
|
1862
1891
|
if (hasTopGroup(lines)) return [];
|
|
1863
|
-
|
|
1892
|
+
const missing = jobs.filter((job) => !job.grouped && !(job.calls !== void 0 && grouped.includes(job.calls)));
|
|
1893
|
+
const edits = missing.length === 0 ? [] : groupEdits(file, text, lines);
|
|
1894
|
+
return missing.map((job) => ({
|
|
1864
1895
|
file,
|
|
1865
1896
|
line: job.line,
|
|
1866
|
-
message: `${file}: the job ${job.name} has no concurrency group, and the workflow has none
|
|
1897
|
+
message: `${file}: the job ${job.name} has no concurrency group, and the workflow has none.`,
|
|
1898
|
+
edits
|
|
1867
1899
|
}));
|
|
1868
1900
|
}
|
|
1869
1901
|
/** This function gives the breaks of the matrices: each `strategy` with a `matrix` has a `max-parallel` of `limit` or less. */
|
|
1870
|
-
function matrixBreaks(file, lines, limit) {
|
|
1902
|
+
function matrixBreaks(file, text, lines, limit) {
|
|
1871
1903
|
const breaks = [];
|
|
1904
|
+
const originals = text.split(/\r?\n/);
|
|
1872
1905
|
lines.forEach((line, index) => {
|
|
1873
1906
|
if (keyValue(line, "strategy") === void 0) return;
|
|
1874
1907
|
const keyIndent = childIndent(lines, index);
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1908
|
+
if (keyIndent === void 0) return;
|
|
1909
|
+
const keys = [];
|
|
1910
|
+
for (let i = index + 1; i < blockEnd(lines, index); i++) if ((lines[i] ?? "").trim() !== "" && indentOf(lines[i] ?? "") === keyIndent) keys.push(i);
|
|
1911
|
+
if (!keys.some((i) => keyValue(lines[i] ?? "", "matrix") !== void 0)) return;
|
|
1912
|
+
const at = keys.find((i) => keyValue(lines[i] ?? "", "max-parallel") !== void 0);
|
|
1913
|
+
const raw = at === void 0 ? void 0 : keyValue(lines[at] ?? "", "max-parallel");
|
|
1878
1914
|
const value = raw === void 0 ? NaN : Number(raw);
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1915
|
+
const wanted = `${" ".repeat(keyIndent)}max-parallel: ${String(limit)}`;
|
|
1916
|
+
if (at === void 0 || raw === void 0) {
|
|
1917
|
+
const after = replaceLine(text, index + 1, [originals[index] ?? line, wanted]);
|
|
1918
|
+
breaks.push({
|
|
1919
|
+
file,
|
|
1920
|
+
line: index + 1,
|
|
1921
|
+
message: `${file}: a matrix has no max-parallel.`,
|
|
1922
|
+
edits: [{
|
|
1923
|
+
file,
|
|
1924
|
+
before: text,
|
|
1925
|
+
after
|
|
1926
|
+
}]
|
|
1927
|
+
});
|
|
1928
|
+
} else if (!Number.isInteger(value) || value < 1 || value > limit) {
|
|
1929
|
+
const after = replaceLine(text, at + 1, [wanted]);
|
|
1930
|
+
breaks.push({
|
|
1931
|
+
file,
|
|
1932
|
+
line: index + 1,
|
|
1933
|
+
message: `${file}: a matrix has max-parallel ${raw}, and the most is ${String(limit)}.`,
|
|
1934
|
+
edits: [{
|
|
1935
|
+
file,
|
|
1936
|
+
before: text,
|
|
1937
|
+
after
|
|
1938
|
+
}]
|
|
1939
|
+
});
|
|
1940
|
+
}
|
|
1889
1941
|
});
|
|
1890
1942
|
return breaks;
|
|
1891
1943
|
}
|
|
@@ -1907,8 +1959,9 @@ function startsPerHour(field) {
|
|
|
1907
1959
|
* This function gives the breaks of the schedules: the minute of each `cron` is the minute of the repository and the file. A
|
|
1908
1960
|
* schedule that starts more than once in each hour starts at equal steps from that minute (`18,48` for each 30 minutes).
|
|
1909
1961
|
*/
|
|
1910
|
-
function cronBreaks(file, lines, minute) {
|
|
1962
|
+
function cronBreaks(file, text, lines, minute) {
|
|
1911
1963
|
const breaks = [];
|
|
1964
|
+
const originals = text.split(/\r?\n/);
|
|
1912
1965
|
lines.forEach((line, index) => {
|
|
1913
1966
|
const value = keyValue(line, "cron");
|
|
1914
1967
|
if (value === void 0) return;
|
|
@@ -1916,11 +1969,18 @@ function cronBreaks(file, lines, minute) {
|
|
|
1916
1969
|
const wanted = minuteField(minute, startsPerHour(fields[0] ?? ""));
|
|
1917
1970
|
if (fields[0] === wanted) return;
|
|
1918
1971
|
const expected = [wanted, ...fields.slice(1)].join(" ");
|
|
1972
|
+
const original = originals[index] ?? line;
|
|
1973
|
+
const edits = original.includes(value) ? [{
|
|
1974
|
+
file,
|
|
1975
|
+
before: text,
|
|
1976
|
+
after: replaceLine(text, index + 1, [original.replace(value, () => expected)])
|
|
1977
|
+
}] : [];
|
|
1919
1978
|
breaks.push({
|
|
1920
1979
|
file,
|
|
1921
1980
|
line: index + 1,
|
|
1922
1981
|
message: `${file}: the schedule "${value}" starts at minute ${fields[0] ?? "?"}, and the minute of this repository and file is ${String(minute)}.`,
|
|
1923
|
-
fix: `cron: "${expected}"
|
|
1982
|
+
fix: `cron: "${expected}"`,
|
|
1983
|
+
edits
|
|
1924
1984
|
});
|
|
1925
1985
|
});
|
|
1926
1986
|
return breaks;
|
|
@@ -1974,13 +2034,13 @@ const runnerBudget = {
|
|
|
1974
2034
|
continue;
|
|
1975
2035
|
}
|
|
1976
2036
|
const lines = text.split(/\r?\n/).map((line) => line.trimStart().startsWith("#") ? "" : line);
|
|
1977
|
-
breaks.push(...matrixBreaks(file, lines, limit), ...concurrencyBreaks(file, lines, grouped));
|
|
2037
|
+
breaks.push(...matrixBreaks(file, text, lines, limit), ...concurrencyBreaks(file, text, lines, grouped));
|
|
1978
2038
|
if (options["minute"] !== false) {
|
|
1979
2039
|
if (lines.some((line) => keyValue(line, "cron") !== void 0) && repository === void 0) breaks.push({
|
|
1980
2040
|
file,
|
|
1981
2041
|
message: `${file} has a schedule, and the rule cannot find the repository (GITHUB_REPOSITORY, or a GitHub URL of the remote origin).`
|
|
1982
2042
|
});
|
|
1983
|
-
else if (repository !== void 0) breaks.push(...cronBreaks(file, lines, scheduleMinute(repository, file)));
|
|
2043
|
+
else if (repository !== void 0) breaks.push(...cronBreaks(file, text, lines, scheduleMinute(repository, file)));
|
|
1984
2044
|
}
|
|
1985
2045
|
}
|
|
1986
2046
|
return breaks;
|
|
@@ -2121,46 +2181,6 @@ const sourceMain = {
|
|
|
2121
2181
|
return breaks;
|
|
2122
2182
|
}
|
|
2123
2183
|
};
|
|
2124
|
-
// src/rules/tests-required.ts
|
|
2125
|
-
/**
|
|
2126
|
-
* The rule `tests-required`: no test runner passes when it finds no test (`passWithNoTests`).
|
|
2127
|
-
*/
|
|
2128
|
-
/** The files that set the options of a test runner: its configs, and package.json for the scripts. */
|
|
2129
|
-
const RUNNER_FILE = /(?:^|\/)(?:(?:vitest|vite|jest|playwright)(?:\.[\w-]+)*\.config\.[cm]?[jt]s|vitest\.workspace\.[cm]?[jt]s|package\.json)$/;
|
|
2130
|
-
/** The option in a config (`passWithNoTests: true`) or on a command line (`--passWithNoTests`, `--pass-with-no-tests`). */
|
|
2131
|
-
const PASS_WITH_NO_TESTS = /passWithNoTests\s*:\s*true|--passWithNoTests(?!=false)|--pass-with-no-tests(?!=false)/;
|
|
2132
|
-
const testsRequired = {
|
|
2133
|
-
id: "tests-required",
|
|
2134
|
-
title: "No test runner passes when it finds no test: no `passWithNoTests: true` in a config, and no `--passWithNoTests` in a script.",
|
|
2135
|
-
reason: "With the option, a test step that finds 0 tests passes. A broken include pattern, a moved folder or a renamed file then turns the gate green with no test run. In the fleet audit of 2026-10-30, vex had the option in all 9 vitest configs and client in 2 packages that have tests.",
|
|
2136
|
-
fix: "Remove the option. A package with no tests has no test script, so the shared CI skips it. A package whose tests a later change adds keeps no test script until then.",
|
|
2137
|
-
sources: [{
|
|
2138
|
-
repo: "fleet",
|
|
2139
|
-
rule: "fail-closed",
|
|
2140
|
-
doc: "docs/STRATEGY.md (2026-10-30, gates and probes fail closed)"
|
|
2141
|
-
}],
|
|
2142
|
-
options: {},
|
|
2143
|
-
check(context) {
|
|
2144
|
-
const files = context.gitFiles();
|
|
2145
|
-
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
2146
|
-
const breaks = [];
|
|
2147
|
-
for (const file of files.filter((path) => RUNNER_FILE.test(path)).sort(byCode)) {
|
|
2148
|
-
let text;
|
|
2149
|
-
try {
|
|
2150
|
-
text = readFileSync(join(context.root, file), "utf8");
|
|
2151
|
-
} catch {
|
|
2152
|
-
continue;
|
|
2153
|
-
}
|
|
2154
|
-
const index = text.split(/\r?\n/).findIndex((line) => PASS_WITH_NO_TESTS.test(line));
|
|
2155
|
-
if (index >= 0) breaks.push({
|
|
2156
|
-
file,
|
|
2157
|
-
line: index + 1,
|
|
2158
|
-
message: `${file} lets the tests pass when they find no test (passWithNoTests).`
|
|
2159
|
-
});
|
|
2160
|
-
}
|
|
2161
|
-
return breaks;
|
|
2162
|
-
}
|
|
2163
|
-
};
|
|
2164
2184
|
// src/rules/tsconfig-test.ts
|
|
2165
2185
|
/**
|
|
2166
2186
|
* The rule `tsconfig-test`: each TypeScript package has a `tsconfig.test.json`, and its typecheck
|
|
@@ -2268,6 +2288,79 @@ const tsconfigTest = {
|
|
|
2268
2288
|
return breaks;
|
|
2269
2289
|
}
|
|
2270
2290
|
};
|
|
2291
|
+
// src/rules/tests-required.ts
|
|
2292
|
+
/**
|
|
2293
|
+
* The rule `tests-required`: no test runner passes when it finds no test (`passWithNoTests`).
|
|
2294
|
+
*/
|
|
2295
|
+
/** The files that set the options of a test runner: its configs, and package.json for the scripts. */
|
|
2296
|
+
const RUNNER_FILE = /(?:^|\/)(?:(?:vitest|vite|jest|playwright)(?:\.[\w-]+)*\.config\.[cm]?[jt]s|vitest\.workspace\.[cm]?[jt]s|package\.json)$/;
|
|
2297
|
+
/** The option in a config (`passWithNoTests: true`) or on a command line (`--passWithNoTests`, `--pass-with-no-tests`). */
|
|
2298
|
+
const PASS_WITH_NO_TESTS = /passWithNoTests\s*:\s*true|--passWithNoTests(?!=false)|--pass-with-no-tests(?!=false)/;
|
|
2299
|
+
/** A line that holds only the option in a config. `conventions fix` removes such a line. */
|
|
2300
|
+
const OPTION_LINE = /^\s*passWithNoTests\s*:\s*true\s*,?\s*$/;
|
|
2301
|
+
/** The option in a line of a config with more keys. The first form has the comma after it, and the second form has the comma before it. */
|
|
2302
|
+
const OPTION_IN_LINE = [/\bpassWithNoTests\s*:\s*true\s*,\s*/, /,?\s*\bpassWithNoTests\s*:\s*true\b/];
|
|
2303
|
+
/** The option on a command line, with the space before it. */
|
|
2304
|
+
const FLAG = / --(?:passWithNoTests|pass-with-no-tests)(?:=true)?(?=\s|"|$)/g;
|
|
2305
|
+
/** This function gives the folder of the package that holds `file`: the longest folder of a package that starts its path. */
|
|
2306
|
+
function packageOf(context, file) {
|
|
2307
|
+
let best = "";
|
|
2308
|
+
for (const info of context.packages) if (info.folder !== "" && file.startsWith(`${info.folder}/`) && info.folder.length > best.length) best = info.folder;
|
|
2309
|
+
return best;
|
|
2310
|
+
}
|
|
2311
|
+
/**
|
|
2312
|
+
* This function gives the edit that removes the option from one line, or no edit. The edit exists only when the package has
|
|
2313
|
+
* test files: then the test step still finds tests. A package with no tests needs a person, who removes its test script.
|
|
2314
|
+
*/
|
|
2315
|
+
function removeOption(context, files, file, text, index) {
|
|
2316
|
+
if (!hasTests(files, packageOf(context, file))) return [];
|
|
2317
|
+
const line = text.split(/\r?\n/)[index] ?? "";
|
|
2318
|
+
if (OPTION_LINE.test(line)) return [{
|
|
2319
|
+
file,
|
|
2320
|
+
before: text,
|
|
2321
|
+
after: replaceLine(text, index + 1, [])
|
|
2322
|
+
}];
|
|
2323
|
+
const form = OPTION_IN_LINE.find((pattern) => pattern.test(line));
|
|
2324
|
+
const without = file.endsWith("package.json") ? line.replace(FLAG, "") : form === void 0 ? line : line.replace(form, "");
|
|
2325
|
+
return without === line ? [] : [{
|
|
2326
|
+
file,
|
|
2327
|
+
before: text,
|
|
2328
|
+
after: replaceLine(text, index + 1, [without])
|
|
2329
|
+
}];
|
|
2330
|
+
}
|
|
2331
|
+
const testsRequired = {
|
|
2332
|
+
id: "tests-required",
|
|
2333
|
+
title: "No test runner passes when it finds no test: no `passWithNoTests: true` in a config, and no `--passWithNoTests` in a script.",
|
|
2334
|
+
reason: "With the option, a test step that finds 0 tests passes. A broken include pattern, a moved folder or a renamed file then turns the gate green with no test run. In the fleet audit of 2026-10-30, vex had the option in all 9 vitest configs and client in 2 packages that have tests.",
|
|
2335
|
+
fix: "Remove the option. A package with no tests has no test script, so the shared CI skips it. A package whose tests a later change adds keeps no test script until then.",
|
|
2336
|
+
sources: [{
|
|
2337
|
+
repo: "fleet",
|
|
2338
|
+
rule: "fail-closed",
|
|
2339
|
+
doc: "docs/STRATEGY.md (2026-10-30, gates and probes fail closed)"
|
|
2340
|
+
}],
|
|
2341
|
+
options: {},
|
|
2342
|
+
check(context) {
|
|
2343
|
+
const files = context.gitFiles();
|
|
2344
|
+
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
2345
|
+
const breaks = [];
|
|
2346
|
+
for (const file of files.filter((path) => RUNNER_FILE.test(path)).sort(byCode)) {
|
|
2347
|
+
let text;
|
|
2348
|
+
try {
|
|
2349
|
+
text = readFileSync(join(context.root, file), "utf8");
|
|
2350
|
+
} catch {
|
|
2351
|
+
continue;
|
|
2352
|
+
}
|
|
2353
|
+
const index = text.split(/\r?\n/).findIndex((line) => PASS_WITH_NO_TESTS.test(line));
|
|
2354
|
+
if (index >= 0) breaks.push({
|
|
2355
|
+
file,
|
|
2356
|
+
line: index + 1,
|
|
2357
|
+
message: `${file} lets the tests pass when they find no test (passWithNoTests).`,
|
|
2358
|
+
edits: removeOption(context, files, file, text, index)
|
|
2359
|
+
});
|
|
2360
|
+
}
|
|
2361
|
+
return breaks;
|
|
2362
|
+
}
|
|
2363
|
+
};
|
|
2271
2364
|
// src/rules/typed-files.ts
|
|
2272
2365
|
/**
|
|
2273
2366
|
* The rule `typed-files`: each TypeScript file that git keeps is in a tsconfig that a `typecheck`
|
|
@@ -2391,6 +2484,65 @@ function referencesOf(config) {
|
|
|
2391
2484
|
if (!Array.isArray(references)) return [];
|
|
2392
2485
|
return references.flatMap((item) => typeof item === "object" && item !== null && typeof item.path === "string" ? [resolve(dirname(config), item.path)] : []);
|
|
2393
2486
|
}
|
|
2487
|
+
/** A config file of a tool (`vitest.config.ts`), with its extension. */
|
|
2488
|
+
const CONFIG_FILE = /\.config(\.[cm]?ts)$/;
|
|
2489
|
+
/** A `rootDir` that is the folder of the tsconfig, so that the config files at the root are in it. */
|
|
2490
|
+
const ROOT_DIRS = /* @__PURE__ */ new Set([
|
|
2491
|
+
".",
|
|
2492
|
+
"./",
|
|
2493
|
+
"${configDir}",
|
|
2494
|
+
"${configDir}/"
|
|
2495
|
+
]);
|
|
2496
|
+
/**
|
|
2497
|
+
* This function gives the edit that adds the config files at the root of a package to its `tsconfig.test.json`. It adds
|
|
2498
|
+
* the include `*.config.ts`. When the `rootDir` is a subfolder, it sets `rootDir: "."`. The edit changes only these
|
|
2499
|
+
* values and keeps the format of the file. It gives no edit for a tsconfig with comments, so that no comment goes. It
|
|
2500
|
+
* also gives no edit when the changed text does not parse as the intended config.
|
|
2501
|
+
*/
|
|
2502
|
+
function configEdit(root, tsconfig, extension) {
|
|
2503
|
+
const text = readFileSync(tsconfig, "utf8");
|
|
2504
|
+
let json;
|
|
2505
|
+
try {
|
|
2506
|
+
json = JSON.parse(text);
|
|
2507
|
+
} catch {
|
|
2508
|
+
return [];
|
|
2509
|
+
}
|
|
2510
|
+
const globs = json.include;
|
|
2511
|
+
if (!Array.isArray(globs)) return [];
|
|
2512
|
+
const glob = `${globs.length > 0 && globs.every((glob) => typeof glob === "string" && glob.startsWith("${configDir}/")) ? "${configDir}/" : ""}*.config${extension}`;
|
|
2513
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
2514
|
+
let after = text;
|
|
2515
|
+
if (!globs.includes(glob)) after = after.replace(/("include"\s*:\s*\[)([^\]]*)\]/, (_all, start, items) => {
|
|
2516
|
+
const kept = items.replace(/\s+$/, "");
|
|
2517
|
+
const end = items.slice(kept.length);
|
|
2518
|
+
if (kept.trim() === "") return `${start}${JSON.stringify(glob)}]`;
|
|
2519
|
+
const indent = kept.includes("\n") ? /\n([ \t]*)[^\n]*$/.exec(kept)?.[1] ?? "" : void 0;
|
|
2520
|
+
return `${start}${kept},${indent === void 0 ? " " : `${eol}${indent}`}${JSON.stringify(glob)}${end}]`;
|
|
2521
|
+
});
|
|
2522
|
+
const rootDir = json.compilerOptions?.["rootDir"];
|
|
2523
|
+
const moveRoot = typeof rootDir === "string" && !ROOT_DIRS.has(rootDir);
|
|
2524
|
+
if (moveRoot) after = after.replace(/("rootDir"\s*:\s*)"(?:[^"\\]|\\.)*"/, "$1\".\"");
|
|
2525
|
+
const intended = {
|
|
2526
|
+
...json,
|
|
2527
|
+
...moveRoot ? { compilerOptions: {
|
|
2528
|
+
...json.compilerOptions,
|
|
2529
|
+
rootDir: "."
|
|
2530
|
+
} } : {},
|
|
2531
|
+
include: globs.includes(glob) ? globs : [...globs, glob]
|
|
2532
|
+
};
|
|
2533
|
+
let parsed;
|
|
2534
|
+
try {
|
|
2535
|
+
parsed = JSON.parse(after);
|
|
2536
|
+
} catch {
|
|
2537
|
+
return [];
|
|
2538
|
+
}
|
|
2539
|
+
if (JSON.stringify(parsed) !== JSON.stringify(intended)) return [];
|
|
2540
|
+
return after === text ? [] : [{
|
|
2541
|
+
file: fromRoot(root, tsconfig),
|
|
2542
|
+
before: text,
|
|
2543
|
+
after
|
|
2544
|
+
}];
|
|
2545
|
+
}
|
|
2394
2546
|
/** The path of `file` relative to `root`, with `/`. */
|
|
2395
2547
|
const fromRoot = (root, file) => relative(root, file).split("\\").join("/");
|
|
2396
2548
|
const typedFiles = {
|
|
@@ -2421,6 +2573,7 @@ const typedFiles = {
|
|
|
2421
2573
|
}];
|
|
2422
2574
|
const breaks = [];
|
|
2423
2575
|
const queue = [];
|
|
2576
|
+
const testConfigs = /* @__PURE__ */ new Map();
|
|
2424
2577
|
const packages = [context.rootPackage, ...codePackages(context).filter((info) => info !== context.rootPackage)];
|
|
2425
2578
|
for (const info of packages) {
|
|
2426
2579
|
const scripts = info.manifest["scripts"];
|
|
@@ -2438,6 +2591,7 @@ const typedFiles = {
|
|
|
2438
2591
|
continue;
|
|
2439
2592
|
}
|
|
2440
2593
|
queue.push(path);
|
|
2594
|
+
if (basename(path) === "tsconfig.test.json" && resolve(dirname(path)) === resolve(info.dir)) testConfigs.set(info.folder, path);
|
|
2441
2595
|
}
|
|
2442
2596
|
}
|
|
2443
2597
|
const extra = Array.isArray(options["configs"]) ? options["configs"] : [];
|
|
@@ -2472,10 +2626,18 @@ const typedFiles = {
|
|
|
2472
2626
|
message: "No typecheck script names a tsconfig, so no TypeScript file has a type check.",
|
|
2473
2627
|
fix: "Add a script typecheck (`tsc -p tsconfig.json`) to each package."
|
|
2474
2628
|
});
|
|
2475
|
-
for (const file of files)
|
|
2476
|
-
file
|
|
2477
|
-
|
|
2478
|
-
|
|
2629
|
+
for (const file of files) {
|
|
2630
|
+
if (covered.has(file)) continue;
|
|
2631
|
+
const folder = file.includes("/") ? file.slice(0, file.lastIndexOf("/")) : "";
|
|
2632
|
+
const extension = CONFIG_FILE.exec(file)?.[1];
|
|
2633
|
+
const tsconfig = testConfigs.get(folder);
|
|
2634
|
+
const edits = extension === void 0 || tsconfig === void 0 ? [] : configEdit(context.root, tsconfig, extension);
|
|
2635
|
+
breaks.push({
|
|
2636
|
+
file,
|
|
2637
|
+
message: `${file} is in no tsconfig that a typecheck script examines.`,
|
|
2638
|
+
edits
|
|
2639
|
+
});
|
|
2640
|
+
}
|
|
2479
2641
|
return breaks;
|
|
2480
2642
|
}
|
|
2481
2643
|
};
|
|
@@ -2583,6 +2745,150 @@ const typedScripts = {
|
|
|
2583
2745
|
return breaks;
|
|
2584
2746
|
}
|
|
2585
2747
|
};
|
|
2748
|
+
// src/rules/trust-policy.ts
|
|
2749
|
+
/**
|
|
2750
|
+
* The rule `trust-policy`: a pnpm repository sets `trustPolicy: no-downgrade` in `pnpm-workspace.yaml`. It checks each
|
|
2751
|
+
* version for 7 days after its publish (`trustPolicyIgnoreAfter`). It excludes the scopes of the release train.
|
|
2752
|
+
*/
|
|
2753
|
+
const WORKSPACE = "pnpm-workspace.yaml";
|
|
2754
|
+
/** The scopes that the release train updates. The train checks the provenance of their versions itself. */
|
|
2755
|
+
const TRAIN_SCOPES = ["@mark1russell7/*", "@procedures/*"];
|
|
2756
|
+
/** 7 days, in minutes. */
|
|
2757
|
+
const IGNORE_AFTER = 10080;
|
|
2758
|
+
const POLICY_COMMENT = ["# An install fails when a new version has less trust evidence than an earlier version of the same package: for", "# example, a version with no provenance after versions from a trusted publisher. Such a version can be a stolen token."];
|
|
2759
|
+
const IGNORE_COMMENT = ["# The check examines the versions of the last 7 days. A stolen-token version is new, and the registry removes it in", "# hours. Older versions can have less evidence for other reasons: for example undici-types 6.21.0 under @types/node."];
|
|
2760
|
+
const EXCLUDE_COMMENT = ["# The release train updates our own scopes, and it checks the provenance of each version. pnpm cannot use them: it", "# ranks the first versions, which were staged by hand, above the versions from release.yml (pnpm/pnpm#16689)."];
|
|
2761
|
+
/** A top-level key of the file: its line index, and its value without a comment or quotes. */
|
|
2762
|
+
function valueOf(lines, key) {
|
|
2763
|
+
const index = lines.findIndex((line) => line.startsWith(`${key}:`));
|
|
2764
|
+
if (index < 0) return void 0;
|
|
2765
|
+
return {
|
|
2766
|
+
index,
|
|
2767
|
+
value: (lines[index] ?? "").slice(key.length + 1).replace(/\s+#.*$/, "").trim().replace(/^["']|["']$/g, "")
|
|
2768
|
+
};
|
|
2769
|
+
}
|
|
2770
|
+
/** This function gives the items of the block list under the line `start`, the index of its last item, and its indent. */
|
|
2771
|
+
function blockList(lines, start) {
|
|
2772
|
+
const items = [];
|
|
2773
|
+
let last = start;
|
|
2774
|
+
let indent = " ";
|
|
2775
|
+
for (let index = start + 1; index < lines.length; index++) {
|
|
2776
|
+
const line = lines[index] ?? "";
|
|
2777
|
+
const text = line.trim();
|
|
2778
|
+
if (text === "" || text.startsWith("#")) continue;
|
|
2779
|
+
if (!text.startsWith("- ") || line === line.trimStart()) break;
|
|
2780
|
+
indent = line.slice(0, line.length - line.trimStart().length);
|
|
2781
|
+
items.push(text.slice(2).replace(/\s+#.*$/, "").trim().replace(/^["']|["']$/g, ""));
|
|
2782
|
+
last = index;
|
|
2783
|
+
}
|
|
2784
|
+
return {
|
|
2785
|
+
items,
|
|
2786
|
+
last,
|
|
2787
|
+
indent
|
|
2788
|
+
};
|
|
2789
|
+
}
|
|
2790
|
+
/** This function gives the text with the lines `added` after the line `after` (-1: at the end), with the line ends of the text. */
|
|
2791
|
+
function insert(text, after, added) {
|
|
2792
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
2793
|
+
const lines = text.split(/\r?\n/);
|
|
2794
|
+
if (after >= 0) {
|
|
2795
|
+
lines.splice(after + 1, 0, ...added);
|
|
2796
|
+
return lines.join(eol);
|
|
2797
|
+
}
|
|
2798
|
+
while (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
|
|
2799
|
+
return [
|
|
2800
|
+
...lines,
|
|
2801
|
+
...lines.length > 0 ? [""] : [],
|
|
2802
|
+
...added,
|
|
2803
|
+
""
|
|
2804
|
+
].join(eol);
|
|
2805
|
+
}
|
|
2806
|
+
/** This function gives the text with the value of the top-level key on the line `index` replaced. */
|
|
2807
|
+
function setValue(text, index, key, value) {
|
|
2808
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
2809
|
+
const lines = text.split(/\r?\n/);
|
|
2810
|
+
lines[index] = `${key}: ${value}`;
|
|
2811
|
+
return lines.join(eol);
|
|
2812
|
+
}
|
|
2813
|
+
const trustPolicy = {
|
|
2814
|
+
id: "trust-policy",
|
|
2815
|
+
title: "A pnpm repository sets `trustPolicy: no-downgrade` for the versions of the last 7 days, and excludes the scopes of the release train.",
|
|
2816
|
+
reason: "A stolen npm token can publish a version with no provenance, and the next install takes it. With `no-downgrade`, pnpm refuses a version with less trust evidence than an earlier version. The release age of pnpm keeps out the versions of the last day; this check covers the next days. The release train updates our own scopes at once and checks their provenance itself.",
|
|
2817
|
+
fix: "Add `trustPolicy: no-downgrade`, `trustPolicyIgnoreAfter: 10080` and a `trustPolicyExclude` with the scopes of the option `exclude` to `pnpm-workspace.yaml`. `conventions fix` writes them.",
|
|
2818
|
+
sources: [{
|
|
2819
|
+
repo: "fleet",
|
|
2820
|
+
rule: "trust-policy",
|
|
2821
|
+
doc: "docs/STRATEGY.md (2026-11-01, release age and trust policy)"
|
|
2822
|
+
}],
|
|
2823
|
+
options: {
|
|
2824
|
+
exclude: {
|
|
2825
|
+
type: "strings",
|
|
2826
|
+
default: [...TRAIN_SCOPES],
|
|
2827
|
+
description: "The patterns that `trustPolicyExclude` must have: the scopes whose versions the release train checks."
|
|
2828
|
+
},
|
|
2829
|
+
ignoreAfter: {
|
|
2830
|
+
type: "number",
|
|
2831
|
+
default: IGNORE_AFTER,
|
|
2832
|
+
description: "The smallest `trustPolicyIgnoreAfter`, in minutes. A larger value checks more versions."
|
|
2833
|
+
}
|
|
2834
|
+
},
|
|
2835
|
+
check(context, options) {
|
|
2836
|
+
if (!hasFile(context.root, "pnpm-lock.yaml")) return { skipped: "the repository has no pnpm-lock.yaml" };
|
|
2837
|
+
const exclude = Array.isArray(options["exclude"]) ? options["exclude"] : TRAIN_SCOPES;
|
|
2838
|
+
const ignoreAfter = typeof options["ignoreAfter"] === "number" ? options["ignoreAfter"] : IGNORE_AFTER;
|
|
2839
|
+
const exists = hasFile(context.root, WORKSPACE);
|
|
2840
|
+
const text = exists ? readFileSync(join(context.root, WORKSPACE), "utf8") : "";
|
|
2841
|
+
const lines = text.split(/\r?\n/);
|
|
2842
|
+
const edit = (after) => after === text ? [] : [{
|
|
2843
|
+
file: WORKSPACE,
|
|
2844
|
+
before: text,
|
|
2845
|
+
after
|
|
2846
|
+
}];
|
|
2847
|
+
const at = (index) => index === void 0 ? {} : { line: index + 1 };
|
|
2848
|
+
const breaks = [];
|
|
2849
|
+
const policy = valueOf(lines, "trustPolicy");
|
|
2850
|
+
if (policy?.value !== "no-downgrade") breaks.push({
|
|
2851
|
+
file: WORKSPACE,
|
|
2852
|
+
...at(policy?.index),
|
|
2853
|
+
message: policy === void 0 ? `${exists ? WORKSPACE : "The repository"} does not set trustPolicy.` : `trustPolicy is "${policy.value}", not "no-downgrade".`,
|
|
2854
|
+
edits: edit(policy === void 0 ? insert(text, -1, [...POLICY_COMMENT, "trustPolicy: no-downgrade"]) : setValue(text, policy.index, "trustPolicy", "no-downgrade"))
|
|
2855
|
+
});
|
|
2856
|
+
const ignore = valueOf(lines, "trustPolicyIgnoreAfter");
|
|
2857
|
+
const minutes = ignore === void 0 ? void 0 : Number(ignore.value);
|
|
2858
|
+
if (minutes === void 0 || !Number.isInteger(minutes) || minutes < ignoreAfter) {
|
|
2859
|
+
const after = ignore !== void 0 ? setValue(text, ignore.index, "trustPolicyIgnoreAfter", String(ignoreAfter)) : policy !== void 0 ? insert(text, policy.index, [...IGNORE_COMMENT, `trustPolicyIgnoreAfter: ${String(ignoreAfter)}`]) : text;
|
|
2860
|
+
breaks.push({
|
|
2861
|
+
file: WORKSPACE,
|
|
2862
|
+
...at(ignore?.index),
|
|
2863
|
+
message: ignore === void 0 ? `${WORKSPACE} does not set trustPolicyIgnoreAfter, so pnpm also refuses old versions that have less evidence for other reasons.` : `trustPolicyIgnoreAfter is ${ignore.value}, not a whole number of at least ${String(ignoreAfter)} minutes.`,
|
|
2864
|
+
edits: edit(after)
|
|
2865
|
+
});
|
|
2866
|
+
}
|
|
2867
|
+
const start = lines.findIndex((line) => line.startsWith("trustPolicyExclude:"));
|
|
2868
|
+
const inline = start >= 0 && (valueOf(lines, "trustPolicyExclude")?.value ?? "") !== "";
|
|
2869
|
+
const list = start >= 0 && !inline ? blockList(lines, start) : {
|
|
2870
|
+
items: [],
|
|
2871
|
+
last: start,
|
|
2872
|
+
indent: " "
|
|
2873
|
+
};
|
|
2874
|
+
const missing = exclude.filter((pattern) => !list.items.includes(pattern));
|
|
2875
|
+
if (missing.length > 0) {
|
|
2876
|
+
const items = missing.map((pattern) => `${list.indent}- ${JSON.stringify(pattern)}`);
|
|
2877
|
+
const after = inline ? text : start >= 0 ? insert(text, list.last, items) : policy === void 0 ? text : insert(text, -1, [
|
|
2878
|
+
...EXCLUDE_COMMENT,
|
|
2879
|
+
"trustPolicyExclude:",
|
|
2880
|
+
...items
|
|
2881
|
+
]);
|
|
2882
|
+
breaks.push({
|
|
2883
|
+
file: WORKSPACE,
|
|
2884
|
+
...at(start >= 0 ? start : void 0),
|
|
2885
|
+
message: `trustPolicyExclude does not have ${missing.join(", ")}.`,
|
|
2886
|
+
edits: edit(after)
|
|
2887
|
+
});
|
|
2888
|
+
}
|
|
2889
|
+
return breaks;
|
|
2890
|
+
}
|
|
2891
|
+
};
|
|
2586
2892
|
// src/rules/workspace-protocol.ts
|
|
2587
2893
|
/**
|
|
2588
2894
|
* The rule `workspace-protocol`: a package uses another package of the workspace through `workspace:`.
|
|
@@ -2652,6 +2958,7 @@ const workspaceProtocol = {
|
|
|
2652
2958
|
const RULES = [
|
|
2653
2959
|
pinnedGitDeps,
|
|
2654
2960
|
workspaceProtocol,
|
|
2961
|
+
trustPolicy,
|
|
2655
2962
|
sourceMain,
|
|
2656
2963
|
tsconfigTest,
|
|
2657
2964
|
cuePreset,
|
|
@@ -2667,8 +2974,8 @@ const RULES = [
|
|
|
2667
2974
|
];
|
|
2668
2975
|
// src/run.ts
|
|
2669
2976
|
/**
|
|
2670
|
-
* The commands `check` and `--list` of the bin `conventions`, as functions. `runChecks` starts the
|
|
2671
|
-
* rules, and `runCli` reads the arguments and writes the result.
|
|
2977
|
+
* The commands `check`, `fix` and `--list` of the bin `conventions`, as functions. `runChecks` starts the
|
|
2978
|
+
* rules, `runFix` writes the edits of the breaks, and `runCli` reads the arguments and writes the result.
|
|
2672
2979
|
*/
|
|
2673
2980
|
/** This function reads a `package.json` file. */
|
|
2674
2981
|
function readPackage(root, dir) {
|
|
@@ -2784,6 +3091,52 @@ function runChecks(options) {
|
|
|
2784
3091
|
failed: results.some((result) => result.status === "break" || result.status === "error")
|
|
2785
3092
|
};
|
|
2786
3093
|
}
|
|
3094
|
+
/** The most checks of `runFix`. Each check writes at most one edit of each file. */
|
|
3095
|
+
const MAX_PASSES = 20;
|
|
3096
|
+
/**
|
|
3097
|
+
* This function writes the edits of the breaks, and checks again, until no edit applies. In each pass it writes the first
|
|
3098
|
+
* edit of each file whose `before` is the current text of the file. The other edits of that file wait for the next check,
|
|
3099
|
+
* which gives them again from the new text. Thus a fix does not write over a change that it did not see.
|
|
3100
|
+
*/
|
|
3101
|
+
function runFix(options) {
|
|
3102
|
+
const root = resolve(options.root);
|
|
3103
|
+
const changed = [];
|
|
3104
|
+
let result = runChecks(options);
|
|
3105
|
+
let passes = 1;
|
|
3106
|
+
while (passes < MAX_PASSES) {
|
|
3107
|
+
const written = /* @__PURE__ */ new Set();
|
|
3108
|
+
for (const rule of result.rules) for (const edit of rule.breaks.flatMap((item) => item.edits ?? [])) {
|
|
3109
|
+
if (written.has(edit.file)) continue;
|
|
3110
|
+
const path = join(root, edit.file);
|
|
3111
|
+
if ((existsSync(path) ? readFileSync(path, "utf8") : "") !== edit.before) continue;
|
|
3112
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
3113
|
+
writeFileSync(path, edit.after);
|
|
3114
|
+
written.add(edit.file);
|
|
3115
|
+
if (!changed.includes(edit.file)) changed.push(edit.file);
|
|
3116
|
+
}
|
|
3117
|
+
if (written.size === 0) break;
|
|
3118
|
+
result = runChecks(options);
|
|
3119
|
+
passes += 1;
|
|
3120
|
+
}
|
|
3121
|
+
return {
|
|
3122
|
+
changed,
|
|
3123
|
+
passes,
|
|
3124
|
+
result
|
|
3125
|
+
};
|
|
3126
|
+
}
|
|
3127
|
+
/** This function gives a result for JSON: each break without the texts of its edits, and with `fixable`. */
|
|
3128
|
+
function withoutEdits(result) {
|
|
3129
|
+
return {
|
|
3130
|
+
...result,
|
|
3131
|
+
rules: result.rules.map((rule) => ({
|
|
3132
|
+
...rule,
|
|
3133
|
+
breaks: rule.breaks.map(({ edits, ...item }) => ({
|
|
3134
|
+
...item,
|
|
3135
|
+
fixable: (edits ?? []).length > 0
|
|
3136
|
+
}))
|
|
3137
|
+
}))
|
|
3138
|
+
};
|
|
3139
|
+
}
|
|
2787
3140
|
/** The most breaks of one rule in the text output. The JSON output has each break. */
|
|
2788
3141
|
const MAX_SHOWN = 50;
|
|
2789
3142
|
/** This function gives the place of a break as `file:line`. */
|
|
@@ -2804,7 +3157,7 @@ function formatResult(result) {
|
|
|
2804
3157
|
const extra = rule.ignored > 0 ? ` (${rule.ignored} ignored: ${rule.note ?? ""})` : rule.note !== void 0 && rule.status !== "pass" ? ` (${rule.note})` : "";
|
|
2805
3158
|
out.push(`${label[rule.status]} ${rule.id}${rule.breaks.length > 0 ? `: ${rule.breaks.length} break(s)` : ""}${extra}`);
|
|
2806
3159
|
for (const item of rule.breaks.slice(0, MAX_SHOWN)) {
|
|
2807
|
-
out.push(` ${placeOf(item)} ${item.message}`);
|
|
3160
|
+
out.push(` ${placeOf(item)} ${item.message}${(item.edits ?? []).length > 0 ? " (conventions fix writes the fix)" : ""}`);
|
|
2808
3161
|
if (item.fix !== void 0) out.push(` fix: ${item.fix}`);
|
|
2809
3162
|
}
|
|
2810
3163
|
if (rule.breaks.length > MAX_SHOWN) out.push(` ... ${rule.breaks.length - MAX_SHOWN} more. Start \`conventions check --json\` for each break.`);
|
|
@@ -2868,9 +3221,11 @@ function listRules(config, rules = RULES) {
|
|
|
2868
3221
|
}
|
|
2869
3222
|
/** The help text of the bin. */
|
|
2870
3223
|
const USAGE = `Usage: conventions check [options]
|
|
3224
|
+
conventions fix [options]
|
|
2871
3225
|
conventions --list
|
|
2872
3226
|
|
|
2873
3227
|
check Start each rule. Exit code 1 when a rule has a break.
|
|
3228
|
+
fix Write the fixes of the breaks that have one, and check again. Exit code 1 when a break stays.
|
|
2874
3229
|
--list Show each rule: why, fix, options, state and the audit rows that it comes from.
|
|
2875
3230
|
|
|
2876
3231
|
--root <folder> The root of the repository. The default is the current folder.
|
|
@@ -2891,6 +3246,7 @@ var UsageError = class extends Error {};
|
|
|
2891
3246
|
/** This function starts the bin with the arguments `args`, and gives its exit code. */
|
|
2892
3247
|
function runCli(args, io) {
|
|
2893
3248
|
let check = false;
|
|
3249
|
+
let fix = false;
|
|
2894
3250
|
let list = false;
|
|
2895
3251
|
let json = false;
|
|
2896
3252
|
let root = io.cwd;
|
|
@@ -2905,6 +3261,7 @@ function runCli(args, io) {
|
|
|
2905
3261
|
return next;
|
|
2906
3262
|
};
|
|
2907
3263
|
if (arg === "check") check = true;
|
|
3264
|
+
else if (arg === "fix") fix = true;
|
|
2908
3265
|
else if (arg === "--list" || arg === "list") list = true;
|
|
2909
3266
|
else if (arg === "--json") json = true;
|
|
2910
3267
|
else if (arg === "--root") root = resolve(io.cwd, value());
|
|
@@ -2915,7 +3272,7 @@ function runCli(args, io) {
|
|
|
2915
3272
|
return 0;
|
|
2916
3273
|
} else throw new UsageError(`An unknown argument: ${arg}`);
|
|
2917
3274
|
}
|
|
2918
|
-
if (!check && !list) throw new UsageError("Give the command check, or --list.");
|
|
3275
|
+
if (!check && !fix && !list) throw new UsageError("Give the command check or fix, or --list.");
|
|
2919
3276
|
} catch (error) {
|
|
2920
3277
|
if (!(error instanceof UsageError)) throw error;
|
|
2921
3278
|
io.stderr(`conventions: ${error.message}\n\n${USAGE}`);
|
|
@@ -2933,18 +3290,32 @@ function runCli(args, io) {
|
|
|
2933
3290
|
return 0;
|
|
2934
3291
|
}
|
|
2935
3292
|
let result;
|
|
3293
|
+
let fixed;
|
|
2936
3294
|
try {
|
|
2937
|
-
|
|
3295
|
+
const options = {
|
|
2938
3296
|
root,
|
|
2939
3297
|
only,
|
|
2940
3298
|
env: io.env,
|
|
2941
3299
|
...base === void 0 ? {} : { base }
|
|
2942
|
-
}
|
|
3300
|
+
};
|
|
3301
|
+
if (fix) {
|
|
3302
|
+
fixed = runFix(options);
|
|
3303
|
+
result = fixed.result;
|
|
3304
|
+
} else result = runChecks(options);
|
|
2943
3305
|
} catch (error) {
|
|
2944
3306
|
io.stderr(`conventions: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
2945
3307
|
return 1;
|
|
2946
3308
|
}
|
|
2947
|
-
if (json)
|
|
3309
|
+
if (fixed !== void 0 && !json) {
|
|
3310
|
+
const files = fixed.changed.map((file) => ` ${file}\n`).join("");
|
|
3311
|
+
io.stdout(fixed.changed.length === 0 ? "conventions fix: no break has a fix that applies.\n" : `conventions fix: changed ${fixed.changed.length} file(s) in ${fixed.passes} check(s):\n${files}\n`);
|
|
3312
|
+
}
|
|
3313
|
+
const shown = fixed === void 0 ? withoutEdits(result) : {
|
|
3314
|
+
changed: fixed.changed,
|
|
3315
|
+
passes: fixed.passes,
|
|
3316
|
+
...withoutEdits(result)
|
|
3317
|
+
};
|
|
3318
|
+
if (json) io.stdout(`${JSON.stringify(shown, null, 2)}\n`);
|
|
2948
3319
|
else {
|
|
2949
3320
|
if (io.env["GITHUB_ACTIONS"] === "true") io.stdout(annotations(result));
|
|
2950
3321
|
io.stdout(formatResult(result));
|
|
@@ -2953,6 +3324,6 @@ function runCli(args, io) {
|
|
|
2953
3324
|
if (summary) appendFileSync(summary, summaryMarkdown(result));
|
|
2954
3325
|
return result.failed ? 1 : 0;
|
|
2955
3326
|
}
|
|
2956
|
-
export {
|
|
3327
|
+
export { runGit as $, roadmapParses as A, STRICT_OPTIONS as B, isSourcePath as C, runnerBudget as D, repositoryOfRemote as E, pinnedGitDeps as F, hasFile as G, DEPENDENCY_FIELDS as H, DEFAULT_ALLOWED as I, lineOf as J, inFolder as K, HOME_PATTERNS as L, releaseFiles as M, isGitSpecifier as N, scheduleMinute as O, isPinned as P, replaceLine as Q, noLocalPaths as R, tsconfigTest as S, sourceMain as T, cleanPath as U, cuePreset as V, codePackages as W, parseJsonc as X, matchesAny as Y, readJsonc as Z, configsOfScript as _, listRules as a, defaultOptions as at, testsRequired as b, runCli as c, RULES as d, specifiersOf as et, workspaceProtocol as f, typedScripts as g, trustPolicy as h, formatResult as i, workspaceGlobs as it, requiredScripts as j, roadmapOfLine as k, runFix as l, TRAIN_SCOPES as m, annotations as n, globToRegExp as nt, readConfig as o, parseConfig as ot, IGNORE_AFTER as p, keyLine as q, createContext as r, packageFolders as rt, runChecks as s, USAGE as t, globFolders as tt, summaryMarkdown as u, scriptsOf as v, pathsOf as w, hasTests as x, typedFiles as y, noBuildOutput as z };
|
|
2957
3328
|
|
|
2958
|
-
//# sourceMappingURL=run-
|
|
3329
|
+
//# sourceMappingURL=run-CRjXzR_6.js.map
|