@mark1russell7/conventions 0.36.1 → 0.37.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 +6 -3
- package/build/cli.js +1 -1
- package/build/index.d.ts +20 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -2
- package/build/{run-D4nX8sbO.js → run-DWyPhbeH.js} +433 -139
- package/build/run-DWyPhbeH.js.map +1 -0
- package/package.json +2 -2
- package/build/run-D4nX8sbO.js.map +0 -1
|
@@ -9,6 +9,7 @@ import { parseAllDocuments } from "yaml";
|
|
|
9
9
|
const RULE_FIELDS = [
|
|
10
10
|
"off",
|
|
11
11
|
"ignore",
|
|
12
|
+
"generated",
|
|
12
13
|
"reason"
|
|
13
14
|
];
|
|
14
15
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -50,6 +51,9 @@ function parseConfig(value, rules) {
|
|
|
50
51
|
const reason = entry["reason"];
|
|
51
52
|
if (reason !== void 0 && (typeof reason !== "string" || reason.trim() === "")) throw new Error(`${where}.reason must be text.`);
|
|
52
53
|
if (ignore.length > 0 && reason === void 0) throw new Error(`${where}.ignore needs a reason: add "reason": "<why these files are an exception>".`);
|
|
54
|
+
const generated = entry["generated"] ?? [];
|
|
55
|
+
if (!isStrings(generated)) throw new Error(`${where}.generated must be an array of globs.`);
|
|
56
|
+
if (generated.length > 0 && reason === void 0) throw new Error(`${where}.generated needs a reason: add "reason": "<which build makes these files>".`);
|
|
53
57
|
const options = { ...defaultOptions(rule) };
|
|
54
58
|
const changed = [];
|
|
55
59
|
for (const [name, option] of Object.entries(entry)) {
|
|
@@ -67,6 +71,7 @@ function parseConfig(value, rules) {
|
|
|
67
71
|
result[id] = {
|
|
68
72
|
...off === void 0 ? {} : { off },
|
|
69
73
|
ignore,
|
|
74
|
+
...generated.length === 0 ? {} : { generated },
|
|
70
75
|
...reason === void 0 ? {} : { reason },
|
|
71
76
|
options
|
|
72
77
|
};
|
|
@@ -2206,6 +2211,325 @@ const securityOneJob = {
|
|
|
2206
2211
|
return breaks;
|
|
2207
2212
|
}
|
|
2208
2213
|
};
|
|
2214
|
+
// src/rules/shared-ci.ts
|
|
2215
|
+
/**
|
|
2216
|
+
* The rule `shared-ci`: a repository uses the shared workflows and actions of the template, and keeps no copy of them.
|
|
2217
|
+
* Its `ci.yml` uses the shared workflow `reusable-ci.yml` of the template. No workflow file and no action of the
|
|
2218
|
+
* repository has the name of a shared workflow or a shared action. The template itself is the home, so the rule does
|
|
2219
|
+
* not examine it.
|
|
2220
|
+
*/
|
|
2221
|
+
/** The shared workflows of the template, by file name. */
|
|
2222
|
+
const SHARED_WORKFLOWS = [
|
|
2223
|
+
"reusable-ai-review.yml",
|
|
2224
|
+
"reusable-ci.yml",
|
|
2225
|
+
"reusable-codex-review.yml",
|
|
2226
|
+
"reusable-mutation.yml",
|
|
2227
|
+
"reusable-pages.yml",
|
|
2228
|
+
"reusable-release-build.yml",
|
|
2229
|
+
"reusable-release-tag.yml",
|
|
2230
|
+
"reusable-security.yml"
|
|
2231
|
+
];
|
|
2232
|
+
/** The shared actions of the template, by folder name under `.github/actions`. */
|
|
2233
|
+
const SHARED_ACTIONS = [
|
|
2234
|
+
"changes",
|
|
2235
|
+
"changeset-check",
|
|
2236
|
+
"coverage",
|
|
2237
|
+
"data-stamps",
|
|
2238
|
+
"gate-summary",
|
|
2239
|
+
"green-main",
|
|
2240
|
+
"npm-publish",
|
|
2241
|
+
"security-scan",
|
|
2242
|
+
"setup-playwright",
|
|
2243
|
+
"site-check",
|
|
2244
|
+
"site-pages"
|
|
2245
|
+
];
|
|
2246
|
+
/** The `uses` value of a job that calls the shared CI, with no pin. */
|
|
2247
|
+
const SHARED_CI = "mark1russell7/template/.github/workflows/reusable-ci.yml";
|
|
2248
|
+
/** The action folder of a path: `.github/actions/<name>/action.yml` gives `<name>`. */
|
|
2249
|
+
const ACTION = /^\.github\/actions\/([^/]+)\//;
|
|
2250
|
+
/** The file name of a path. */
|
|
2251
|
+
const baseName = (path) => path.slice(path.lastIndexOf("/") + 1);
|
|
2252
|
+
/** This function tells if a job of a workflow text uses the shared CI of the template. */
|
|
2253
|
+
function callsSharedCi(file, text) {
|
|
2254
|
+
return readWorkflow(file, text).jobs.some((job) => job.steps.some((step) => step.uses === SHARED_CI));
|
|
2255
|
+
}
|
|
2256
|
+
const sharedCi = {
|
|
2257
|
+
id: "shared-ci",
|
|
2258
|
+
title: "`ci.yml` calls the shared workflow `reusable-ci.yml` of the template, and no workflow or action copies a shared one.",
|
|
2259
|
+
reason: "The shared CI is the one place where each check of a repository is set: the typecheck, the tests, the conventions, the API report and the summary check CI OK that the ruleset needs. A ci.yml with its own steps, or a copy of a shared workflow or action, does not get the fixes and the new checks of the template, and it drifts with no sign. On 2026-11-07, 3 of 19 repositories of the account ran CI steps of their own, and the rule was only text in each CLAUDE.md.",
|
|
2260
|
+
fix: "Make ci.yml call mark1russell7/template/.github/workflows/reusable-ci.yml at a pinned commit, and give the differences as its inputs (CI.md). Remove the local copy of a shared workflow or action, and call the one of the template. A repository that cannot call the shared CI turns the rule off with its reason.",
|
|
2261
|
+
sources: [
|
|
2262
|
+
{
|
|
2263
|
+
repo: "template",
|
|
2264
|
+
rule: "shared-workflows",
|
|
2265
|
+
doc: "CLAUDE.md: the workflows use the shared workflows and actions of the template; a repository changes only the inputs of its callers"
|
|
2266
|
+
},
|
|
2267
|
+
{
|
|
2268
|
+
repo: "template",
|
|
2269
|
+
rule: "ci",
|
|
2270
|
+
doc: "CI.md, CI: a caller of reusable-ci.yml needs no inputs, and gives each difference as an input"
|
|
2271
|
+
},
|
|
2272
|
+
{
|
|
2273
|
+
repo: "highways",
|
|
2274
|
+
rule: "ci",
|
|
2275
|
+
doc: ".github/workflows/ci.yml:1: the job ci is the shared CI (reusable-ci.yml, CI.md)"
|
|
2276
|
+
},
|
|
2277
|
+
{
|
|
2278
|
+
repo: "packing",
|
|
2279
|
+
rule: "ci",
|
|
2280
|
+
doc: ".github/workflows/ci.yml:1: the job ci is the shared CI (reusable-ci.yml, CI.md)"
|
|
2281
|
+
},
|
|
2282
|
+
{
|
|
2283
|
+
repo: "ste-lint",
|
|
2284
|
+
rule: "ci",
|
|
2285
|
+
doc: ".github/workflows/ci.yml (2026-11-07): its own steps, no call of reusable-ci.yml; the same in optional and lag"
|
|
2286
|
+
}
|
|
2287
|
+
],
|
|
2288
|
+
options: {
|
|
2289
|
+
home: {
|
|
2290
|
+
type: "strings",
|
|
2291
|
+
default: ["template-monorepo"],
|
|
2292
|
+
description: "The names of the root packages that own the shared workflows. The rule does not examine them."
|
|
2293
|
+
},
|
|
2294
|
+
ciFile: {
|
|
2295
|
+
type: "string",
|
|
2296
|
+
default: ".github/workflows/ci.yml",
|
|
2297
|
+
description: "The workflow file that must call the shared CI."
|
|
2298
|
+
}
|
|
2299
|
+
},
|
|
2300
|
+
check(context, options) {
|
|
2301
|
+
const home = options["home"];
|
|
2302
|
+
const name = context.rootPackage.manifest["name"];
|
|
2303
|
+
if (typeof name === "string" && home.includes(name)) return { skipped: `the repository is the home of the shared workflows (${name})` };
|
|
2304
|
+
const files = context.gitFiles();
|
|
2305
|
+
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
2306
|
+
const breaks = [];
|
|
2307
|
+
for (const file of files.filter((path) => WORKFLOW$1.test(path)).sort(byCode)) if (SHARED_WORKFLOWS.includes(baseName(file))) breaks.push({
|
|
2308
|
+
file,
|
|
2309
|
+
message: `${file} has the name of a shared workflow of the template: it is a local copy, which does not get the fixes of the template.`
|
|
2310
|
+
});
|
|
2311
|
+
const actions = /* @__PURE__ */ new Set();
|
|
2312
|
+
for (const file of files) {
|
|
2313
|
+
const folder = ACTION.exec(file)?.[1];
|
|
2314
|
+
if (folder !== void 0 && SHARED_ACTIONS.includes(folder) && !actions.has(folder)) {
|
|
2315
|
+
actions.add(folder);
|
|
2316
|
+
breaks.push({
|
|
2317
|
+
file: `.github/actions/${folder}`,
|
|
2318
|
+
message: `.github/actions/${folder} has the name of a shared action of the template: it is a local copy, which does not get the fixes of the template.`
|
|
2319
|
+
});
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
const ciFile = options["ciFile"];
|
|
2323
|
+
const path = join(context.root, ciFile);
|
|
2324
|
+
if (!existsSync(path)) breaks.push({
|
|
2325
|
+
file: ciFile,
|
|
2326
|
+
message: `${ciFile} is missing, so no job calls the shared CI of the template.`
|
|
2327
|
+
});
|
|
2328
|
+
else if (!callsSharedCi(ciFile, readFileSync(path, "utf8"))) breaks.push({
|
|
2329
|
+
file: ciFile,
|
|
2330
|
+
message: `No job of ${ciFile} calls ${SHARED_CI}: the CI runs its own steps, and does not get the checks of the template.`
|
|
2331
|
+
});
|
|
2332
|
+
return breaks;
|
|
2333
|
+
}
|
|
2334
|
+
};
|
|
2335
|
+
// src/rules/tsconfig-test.ts
|
|
2336
|
+
/**
|
|
2337
|
+
* The rule `tsconfig-test`: each TypeScript package has a `tsconfig.test.json`, and its typecheck
|
|
2338
|
+
* examines it.
|
|
2339
|
+
*/
|
|
2340
|
+
/** The ends of the name of a test file: `.test.` or `.spec.`, then an extension of JavaScript or TypeScript. */
|
|
2341
|
+
const TEST_ENDS = ["test", "spec"].flatMap((kind) => [
|
|
2342
|
+
"",
|
|
2343
|
+
"c",
|
|
2344
|
+
"m"
|
|
2345
|
+
].flatMap((module) => ["j", "t"].flatMap((lang) => ["", "x"].map((jsx) => `.${kind}.${module}${lang}s${jsx}`))));
|
|
2346
|
+
/**
|
|
2347
|
+
* This function tells if a path is a test file: `*.test.*` or `*.spec.*` of JavaScript or TypeScript, or a file in a
|
|
2348
|
+
* folder `__tests__`. It uses string operations, with no regular expression, so a long path takes linear time.
|
|
2349
|
+
*/
|
|
2350
|
+
function isTestFile(path) {
|
|
2351
|
+
const segments = path.split("/");
|
|
2352
|
+
const name = segments[segments.length - 1] ?? "";
|
|
2353
|
+
if (name !== "" && segments.slice(0, -1).includes("__tests__")) return true;
|
|
2354
|
+
return TEST_ENDS.some((end) => name.length > end.length && name.endsWith(end));
|
|
2355
|
+
}
|
|
2356
|
+
/** This function tells if git tracks a test file in the package folder `folder` (`""` is the root). */
|
|
2357
|
+
function hasTests(files, folder) {
|
|
2358
|
+
const prefix = folder === "" ? "" : `${folder}/`;
|
|
2359
|
+
return files.some((path) => path.startsWith(prefix) && isTestFile(path.slice(prefix.length)));
|
|
2360
|
+
}
|
|
2361
|
+
const tsconfigTest = {
|
|
2362
|
+
id: "tsconfig-test",
|
|
2363
|
+
title: "Each package with a `tsconfig.json` and test files has a `tsconfig.test.json`, and its `typecheck` script examines it.",
|
|
2364
|
+
reason: "The build config leaves out the tests. Without a second config, `pnpm typecheck` does not examine the tests, and a type error in a test hides until the test runs.",
|
|
2365
|
+
fix: "Add `tsconfig.test.json` (extends `./tsconfig.json`, includes the tests, `noEmit`), and set the script `typecheck` to `tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json`. Keep `--noEmit` on the first call when the build config emits, so that a typecheck writes no build output.",
|
|
2366
|
+
sources: [
|
|
2367
|
+
{
|
|
2368
|
+
repo: "coeval",
|
|
2369
|
+
rule: "package-tsconfig-test",
|
|
2370
|
+
doc: "CLAUDE.md:18"
|
|
2371
|
+
},
|
|
2372
|
+
{
|
|
2373
|
+
repo: "coeval",
|
|
2374
|
+
rule: "tsconfig-test",
|
|
2375
|
+
doc: "CLAUDE.md:18"
|
|
2376
|
+
},
|
|
2377
|
+
{
|
|
2378
|
+
repo: "crawler",
|
|
2379
|
+
rule: "pkg-tsconfig-test",
|
|
2380
|
+
doc: "CLAUDE.md:18"
|
|
2381
|
+
},
|
|
2382
|
+
{
|
|
2383
|
+
repo: "crawler",
|
|
2384
|
+
rule: "tsconfig-test",
|
|
2385
|
+
doc: "CLAUDE.md:18"
|
|
2386
|
+
},
|
|
2387
|
+
{
|
|
2388
|
+
repo: "headroom",
|
|
2389
|
+
rule: "tsconfig-test",
|
|
2390
|
+
doc: "CLAUDE.md:32"
|
|
2391
|
+
},
|
|
2392
|
+
{
|
|
2393
|
+
repo: "headroom",
|
|
2394
|
+
rule: "tsconfig-test-per-package",
|
|
2395
|
+
doc: "CLAUDE.md:32"
|
|
2396
|
+
},
|
|
2397
|
+
{
|
|
2398
|
+
repo: "Vex",
|
|
2399
|
+
rule: "package-tsconfig-test",
|
|
2400
|
+
doc: "CLAUDE.md:23"
|
|
2401
|
+
},
|
|
2402
|
+
{
|
|
2403
|
+
repo: "Vex",
|
|
2404
|
+
rule: "tsconfig-test",
|
|
2405
|
+
doc: "CLAUDE.md:23"
|
|
2406
|
+
}
|
|
2407
|
+
],
|
|
2408
|
+
options: { file: {
|
|
2409
|
+
type: "string",
|
|
2410
|
+
default: "tsconfig.test.json",
|
|
2411
|
+
description: "The name of the config of the tests."
|
|
2412
|
+
} },
|
|
2413
|
+
check(context, options) {
|
|
2414
|
+
const file = typeof options["file"] === "string" ? options["file"] : "tsconfig.test.json";
|
|
2415
|
+
const tracked = context.gitFiles();
|
|
2416
|
+
const breaks = [];
|
|
2417
|
+
for (const info of codePackages(context)) {
|
|
2418
|
+
if (!hasFile(info.dir, "tsconfig.json")) continue;
|
|
2419
|
+
if (tracked !== void 0 && !hasTests(tracked, info.folder)) continue;
|
|
2420
|
+
if (!hasFile(info.dir, file)) {
|
|
2421
|
+
breaks.push({
|
|
2422
|
+
file: inFolder(info.folder, file),
|
|
2423
|
+
message: `The package has a tsconfig.json and no ${file}.`
|
|
2424
|
+
});
|
|
2425
|
+
continue;
|
|
2426
|
+
}
|
|
2427
|
+
const scripts = info.manifest["scripts"];
|
|
2428
|
+
const typecheck = typeof scripts === "object" && scripts !== null ? scripts["typecheck"] : void 0;
|
|
2429
|
+
if (typeof typecheck === "string" && !typecheck.includes(file)) {
|
|
2430
|
+
const line = lineOf(info.text, "\"typecheck\"");
|
|
2431
|
+
breaks.push({
|
|
2432
|
+
file: info.file,
|
|
2433
|
+
...line === void 0 ? {} : { line },
|
|
2434
|
+
message: `The script typecheck ("${typecheck}") does not examine ${file}.`,
|
|
2435
|
+
fix: `Add \`tsc -p ${file}\` to the script typecheck.`
|
|
2436
|
+
});
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
return breaks;
|
|
2440
|
+
}
|
|
2441
|
+
};
|
|
2442
|
+
// src/rules/service-run-main.ts
|
|
2443
|
+
/**
|
|
2444
|
+
* The rule `service-run-main`: in a server package, only the entry `src/main.ts` starts the service with `run()`. A
|
|
2445
|
+
* server package is a package with a dependency on `@mark1russell7/service` and a file `src/main.ts`, as the preset
|
|
2446
|
+
* `service` of `pnpm package add` writes it. The other source files declare the service and give it to the entry.
|
|
2447
|
+
*/
|
|
2448
|
+
/** The package of the service. */
|
|
2449
|
+
const SERVICE_PACKAGE = "@mark1russell7/service";
|
|
2450
|
+
/** An import of the service package or of one of its entries. */
|
|
2451
|
+
const SERVICE_IMPORT = /\bfrom\s+["']@mark1russell7\/service(\/[^"']*)?["']|\bimport\s*\(\s*["']@mark1russell7\/service(\/[^"']*)?["']\s*\)/;
|
|
2452
|
+
/** A call of `run(` on a value, but not on `this`. */
|
|
2453
|
+
const RUN_CALL = /(?<!\bthis)\.run\s*\(/;
|
|
2454
|
+
/** The source files that the rule reads. */
|
|
2455
|
+
const SOURCE = /\.(c|m)?tsx?$/;
|
|
2456
|
+
/** This function gives the lines (from 1) of the calls of `run(` in a source text that imports the service package. */
|
|
2457
|
+
function runCalls(text) {
|
|
2458
|
+
if (!SERVICE_IMPORT.test(text)) return [];
|
|
2459
|
+
const found = [];
|
|
2460
|
+
text.split(/\r?\n/).forEach((line, index) => {
|
|
2461
|
+
const comment = line.indexOf("//");
|
|
2462
|
+
const code = comment < 0 ? line : line.slice(0, comment);
|
|
2463
|
+
const trimmed = code.trimStart();
|
|
2464
|
+
if (trimmed.startsWith("*") || trimmed.startsWith("/*")) return;
|
|
2465
|
+
if (RUN_CALL.test(code)) found.push(index + 1);
|
|
2466
|
+
});
|
|
2467
|
+
return found;
|
|
2468
|
+
}
|
|
2469
|
+
/** This function tells if a manifest has a dependency on the service package. */
|
|
2470
|
+
const dependsOnService = (manifest) => {
|
|
2471
|
+
const dependencies = manifest["dependencies"];
|
|
2472
|
+
return typeof dependencies === "object" && dependencies !== null && "@mark1russell7/service" in dependencies;
|
|
2473
|
+
};
|
|
2474
|
+
const serviceRunMain = {
|
|
2475
|
+
id: "service-run-main",
|
|
2476
|
+
title: "In a server package, only the entry `src/main.ts` starts the service with `run()`.",
|
|
2477
|
+
reason: "run() of @mark1russell7/service owns the process: it starts the listeners, it reads the signals, and it ends the process. A module that starts it cannot be imported by a test or by a second entry without a second server. When only the entry starts it, each other module gives a service that a test can start, check and stop.",
|
|
2478
|
+
fix: "Move the call of run() to src/main.ts. Export the service (or a function that makes it) from the module, and start it in the entry.",
|
|
2479
|
+
sources: [
|
|
2480
|
+
{
|
|
2481
|
+
repo: "template",
|
|
2482
|
+
rule: "service-preset",
|
|
2483
|
+
doc: "CLAUDE.md: make a server package with --preset=service; only its entry src/main.ts uses run() of @mark1russell7/service"
|
|
2484
|
+
},
|
|
2485
|
+
{
|
|
2486
|
+
repo: "template",
|
|
2487
|
+
rule: "service-preset",
|
|
2488
|
+
doc: "packages/cli/src/commands/package/add.ts: the preset service writes src/main.ts and the script start"
|
|
2489
|
+
},
|
|
2490
|
+
{
|
|
2491
|
+
repo: "systems",
|
|
2492
|
+
rule: "service-run-main",
|
|
2493
|
+
doc: "packages/reference/src/main.ts:3: only this file starts run()"
|
|
2494
|
+
},
|
|
2495
|
+
{
|
|
2496
|
+
repo: "vex",
|
|
2497
|
+
rule: "service-run-main",
|
|
2498
|
+
doc: "packages/mcp/src/main.ts: the one call of run() of the package"
|
|
2499
|
+
}
|
|
2500
|
+
],
|
|
2501
|
+
options: { main: {
|
|
2502
|
+
type: "string",
|
|
2503
|
+
default: "src/main.ts",
|
|
2504
|
+
description: "The entry of a server package, the one file that starts the service."
|
|
2505
|
+
} },
|
|
2506
|
+
check(context, options) {
|
|
2507
|
+
const main = typeof options["main"] === "string" ? options["main"] : "src/main.ts";
|
|
2508
|
+
const tracked = context.gitFiles();
|
|
2509
|
+
if (tracked === void 0) return { skipped: "the root is not in a git repository" };
|
|
2510
|
+
const breaks = [];
|
|
2511
|
+
for (const info of codePackages(context)) {
|
|
2512
|
+
if (!dependsOnService(info.manifest) || !hasFile(info.dir, main)) continue;
|
|
2513
|
+
const prefix = info.folder === "" ? "" : `${info.folder}/`;
|
|
2514
|
+
const entry = inFolder(info.folder, main);
|
|
2515
|
+
const own = tracked.filter((path) => path.startsWith(`${prefix}src/`) && SOURCE.test(path) && !/\.d\.(c|m)?ts$/.test(path) && path !== entry && !isTestFile(path.slice(prefix.length)));
|
|
2516
|
+
for (const file of own.sort(byCode)) {
|
|
2517
|
+
let text;
|
|
2518
|
+
try {
|
|
2519
|
+
text = readFileSync(join(context.root, file), "utf8");
|
|
2520
|
+
} catch {
|
|
2521
|
+
continue;
|
|
2522
|
+
}
|
|
2523
|
+
for (const line of runCalls(text)) breaks.push({
|
|
2524
|
+
file,
|
|
2525
|
+
line,
|
|
2526
|
+
message: `${file} starts the service with run(). In a server package only ${entry} does.`
|
|
2527
|
+
});
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
return breaks;
|
|
2531
|
+
}
|
|
2532
|
+
};
|
|
2209
2533
|
// src/change.ts
|
|
2210
2534
|
/**
|
|
2211
2535
|
* The change that a check examines: the option `--base`, the merge commit of a pull request, or a push to the default
|
|
@@ -9110,7 +9434,10 @@ const noBuildOutput = {
|
|
|
9110
9434
|
};
|
|
9111
9435
|
// src/rules/no-local-paths.ts
|
|
9112
9436
|
/**
|
|
9113
|
-
* The rule `no-local-paths`: no tracked file names the home folder of a user of a computer.
|
|
9437
|
+
* The rule `no-local-paths`: no tracked file names the home folder of a user of a computer. The commit messages of a
|
|
9438
|
+
* change and the title and the body of its pull request do not name one either. The same is true for each private
|
|
9439
|
+
* pattern of the environment variable `CONVENTIONS_PRIVATE_PATTERNS`. A break of a private pattern does not show the
|
|
9440
|
+
* text or the pattern, because a public log must not name them.
|
|
9114
9441
|
*/
|
|
9115
9442
|
/** The extensions of files that are not text. The rule does not read them. */
|
|
9116
9443
|
const BINARY = new Set(".png .jpg .jpeg .gif .webp .avif .ico .bmp .tiff .pdf .zip .gz .tgz .bz2 .xz .7z .tar .woff .woff2 .ttf .otf .eot .mp3 .mp4 .webm .mov .wav .ogg .wasm .node .exe .dll .so .dylib .bin .db .sqlite .duckdb".split(" "));
|
|
@@ -9143,9 +9470,56 @@ const HOME_PATTERNS = [
|
|
|
9143
9470
|
/(?<![\w.~-])\/Users\/(?<user>[^/\s"'`<>|:*?%$(){}[\],;]+)/g,
|
|
9144
9471
|
/(?<![\w.~-])\/home\/(?<user>[^/\s"'`<>|:*?%$(){}[\],;]+)/g
|
|
9145
9472
|
];
|
|
9473
|
+
/** The name of the environment variable of the private patterns. */
|
|
9474
|
+
const PRIVATE_PATTERNS_VARIABLE = "CONVENTIONS_PRIVATE_PATTERNS";
|
|
9475
|
+
/** This function gives the private patterns of the environment variable, with the line of each (from 1). */
|
|
9476
|
+
function privatePatterns(env) {
|
|
9477
|
+
return (env["CONVENTIONS_PRIVATE_PATTERNS"] ?? "").split("\n").map((source, index) => ({
|
|
9478
|
+
source: source.trim(),
|
|
9479
|
+
line: index + 1
|
|
9480
|
+
})).filter((pattern) => pattern.source !== "");
|
|
9481
|
+
}
|
|
9482
|
+
/**
|
|
9483
|
+
* This function gives the texts of the change that are not files. They are each commit message of a pull request (or of the
|
|
9484
|
+
* range of `--base`). They are also the title and the body of the pull request, from the event file of GitHub Actions.
|
|
9485
|
+
*/
|
|
9486
|
+
function changeTexts(context) {
|
|
9487
|
+
const texts = [];
|
|
9488
|
+
const range = rangeOf(context);
|
|
9489
|
+
if (!("skipped" in range)) {
|
|
9490
|
+
const log = context.git([
|
|
9491
|
+
"log",
|
|
9492
|
+
"--no-merges",
|
|
9493
|
+
"--format=%H%x00%B%x1e",
|
|
9494
|
+
...range.log
|
|
9495
|
+
]) ?? "";
|
|
9496
|
+
for (const entry of log.split("")) {
|
|
9497
|
+
const [sha, message] = entry.replace(/^\s+/, "").split("\0");
|
|
9498
|
+
if (sha !== void 0 && sha !== "" && message !== void 0) texts.push({
|
|
9499
|
+
name: `commit ${sha.slice(0, 12)}`,
|
|
9500
|
+
text: message
|
|
9501
|
+
});
|
|
9502
|
+
}
|
|
9503
|
+
}
|
|
9504
|
+
const file = context.env["GITHUB_EVENT_PATH"];
|
|
9505
|
+
if (file !== void 0 && file !== "" && existsSync(file)) try {
|
|
9506
|
+
const event = JSON.parse(readFileSync(file, "utf8"));
|
|
9507
|
+
const title = event.pull_request?.title;
|
|
9508
|
+
const body = event.pull_request?.body;
|
|
9509
|
+
if (typeof title === "string") texts.push({
|
|
9510
|
+
name: "pull request title",
|
|
9511
|
+
text: title
|
|
9512
|
+
});
|
|
9513
|
+
if (typeof body === "string") texts.push({
|
|
9514
|
+
name: "pull request body",
|
|
9515
|
+
text: body
|
|
9516
|
+
});
|
|
9517
|
+
} catch {}
|
|
9518
|
+
return texts;
|
|
9519
|
+
}
|
|
9146
9520
|
const noLocalPaths = {
|
|
9147
9521
|
id: "no-local-paths",
|
|
9148
|
-
title: "No tracked file has the home folder of a user (`C:\\Users\\<name>`, `/Users/<name>`, `/home/<name>`).",
|
|
9522
|
+
title: "No tracked file, commit message of the change or text of its pull request has a private pattern or the home folder of a user (`C:\\Users\\<name>`, `/Users/<name>`, `/home/<name>`).",
|
|
9149
9523
|
reason: "A public file must not name a computer, a user or a path of a computer. A local path also works only on one computer.",
|
|
9150
9524
|
fix: "Use a path relative to the repository, `~`, an environment variable, or a placeholder such as `<you>`.",
|
|
9151
9525
|
sources: [
|
|
@@ -9191,10 +9565,41 @@ const noLocalPaths = {
|
|
|
9191
9565
|
const files = context.gitFiles();
|
|
9192
9566
|
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
9193
9567
|
const allowed = new Set([...DEFAULT_ALLOWED, ...Array.isArray(options["allow"]) ? options["allow"] : []].map((name) => name.toLowerCase()));
|
|
9194
|
-
const
|
|
9195
|
-
|
|
9568
|
+
const extra = [...(Array.isArray(options["patterns"]) ? options["patterns"] : []).map((source) => ({ regex: new RegExp(source, "g") })), ...privatePatterns(context.env).map((pattern) => ({
|
|
9569
|
+
regex: new RegExp(pattern.source, "g"),
|
|
9570
|
+
privateLine: pattern.line
|
|
9571
|
+
}))];
|
|
9196
9572
|
const rootFile = context.rootPackage.file;
|
|
9197
9573
|
const breaks = [];
|
|
9574
|
+
/** This function adds the breaks of the extra patterns on one line. A break of a private pattern shows no text. */
|
|
9575
|
+
const extraBreaks = (file, line, at, isRootFile) => {
|
|
9576
|
+
for (const pattern of extra) {
|
|
9577
|
+
if (isRootFile && pattern.privateLine === void 0 && line.trim().replace(/,$/, "") === JSON.stringify(pattern.regex.source)) continue;
|
|
9578
|
+
for (const match of line.matchAll(pattern.regex)) breaks.push(pattern.privateLine === void 0 ? {
|
|
9579
|
+
file,
|
|
9580
|
+
line: at,
|
|
9581
|
+
message: `The text "${match[0]}" matches the pattern ${pattern.regex.source}.`,
|
|
9582
|
+
fix: "Remove the text."
|
|
9583
|
+
} : {
|
|
9584
|
+
file,
|
|
9585
|
+
line: at,
|
|
9586
|
+
message: `A text matches the private pattern on line ${String(pattern.privateLine)} of ${PRIVATE_PATTERNS_VARIABLE}.`,
|
|
9587
|
+
fix: "Remove the text. The check does not show the text, because the pattern is private."
|
|
9588
|
+
});
|
|
9589
|
+
}
|
|
9590
|
+
};
|
|
9591
|
+
/** This function adds the breaks of the home folders on one line. */
|
|
9592
|
+
const homeBreaks = (file, line, at) => {
|
|
9593
|
+
for (const pattern of HOME_PATTERNS) for (const match of line.matchAll(pattern)) {
|
|
9594
|
+
const user = match.groups?.["user"] ?? "";
|
|
9595
|
+
if (user.length < 2 || allowed.has(user.toLowerCase())) continue;
|
|
9596
|
+
breaks.push({
|
|
9597
|
+
file,
|
|
9598
|
+
line: at,
|
|
9599
|
+
message: `The text "${match[0]}" is the home folder of a user.`
|
|
9600
|
+
});
|
|
9601
|
+
}
|
|
9602
|
+
};
|
|
9198
9603
|
for (const file of files) {
|
|
9199
9604
|
if (BINARY.has(extname(file).toLowerCase())) continue;
|
|
9200
9605
|
const path = join(context.root, file);
|
|
@@ -9209,25 +9614,15 @@ const noLocalPaths = {
|
|
|
9209
9614
|
const lines = text.split(/\r?\n/);
|
|
9210
9615
|
for (let index = 0; index < lines.length; index++) {
|
|
9211
9616
|
const line = lines[index] ?? "";
|
|
9212
|
-
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
}
|
|
9222
|
-
for (const pattern of extra) {
|
|
9223
|
-
if (file === rootFile && line.trim().replace(/,$/, "") === JSON.stringify(pattern.source)) continue;
|
|
9224
|
-
for (const match of line.matchAll(pattern)) breaks.push({
|
|
9225
|
-
file,
|
|
9226
|
-
line: index + 1,
|
|
9227
|
-
message: `The text "${match[0]}" matches the pattern ${pattern.source}.`,
|
|
9228
|
-
fix: "Remove the text."
|
|
9229
|
-
});
|
|
9230
|
-
}
|
|
9617
|
+
if (!(file === rootFile && /^\s*"(?:reason|off)"\s*:/.test(line))) homeBreaks(file, line, index + 1);
|
|
9618
|
+
extraBreaks(file, line, index + 1, file === rootFile);
|
|
9619
|
+
}
|
|
9620
|
+
}
|
|
9621
|
+
for (const change of changeTexts(context)) {
|
|
9622
|
+
const lines = change.text.split(/\r?\n/);
|
|
9623
|
+
for (let index = 0; index < lines.length; index++) {
|
|
9624
|
+
homeBreaks(change.name, lines[index] ?? "", index + 1);
|
|
9625
|
+
extraBreaks(change.name, lines[index] ?? "", index + 1, false);
|
|
9231
9626
|
}
|
|
9232
9627
|
}
|
|
9233
9628
|
return breaks;
|
|
@@ -11787,113 +12182,6 @@ const sourceMain = {
|
|
|
11787
12182
|
return breaks;
|
|
11788
12183
|
}
|
|
11789
12184
|
};
|
|
11790
|
-
// src/rules/tsconfig-test.ts
|
|
11791
|
-
/**
|
|
11792
|
-
* The rule `tsconfig-test`: each TypeScript package has a `tsconfig.test.json`, and its typecheck
|
|
11793
|
-
* examines it.
|
|
11794
|
-
*/
|
|
11795
|
-
/** The ends of the name of a test file: `.test.` or `.spec.`, then an extension of JavaScript or TypeScript. */
|
|
11796
|
-
const TEST_ENDS = ["test", "spec"].flatMap((kind) => [
|
|
11797
|
-
"",
|
|
11798
|
-
"c",
|
|
11799
|
-
"m"
|
|
11800
|
-
].flatMap((module) => ["j", "t"].flatMap((lang) => ["", "x"].map((jsx) => `.${kind}.${module}${lang}s${jsx}`))));
|
|
11801
|
-
/**
|
|
11802
|
-
* This function tells if a path is a test file: `*.test.*` or `*.spec.*` of JavaScript or TypeScript, or a file in a
|
|
11803
|
-
* folder `__tests__`. It uses string operations, with no regular expression, so a long path takes linear time.
|
|
11804
|
-
*/
|
|
11805
|
-
function isTestFile(path) {
|
|
11806
|
-
const segments = path.split("/");
|
|
11807
|
-
const name = segments[segments.length - 1] ?? "";
|
|
11808
|
-
if (name !== "" && segments.slice(0, -1).includes("__tests__")) return true;
|
|
11809
|
-
return TEST_ENDS.some((end) => name.length > end.length && name.endsWith(end));
|
|
11810
|
-
}
|
|
11811
|
-
/** This function tells if git tracks a test file in the package folder `folder` (`""` is the root). */
|
|
11812
|
-
function hasTests(files, folder) {
|
|
11813
|
-
const prefix = folder === "" ? "" : `${folder}/`;
|
|
11814
|
-
return files.some((path) => path.startsWith(prefix) && isTestFile(path.slice(prefix.length)));
|
|
11815
|
-
}
|
|
11816
|
-
const tsconfigTest = {
|
|
11817
|
-
id: "tsconfig-test",
|
|
11818
|
-
title: "Each package with a `tsconfig.json` and test files has a `tsconfig.test.json`, and its `typecheck` script examines it.",
|
|
11819
|
-
reason: "The build config leaves out the tests. Without a second config, `pnpm typecheck` does not examine the tests, and a type error in a test hides until the test runs.",
|
|
11820
|
-
fix: "Add `tsconfig.test.json` (extends `./tsconfig.json`, includes the tests, `noEmit`), and set the script `typecheck` to `tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json`. Keep `--noEmit` on the first call when the build config emits, so that a typecheck writes no build output.",
|
|
11821
|
-
sources: [
|
|
11822
|
-
{
|
|
11823
|
-
repo: "coeval",
|
|
11824
|
-
rule: "package-tsconfig-test",
|
|
11825
|
-
doc: "CLAUDE.md:18"
|
|
11826
|
-
},
|
|
11827
|
-
{
|
|
11828
|
-
repo: "coeval",
|
|
11829
|
-
rule: "tsconfig-test",
|
|
11830
|
-
doc: "CLAUDE.md:18"
|
|
11831
|
-
},
|
|
11832
|
-
{
|
|
11833
|
-
repo: "crawler",
|
|
11834
|
-
rule: "pkg-tsconfig-test",
|
|
11835
|
-
doc: "CLAUDE.md:18"
|
|
11836
|
-
},
|
|
11837
|
-
{
|
|
11838
|
-
repo: "crawler",
|
|
11839
|
-
rule: "tsconfig-test",
|
|
11840
|
-
doc: "CLAUDE.md:18"
|
|
11841
|
-
},
|
|
11842
|
-
{
|
|
11843
|
-
repo: "headroom",
|
|
11844
|
-
rule: "tsconfig-test",
|
|
11845
|
-
doc: "CLAUDE.md:32"
|
|
11846
|
-
},
|
|
11847
|
-
{
|
|
11848
|
-
repo: "headroom",
|
|
11849
|
-
rule: "tsconfig-test-per-package",
|
|
11850
|
-
doc: "CLAUDE.md:32"
|
|
11851
|
-
},
|
|
11852
|
-
{
|
|
11853
|
-
repo: "Vex",
|
|
11854
|
-
rule: "package-tsconfig-test",
|
|
11855
|
-
doc: "CLAUDE.md:23"
|
|
11856
|
-
},
|
|
11857
|
-
{
|
|
11858
|
-
repo: "Vex",
|
|
11859
|
-
rule: "tsconfig-test",
|
|
11860
|
-
doc: "CLAUDE.md:23"
|
|
11861
|
-
}
|
|
11862
|
-
],
|
|
11863
|
-
options: { file: {
|
|
11864
|
-
type: "string",
|
|
11865
|
-
default: "tsconfig.test.json",
|
|
11866
|
-
description: "The name of the config of the tests."
|
|
11867
|
-
} },
|
|
11868
|
-
check(context, options) {
|
|
11869
|
-
const file = typeof options["file"] === "string" ? options["file"] : "tsconfig.test.json";
|
|
11870
|
-
const tracked = context.gitFiles();
|
|
11871
|
-
const breaks = [];
|
|
11872
|
-
for (const info of codePackages(context)) {
|
|
11873
|
-
if (!hasFile(info.dir, "tsconfig.json")) continue;
|
|
11874
|
-
if (tracked !== void 0 && !hasTests(tracked, info.folder)) continue;
|
|
11875
|
-
if (!hasFile(info.dir, file)) {
|
|
11876
|
-
breaks.push({
|
|
11877
|
-
file: inFolder(info.folder, file),
|
|
11878
|
-
message: `The package has a tsconfig.json and no ${file}.`
|
|
11879
|
-
});
|
|
11880
|
-
continue;
|
|
11881
|
-
}
|
|
11882
|
-
const scripts = info.manifest["scripts"];
|
|
11883
|
-
const typecheck = typeof scripts === "object" && scripts !== null ? scripts["typecheck"] : void 0;
|
|
11884
|
-
if (typeof typecheck === "string" && !typecheck.includes(file)) {
|
|
11885
|
-
const line = lineOf(info.text, "\"typecheck\"");
|
|
11886
|
-
breaks.push({
|
|
11887
|
-
file: info.file,
|
|
11888
|
-
...line === void 0 ? {} : { line },
|
|
11889
|
-
message: `The script typecheck ("${typecheck}") does not examine ${file}.`,
|
|
11890
|
-
fix: `Add \`tsc -p ${file}\` to the script typecheck.`
|
|
11891
|
-
});
|
|
11892
|
-
}
|
|
11893
|
-
}
|
|
11894
|
-
return breaks;
|
|
11895
|
-
}
|
|
11896
|
-
};
|
|
11897
12185
|
// src/rules/tests-required.ts
|
|
11898
12186
|
/**
|
|
11899
12187
|
* The rule `tests-required`: no test runner passes when it finds no test (`passWithNoTests`).
|
|
@@ -12846,6 +13134,7 @@ const RULES = [
|
|
|
12846
13134
|
workspaceProtocol,
|
|
12847
13135
|
trustPolicy,
|
|
12848
13136
|
sourceMain,
|
|
13137
|
+
serviceRunMain,
|
|
12849
13138
|
tsconfigTest,
|
|
12850
13139
|
cuePreset,
|
|
12851
13140
|
requiredScripts,
|
|
@@ -12870,6 +13159,7 @@ const RULES = [
|
|
|
12870
13159
|
gateAfterCancel,
|
|
12871
13160
|
gateTrigger,
|
|
12872
13161
|
securityOneJob,
|
|
13162
|
+
sharedCi,
|
|
12873
13163
|
homePackage,
|
|
12874
13164
|
licenseFile,
|
|
12875
13165
|
pagesSite,
|
|
@@ -12979,19 +13269,23 @@ function runChecks(options) {
|
|
|
12979
13269
|
});
|
|
12980
13270
|
continue;
|
|
12981
13271
|
}
|
|
13272
|
+
const generated = ruleConfig.generated ?? [];
|
|
12982
13273
|
const added = ruleConfig.ignore.length > 0 ? addedFiles(context) : void 0;
|
|
12983
13274
|
const breaks = [];
|
|
12984
|
-
for (const item of outcome)
|
|
12985
|
-
|
|
12986
|
-
|
|
12987
|
-
|
|
12988
|
-
|
|
13275
|
+
for (const item of outcome) {
|
|
13276
|
+
if (matchesAny(item.file, generated)) continue;
|
|
13277
|
+
if (!matchesAny(item.file, ruleConfig.ignore)) breaks.push(item);
|
|
13278
|
+
else if (added?.has(item.file) === true) breaks.push({
|
|
13279
|
+
...item,
|
|
13280
|
+
message: `${item.message} The change adds this file, so \`ignore\` does not cover it.`
|
|
13281
|
+
});
|
|
13282
|
+
}
|
|
12989
13283
|
const ignored = outcome.length - breaks.length;
|
|
12990
|
-
if (rule.changeScoped !== true) for (const
|
|
13284
|
+
if (rule.changeScoped !== true) for (const [field, globs] of [["ignore", ruleConfig.ignore], ["generated", generated]]) for (const glob of globs) {
|
|
12991
13285
|
if (outcome.some((item) => matchesAny(item.file, [glob]))) continue;
|
|
12992
13286
|
breaks.push({
|
|
12993
13287
|
file: "package.json",
|
|
12994
|
-
message: `The entry \`${glob}\` of \`
|
|
13288
|
+
message: `The entry \`${glob}\` of \`${field}\` matches no break of this rule. Remove it from the field \`conventions\`.`
|
|
12995
13289
|
});
|
|
12996
13290
|
}
|
|
12997
13291
|
const note = ruleConfig.reason === void 0 ? {} : { note: ruleConfig.reason };
|
|
@@ -13306,6 +13600,6 @@ function runMap(args, io) {
|
|
|
13306
13600
|
else io.stdout(mapText(found));
|
|
13307
13601
|
return 0;
|
|
13308
13602
|
}
|
|
13309
|
-
export {
|
|
13603
|
+
export { pagesAfterRelease as $, prPathFilters as $t, HOME_TIMEOUT_MS as A, mapText as At, publishedMinor as B, SHARED_CI as Bt, configsOfScript as C, parseConfig as Cn, messageOf as Ct, isSourcePath as D, MAP_RULE as Dt, testsRequired as E, HOMES as Et, roadmapParses as F, runCalls as Ft, UNSHIPPED_FILES as G, SECURITY_SCAN_INPUTS as Gt, reachOf as H, callsSharedCi as Ht, requiredScripts as I, serviceRunMain as It, unreleasedChangeRule as J, securityOneJob as Jt, npmLookup as K, SECURITY_TIMEOUT_MINUTES as Kt, releaseFiles as L, hasTests as Lt, githubFetch as M, readOverlay as Mt, sharedDocsRule as N, HOME_EXPORTS as Nt, pathsOf as O, findHomes as Ot, roadmapOfLine as P, SERVICE_PACKAGE as Pt, pinnedGitDeps as Q, gateTrigger as Qt, lockedVersions as R, tsconfigTest as Rt, typedScripts as S, defaultOptions as Sn, homePackage as St, typedFiles as T, signaturesOf as Tt, NPM_REGISTRY as U, sharedCi as Ut, publishedMinorRule as V, SHARED_WORKFLOWS as Vt, SHIPPED_FIELDS as W, SECURITY_SCAN_COMMIT as Wt, isGitSpecifier as X, ACTIONS_COMMIT as Xt, pipeFails as Y, withOneJob as Yt, isPinned as Z, convertGate as Zt, setVersions as _, specifiersOf as _n, licenseFile as _t, listRules as a, DEPENDENCY_FIELDS as an, pagesCalls as at, TRAIN_SCOPES as b, packageFolders as bn, repositoryIsPublic as bt, runCli as c, hasFile as cn, DEFAULT_ALLOWED as ct, RULES as d, lineOf as dn, noBuildOutput as dt, summaryName as en, repositoryOfRemote as et, workspaceProtocol as f, matchesAny as fn, REAL_COMPARE as ft, namedVersions as g, runGit as gn, authorOf as gt, yamlFaults as h, replaceLine as hn, LICENSE_TEXTS as ht, formatResult as i, cuePreset as in, PAGES_WORKFLOWS as it, blockHash as j, mergeHomes as jt, sourceMain as k, mapMarkdown as kt, runFix as l, inFolder as ln, HOME_PATTERNS as lt, workflowParses as m, readJsonc as mn, mainCheck as mt, annotations as n, readWorkflow as nn, scheduleMinute as nt, readConfig as o, cleanPath as on, pagesSite as ot, GITHUB_YAML as p, parseJsonc as pn, hasImportMetaMain as pt, unreleasedChange as q, securityCallers as qt, createContext as r, STRICT_OPTIONS as rn, pushMainOnly as rt, runChecks as s, codePackages as sn, apiReportScript as st, USAGE as t, gateAfterCancel as tn, runnerBudget as tt, summaryMarkdown as u, keyLine as un, noLocalPaths as ut, versionTitle as v, globFolders as vn, licenseFileOf as vt, scriptsOf as w, repoOf as wt, trustPolicy as x, workspaceGlobs as xn, declaredName as xt, IGNORE_AFTER as y, globToRegExp as yn, mitText as yt, minorOf as z, SHARED_ACTIONS as zt };
|
|
13310
13604
|
|
|
13311
|
-
//# sourceMappingURL=run-
|
|
13605
|
+
//# sourceMappingURL=run-DWyPhbeH.js.map
|