@mark1russell7/conventions 0.19.0 → 0.21.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 +3 -0
- package/build/cli.js +1 -1
- package/build/index.d.ts +38 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/{run-D0ua_8Tj.js → run-sEUuSlqi.js} +2225 -1866
- package/build/run-sEUuSlqi.js.map +1 -0
- package/package.json +1 -1
- package/build/run-D0ua_8Tj.js.map +0 -1
|
@@ -309,753 +309,1685 @@ const hasFile = (dir, file) => existsSync(join(dir, file));
|
|
|
309
309
|
function codePackages(context) {
|
|
310
310
|
return context.packages.length > 0 ? context.packages : [context.rootPackage];
|
|
311
311
|
}
|
|
312
|
-
// src/
|
|
312
|
+
// ../site-pages/src/data/versions.ts
|
|
313
|
+
const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
314
|
+
/** This function gives the parts of a version, or null when the text is not a SemVer version. */
|
|
315
|
+
function parseVersion(version) {
|
|
316
|
+
const match = SEMVER.exec(version);
|
|
317
|
+
if (!match) return null;
|
|
318
|
+
return {
|
|
319
|
+
major: Number(match[1]),
|
|
320
|
+
minor: Number(match[2]),
|
|
321
|
+
patch: Number(match[3]),
|
|
322
|
+
prerelease: match[4] ? match[4].split(".") : []
|
|
323
|
+
};
|
|
324
|
+
}
|
|
313
325
|
/**
|
|
314
|
-
*
|
|
315
|
-
*
|
|
326
|
+
* This function compares two versions by the SemVer precedence. It gives a negative number when `a`
|
|
327
|
+
* is older, a positive number when `a` is newer, and 0 for the same version. A text that is not a
|
|
328
|
+
* version comes before each version.
|
|
316
329
|
*/
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
"noImplicitThis",
|
|
345
|
-
"useUnknownInCatchVariables",
|
|
346
|
-
"alwaysStrict"
|
|
347
|
-
]);
|
|
348
|
-
const asObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
349
|
-
/** This function gives the `extends` list of a tsconfig. */
|
|
350
|
-
const extendsOf = (config) => {
|
|
351
|
-
const value = config["extends"];
|
|
352
|
-
if (typeof value === "string") return [value];
|
|
353
|
-
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
354
|
-
};
|
|
330
|
+
function compareVersions(a, b) {
|
|
331
|
+
const x = parseVersion(a);
|
|
332
|
+
const y = parseVersion(b);
|
|
333
|
+
if (!x || !y) return x ? 1 : y ? -1 : a.localeCompare(b);
|
|
334
|
+
const core = x.major - y.major || x.minor - y.minor || x.patch - y.patch;
|
|
335
|
+
if (core !== 0) return core;
|
|
336
|
+
if (x.prerelease.length === 0 || y.prerelease.length === 0) return y.prerelease.length - x.prerelease.length;
|
|
337
|
+
for (let index = 0; index < Math.max(x.prerelease.length, y.prerelease.length); index++) {
|
|
338
|
+
const p = x.prerelease[index];
|
|
339
|
+
const q = y.prerelease[index];
|
|
340
|
+
if (p === void 0) return -1;
|
|
341
|
+
if (q === void 0) return 1;
|
|
342
|
+
if (p === q) continue;
|
|
343
|
+
const pNumber = /^\d+$/.test(p);
|
|
344
|
+
const qNumber = /^\d+$/.test(q);
|
|
345
|
+
if (pNumber && qNumber) return Number(p) - Number(q);
|
|
346
|
+
if (pNumber !== qNumber) return pNumber ? -1 : 1;
|
|
347
|
+
return p < q ? -1 : 1;
|
|
348
|
+
}
|
|
349
|
+
return 0;
|
|
350
|
+
}
|
|
351
|
+
// ../site-pages/src/data/changelog.ts
|
|
352
|
+
const VERSION_HEADING = /^##\s+\[?v?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)\]?(?:\s.*)?$/;
|
|
353
|
+
const COMMIT_ENTRY = /^([0-9a-f]{7,40}):\s+([\s\S]*)$/;
|
|
354
|
+
const DEPENDENCY_ENTRY = /^(?:Updated dependencies\b|@?[\w.-]+(?:\/[\w.-]+)?@\S+\s*$)/;
|
|
355
|
+
const GENERATED_NOTE = /\sby\s+@[\w-]+(?:\[bot\])?\s+in\s+(https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/pull\/(\d+))\s*$/;
|
|
356
|
+
const FIRST_CONTRIBUTION = /\bmade their first contribution\b/;
|
|
355
357
|
/**
|
|
356
|
-
* This function gives the
|
|
357
|
-
* a
|
|
358
|
+
* This function gives the first sentence of a text. A full stop, a question mark or an exclamation
|
|
359
|
+
* mark ends the sentence when a space and no lowercase letter follow it.
|
|
360
|
+
*
|
|
361
|
+
* @remarks A mark in a code span does not end the sentence. A text that ends with a colon (a list
|
|
362
|
+
* follows) ends with a full stop.
|
|
358
363
|
*/
|
|
359
|
-
function
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
for (const base of extendsOf(config)) {
|
|
367
|
-
let file;
|
|
368
|
-
if (base.startsWith(".")) file = resolve(dir, base.endsWith(".json") ? base : `${base}.json`);
|
|
369
|
-
else try {
|
|
370
|
-
file = createRequire(join(dir, "package.json")).resolve(base);
|
|
371
|
-
} catch {
|
|
372
|
-
file = void 0;
|
|
373
|
-
}
|
|
374
|
-
const parent = file === void 0 ? void 0 : readJsonc(file);
|
|
375
|
-
if (parent === void 0 || file === void 0) {
|
|
376
|
-
complete = false;
|
|
364
|
+
function firstSentence(text) {
|
|
365
|
+
const clean = text.replace(/\s+/g, " ").trim();
|
|
366
|
+
let code = false;
|
|
367
|
+
for (let index = 0; index < clean.length; index++) {
|
|
368
|
+
const char = clean[index];
|
|
369
|
+
if (char === "`") {
|
|
370
|
+
code = !code;
|
|
377
371
|
continue;
|
|
378
372
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
373
|
+
if (code || char !== "." && char !== "?" && char !== "!") continue;
|
|
374
|
+
const next = clean[index + 1];
|
|
375
|
+
if (next === void 0) break;
|
|
376
|
+
if (next === " " && !/^[a-z]/.test(clean.slice(index + 2))) return clean.slice(0, index + 1);
|
|
377
|
+
}
|
|
378
|
+
return clean.replace(/:$/, ".");
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* This function makes one entry from the lines of a list item. The text is the first paragraph: the
|
|
382
|
+
* lines before an empty line or a nested list. It gives null for an entry that is not a change.
|
|
383
|
+
*/
|
|
384
|
+
function entryOf(lines) {
|
|
385
|
+
const paragraph = [];
|
|
386
|
+
for (const [index, line] of lines.entries()) {
|
|
387
|
+
if (index > 0 && (line.trim() === "" || /^\s+[-*+]\s/.test(line))) break;
|
|
388
|
+
paragraph.push(line.trim());
|
|
386
389
|
}
|
|
390
|
+
const text = paragraph.join(" ");
|
|
391
|
+
const commit = COMMIT_ENTRY.exec(text);
|
|
392
|
+
let body = (commit ? commit[2] : text) ?? "";
|
|
393
|
+
if (body.trim() === "" || DEPENDENCY_ENTRY.test(body.trim()) || FIRST_CONTRIBUTION.test(body)) return null;
|
|
394
|
+
const note = GENERATED_NOTE.exec(body);
|
|
395
|
+
if (note) body = `${body.slice(0, note.index).trimEnd()} ([#${note[2] ?? ""}](${note[1] ?? ""}))`;
|
|
387
396
|
return {
|
|
388
|
-
|
|
389
|
-
|
|
397
|
+
commit: commit?.[1] ?? null,
|
|
398
|
+
text: firstSentence(body)
|
|
390
399
|
};
|
|
391
400
|
}
|
|
392
401
|
/**
|
|
393
|
-
* This function
|
|
394
|
-
*
|
|
402
|
+
* This function gives the entries of each version of a changelog, in the sequence of the file.
|
|
403
|
+
*
|
|
404
|
+
* @remarks An entry is a line that starts with "- " and the indented lines under it. An entry for a
|
|
405
|
+
* new dependency version is not a change.
|
|
395
406
|
*/
|
|
396
|
-
function
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
rule: "no-manual-tsconfig",
|
|
416
|
-
doc: "CLAUDE.md:64"
|
|
417
|
-
},
|
|
418
|
-
{
|
|
419
|
-
repo: "Graph",
|
|
420
|
-
rule: "cue-preset-strict",
|
|
421
|
-
doc: "docs/architecture/ecosystem-and-structure.md:58"
|
|
422
|
-
},
|
|
423
|
-
{
|
|
424
|
-
repo: "Graph",
|
|
425
|
-
rule: "strict-preset",
|
|
426
|
-
doc: "docs/architecture/ecosystem-and-structure.md:58"
|
|
427
|
-
},
|
|
428
|
-
{
|
|
429
|
-
repo: "Graph",
|
|
430
|
-
rule: "new-package-via-cli",
|
|
431
|
-
doc: "CLAUDE.md:14"
|
|
432
|
-
},
|
|
433
|
-
{
|
|
434
|
-
repo: "coeval",
|
|
435
|
-
rule: "package-scaffold",
|
|
436
|
-
doc: "CLAUDE.md:16"
|
|
437
|
-
},
|
|
438
|
-
{
|
|
439
|
-
repo: "crawler",
|
|
440
|
-
rule: "package-scaffold",
|
|
441
|
-
doc: "CLAUDE.md:16"
|
|
442
|
-
},
|
|
443
|
-
{
|
|
444
|
-
repo: "headroom",
|
|
445
|
-
rule: "package-scaffold",
|
|
446
|
-
doc: "CLAUDE.md:30"
|
|
447
|
-
},
|
|
448
|
-
{
|
|
449
|
-
repo: "Vex",
|
|
450
|
-
rule: "package-scaffold",
|
|
451
|
-
doc: "CLAUDE.md:22"
|
|
452
|
-
}
|
|
453
|
-
],
|
|
454
|
-
options: {
|
|
455
|
-
prefix: {
|
|
456
|
-
type: "string",
|
|
457
|
-
default: "@mark1russell7/cue/",
|
|
458
|
-
description: "The start of the `extends` path of a preset."
|
|
459
|
-
},
|
|
460
|
-
extends: {
|
|
461
|
-
type: "boolean",
|
|
462
|
-
default: true,
|
|
463
|
-
description: "When false, the rule does not examine `extends`. It still reports each strict option that a config turns off. For a package that publishes its own presets."
|
|
407
|
+
function parseChangelog(markdown) {
|
|
408
|
+
const sections = [];
|
|
409
|
+
let section = null;
|
|
410
|
+
let entry = null;
|
|
411
|
+
const close = () => {
|
|
412
|
+
if (entry && section) section.raw.push(entry);
|
|
413
|
+
entry = null;
|
|
414
|
+
};
|
|
415
|
+
for (const line of markdown.split(/\r?\n/)) {
|
|
416
|
+
const heading = VERSION_HEADING.exec(line);
|
|
417
|
+
if (heading?.[1] !== void 0) {
|
|
418
|
+
close();
|
|
419
|
+
section = {
|
|
420
|
+
version: heading[1],
|
|
421
|
+
heading: line.replace(/^##\s+/, "").trim(),
|
|
422
|
+
raw: []
|
|
423
|
+
};
|
|
424
|
+
sections.push(section);
|
|
425
|
+
continue;
|
|
464
426
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
const file = inFolder(info.folder, name);
|
|
474
|
-
const value = readJsonc(path);
|
|
475
|
-
if (value === void 0) {
|
|
476
|
-
if (hasFile(info.dir, name)) breaks.push({
|
|
477
|
-
file,
|
|
478
|
-
message: `${name} is not JSON.`,
|
|
479
|
-
fix: "Correct the JSON."
|
|
480
|
-
});
|
|
481
|
-
continue;
|
|
482
|
-
}
|
|
483
|
-
const config = asObject(value);
|
|
484
|
-
if (name === "tsconfig.json" && options["extends"] !== false && !extendsOf(config).some((base) => base.startsWith(prefix))) {
|
|
485
|
-
const line = lineOf(readFileSync(path, "utf8"), "\"extends\"");
|
|
486
|
-
breaks.push({
|
|
487
|
-
file,
|
|
488
|
-
...line === void 0 ? {} : { line },
|
|
489
|
-
message: `tsconfig.json does not extend a preset of ${prefix.replace(/\/$/, "")}.`
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
const own = asObject(config["compilerOptions"]);
|
|
493
|
-
const inherited = inheritedOptions(config, info.dir);
|
|
494
|
-
for (const option of STRICT_OPTIONS) {
|
|
495
|
-
if (own[option] !== false || !inheritedOn(option, inherited)) continue;
|
|
496
|
-
breaks.push({
|
|
497
|
-
file,
|
|
498
|
-
message: `${name} turns off the strict option ${option}.`,
|
|
499
|
-
fix: `Remove "${option}": false, and correct the code that it hides.`
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
}
|
|
427
|
+
if (section === null) continue;
|
|
428
|
+
if (line.startsWith("- ")) {
|
|
429
|
+
close();
|
|
430
|
+
entry = [line.slice(2)];
|
|
431
|
+
} else if (entry && (line.trim() === "" || /^\s/.test(line))) entry.push(line);
|
|
432
|
+
else {
|
|
433
|
+
close();
|
|
434
|
+
if (/^#{1,2}\s/.test(line)) section = null;
|
|
503
435
|
}
|
|
504
|
-
return breaks;
|
|
505
436
|
}
|
|
506
|
-
|
|
507
|
-
|
|
437
|
+
close();
|
|
438
|
+
return sections.map(({ version, heading, raw }) => ({
|
|
439
|
+
version,
|
|
440
|
+
heading,
|
|
441
|
+
entries: raw.map(entryOf).filter((change) => change !== null)
|
|
442
|
+
}));
|
|
443
|
+
}
|
|
444
|
+
// ../site-pages/src/data/status.ts
|
|
445
|
+
/** An error in the roadmap file, with the file and the line. */
|
|
446
|
+
var RoadmapParseError = class extends Error {};
|
|
447
|
+
const STATUS_KEYWORDS = [
|
|
448
|
+
["open", /\bnot\s+(?:yet\s+)?(?:started|done|fixed|merged|shipped|released)\b|\bto[ -]?do\b/],
|
|
449
|
+
["done", /\b(?:done|shipped|merged|fixed|released|complete|completed|closed|never|dropped|cancell?ed|wontfix)\b|\bwon't do\b/],
|
|
450
|
+
["progress", /\bin[ -]progress\b|\b(?:active|ongoing|started|wip)\b/],
|
|
451
|
+
["waiting", /\b(?:waiting|waits|awaiting|needs)\b/],
|
|
452
|
+
["blocked", /\bblocked\b/],
|
|
453
|
+
["later", /\b(?:later|deferred|postponed|someday)\b/]
|
|
454
|
+
];
|
|
508
455
|
/**
|
|
509
|
-
*
|
|
510
|
-
*
|
|
456
|
+
* This function gives the class of a free-text status: done, progress, waiting, blocked, later or
|
|
457
|
+
* open. The first keyword of the text decides. A text without a keyword ("next", "open") is open.
|
|
511
458
|
*/
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
function keyValue(line, key) {
|
|
527
|
-
let text = line.trimStart();
|
|
528
|
-
if (text.startsWith("- ")) text = text.slice(2).trimStart();
|
|
529
|
-
for (const form of [
|
|
530
|
-
key,
|
|
531
|
-
`"${key}"`,
|
|
532
|
-
`'${key}'`
|
|
533
|
-
]) if (text.startsWith(`${form}:`)) return valueOf$1(text.slice(form.length + 1));
|
|
459
|
+
function statusClassOf(text) {
|
|
460
|
+
const lower = String(text ?? "").toLowerCase();
|
|
461
|
+
let best = {
|
|
462
|
+
index: Infinity,
|
|
463
|
+
value: "open"
|
|
464
|
+
};
|
|
465
|
+
for (const [value, pattern] of STATUS_KEYWORDS) {
|
|
466
|
+
const match = pattern.exec(lower);
|
|
467
|
+
if (match && match.index < best.index) best = {
|
|
468
|
+
index: match.index,
|
|
469
|
+
value
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
return best.value;
|
|
534
473
|
}
|
|
535
|
-
/** This function gives the
|
|
536
|
-
function
|
|
537
|
-
const
|
|
538
|
-
let
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
474
|
+
/** This function gives the cells of a table row. A "|" in a code span or after "\" is text. */
|
|
475
|
+
function splitRow(line) {
|
|
476
|
+
const cells = [];
|
|
477
|
+
let cell = "";
|
|
478
|
+
let code = false;
|
|
479
|
+
const text = line.trim().replace(/^\|/, "").replace(/\|$/, "");
|
|
480
|
+
for (let index = 0; index < text.length; index++) {
|
|
481
|
+
const char = text[index];
|
|
482
|
+
if (char === "\\" && text[index + 1] === "|") {
|
|
483
|
+
cell += "|";
|
|
484
|
+
index++;
|
|
485
|
+
} else if (char === "`") {
|
|
486
|
+
code = !code;
|
|
487
|
+
cell += char;
|
|
488
|
+
} else if (char === "|" && !code) {
|
|
489
|
+
cells.push(cell.trim());
|
|
490
|
+
cell = "";
|
|
491
|
+
} else cell += char;
|
|
543
492
|
}
|
|
544
|
-
|
|
493
|
+
cells.push(cell.trim());
|
|
494
|
+
return cells;
|
|
545
495
|
}
|
|
546
|
-
/**
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
496
|
+
/** A whitespace character, as `\s` of a regular expression and `String.prototype.trim` read it. */
|
|
497
|
+
const SPACE = /\s/;
|
|
498
|
+
/** A character that `.` of a regular expression does not match. */
|
|
499
|
+
const LINE_TERMINATOR = /[\n\r\u2028\u2029]/;
|
|
500
|
+
/** The first whitespace character at or after `lastIndex`. */
|
|
501
|
+
const NEXT_SPACE = /\s/g;
|
|
502
|
+
/**
|
|
503
|
+
* This function replaces each Markdown link `[label](target)` of a text with the result of
|
|
504
|
+
* `replace`. The label ends at the first `]`, and the target ends at the first `)`. In `strict`
|
|
505
|
+
* mode, the label and the target are not empty, and the target has no whitespace.
|
|
506
|
+
*
|
|
507
|
+
* @remarks The function reads the text one time. A regular expression for these links can
|
|
508
|
+
* backtrack (CodeQL `js/polynomial-redos`). For a long text with many `[` characters, its time
|
|
509
|
+
* grows with the square of the length.
|
|
510
|
+
*/
|
|
511
|
+
function replaceLinks(text, strict, replace) {
|
|
512
|
+
let result = "";
|
|
513
|
+
let copied = 0;
|
|
514
|
+
let close = -1;
|
|
515
|
+
let end = -1;
|
|
516
|
+
let space = -1;
|
|
517
|
+
for (let open = text.indexOf("["); open !== -1; open = text.indexOf("[", open + 1)) {
|
|
518
|
+
if (close <= open) close = text.indexOf("]", open + 1);
|
|
519
|
+
if (close === -1) break;
|
|
520
|
+
if (text[close + 1] !== "(" || strict && close === open + 1) continue;
|
|
521
|
+
const start = close + 2;
|
|
522
|
+
if (end < start) end = text.indexOf(")", start);
|
|
523
|
+
if (end === -1) break;
|
|
524
|
+
if (strict) {
|
|
525
|
+
if (space !== Infinity && space < start) {
|
|
526
|
+
NEXT_SPACE.lastIndex = start;
|
|
527
|
+
space = NEXT_SPACE.exec(text)?.index ?? Infinity;
|
|
528
|
+
}
|
|
529
|
+
if (end === start || space < end) continue;
|
|
530
|
+
}
|
|
531
|
+
result += text.slice(copied, open) + replace(text.slice(open + 1, close), text.slice(start, end));
|
|
532
|
+
copied = end + 1;
|
|
533
|
+
open = end;
|
|
534
|
+
}
|
|
535
|
+
return result + text.slice(copied);
|
|
550
536
|
}
|
|
551
|
-
/**
|
|
552
|
-
function
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
537
|
+
/**
|
|
538
|
+
* This function gives the text of an ATX heading without its closing sequence: the whitespace,
|
|
539
|
+
* then the `#` characters, then the whitespace at the end. It gives null when the rest has a line
|
|
540
|
+
* terminator, as the regular expression `(.*?)\s*#*\s*$` does.
|
|
541
|
+
*/
|
|
542
|
+
function closeHeading(text) {
|
|
543
|
+
let end = text.length;
|
|
544
|
+
while (end > 0 && SPACE.test(text[end - 1] ?? "")) end--;
|
|
545
|
+
while (end > 0 && text[end - 1] === "#") end--;
|
|
546
|
+
while (end > 0 && SPACE.test(text[end - 1] ?? "")) end--;
|
|
547
|
+
const rest = text.slice(0, end);
|
|
548
|
+
return LINE_TERMINATOR.test(rest) ? null : rest;
|
|
549
|
+
}
|
|
550
|
+
/** The start of an ATX heading. The text after the whitespace goes to `closeHeading`. */
|
|
551
|
+
const HEADING = /^(#{1,6})\s+(\S[\s\S]*)?$/;
|
|
552
|
+
/** This function gives the level and the text of an ATX heading line, or null for another line. */
|
|
553
|
+
function headingOf(line) {
|
|
554
|
+
const match = HEADING.exec(line);
|
|
555
|
+
const text = match ? closeHeading(match[2] ?? "") : null;
|
|
556
|
+
return match && text !== null ? {
|
|
557
|
+
level: match[1]?.length ?? 0,
|
|
558
|
+
text
|
|
559
|
+
} : null;
|
|
560
|
+
}
|
|
561
|
+
/** This function gives the plain text of inline Markdown: no code marks, no emphasis, the text of each link. */
|
|
562
|
+
function plainText(markdown) {
|
|
563
|
+
return replaceLinks(String(markdown ?? ""), false, (label) => label).replace(/[`*_]/g, "").replace(/\s+/g, " ").trim();
|
|
564
|
+
}
|
|
565
|
+
/** A cell with no value: empty, or a dash. */
|
|
566
|
+
function isEmpty(cell) {
|
|
567
|
+
return cell === void 0 || /^(?:[-–—]|n\/a)?$/i.test(cell.trim());
|
|
558
568
|
}
|
|
559
|
-
// src/rules/gate-trigger.ts
|
|
560
569
|
/**
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
* on each pull request, so its check is not always there, and the ruleset cannot ask for it.
|
|
570
|
+
* This function gives the tables of a Markdown file. Each table has its header names in lowercase
|
|
571
|
+
* plain text, the nearest heading above it, the line of its header and its rows. Fenced code is not read.
|
|
564
572
|
*/
|
|
565
|
-
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
573
|
+
function markdownTables(markdown) {
|
|
574
|
+
const lines = String(markdown).split(/\r?\n/);
|
|
575
|
+
const tables = [];
|
|
576
|
+
let section = "";
|
|
577
|
+
let fence = null;
|
|
578
|
+
for (let index = 0; index < lines.length; index++) {
|
|
579
|
+
const line = lines[index] ?? "";
|
|
580
|
+
const fenceMark = /^\s*(`{3,}|~{3,})/.exec(line)?.[1];
|
|
581
|
+
if (fenceMark !== void 0) {
|
|
582
|
+
if (fence === null) fence = fenceMark[0] ?? null;
|
|
583
|
+
else if (fenceMark[0] === fence) fence = null;
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
if (fence !== null) continue;
|
|
587
|
+
const heading = headingOf(line);
|
|
588
|
+
if (heading) {
|
|
589
|
+
section = plainText(heading.text);
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
if (!line.trim().startsWith("|")) continue;
|
|
593
|
+
const separator = lines[index + 1] ?? "";
|
|
594
|
+
if (!/^\s*(?:\|\s*)?:?-{3,}/.test(separator)) continue;
|
|
595
|
+
const header = splitRow(line).map((name) => plainText(name).toLowerCase());
|
|
596
|
+
const rows = [];
|
|
597
|
+
let next = index + 2;
|
|
598
|
+
for (; next < lines.length && (lines[next] ?? "").trim().startsWith("|"); next++) rows.push({
|
|
599
|
+
line: next + 1,
|
|
600
|
+
cells: splitRow(lines[next] ?? "")
|
|
581
601
|
});
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
602
|
+
tables.push({
|
|
603
|
+
section,
|
|
604
|
+
line: index + 1,
|
|
605
|
+
header,
|
|
606
|
+
rows
|
|
586
607
|
});
|
|
608
|
+
index = next - 1;
|
|
587
609
|
}
|
|
588
|
-
return
|
|
610
|
+
return tables;
|
|
589
611
|
}
|
|
590
|
-
/** The
|
|
591
|
-
const
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
}
|
|
610
|
-
return {
|
|
611
|
-
items,
|
|
612
|
-
end
|
|
613
|
-
};
|
|
612
|
+
/** The columns whose cells hold the links of an item. */
|
|
613
|
+
const LINK_COLUMNS = [
|
|
614
|
+
"where",
|
|
615
|
+
"commit",
|
|
616
|
+
"commits",
|
|
617
|
+
"link",
|
|
618
|
+
"links",
|
|
619
|
+
"pr",
|
|
620
|
+
"prs"
|
|
621
|
+
];
|
|
622
|
+
/** Words before a reference that do not name a repository. */
|
|
623
|
+
const NOT_REPOSITORIES = new Set("a an and also at by commit commits done fixed for from in into issue issues merged of on or plus pr prs run see the then to via with".split(" "));
|
|
624
|
+
/** The URL of a link target of the roadmap file: an absolute URL stays, and a relative one goes to GitHub. */
|
|
625
|
+
function linkUrl(target, { file = "", repository = "", ref = "HEAD" }) {
|
|
626
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(target)) return target;
|
|
627
|
+
if (!repository) return null;
|
|
628
|
+
const [path = "", anchor = ""] = target.split("#", 2);
|
|
629
|
+
const resolved = path === "" ? file : posix.normalize(posix.join(posix.dirname(file), path));
|
|
630
|
+
if (resolved.startsWith("..")) return null;
|
|
631
|
+
return `https://github.com/${repository}/blob/${ref}/${resolved}${anchor ? `#${anchor}` : ""}`;
|
|
614
632
|
}
|
|
615
|
-
/**
|
|
616
|
-
function
|
|
617
|
-
|
|
618
|
-
|
|
633
|
+
/**
|
|
634
|
+
* This function gives the word right before the whitespace that ends `text.slice(0, end)`, as the
|
|
635
|
+
* regular expression `([A-Za-z][\w.-]*)\s+$` does. The word starts with a letter. The function
|
|
636
|
+
* reads only the characters of the word and of the whitespace.
|
|
637
|
+
*/
|
|
638
|
+
function wordBefore(text, end) {
|
|
639
|
+
let stop = end;
|
|
640
|
+
while (stop > 0 && SPACE.test(text[stop - 1] ?? "")) stop--;
|
|
641
|
+
if (stop === end) return void 0;
|
|
642
|
+
let start = stop;
|
|
643
|
+
while (start > 0 && /[\w.-]/.test(text[start - 1] ?? "")) start--;
|
|
644
|
+
while (start < stop && !/[A-Za-z]/.test(text[start] ?? "")) start++;
|
|
645
|
+
return start < stop ? text.slice(start, stop) : void 0;
|
|
619
646
|
}
|
|
620
|
-
/** This function puts an expression into the value of an `if`, as YAML that keeps it. */
|
|
621
|
-
const ifValue = (expression) => {
|
|
622
|
-
const value = `\${{ ${expression} }}`;
|
|
623
|
-
return value.includes(": ") || value.includes(" #") ? `"${value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}"` : value;
|
|
624
|
-
};
|
|
625
647
|
/**
|
|
626
|
-
* This function
|
|
627
|
-
*
|
|
628
|
-
*
|
|
629
|
-
*
|
|
648
|
+
* This function gives the links of a cell: each Markdown link, then each bare reference in the rest
|
|
649
|
+
* of the text. A reference is a pull request ("PR #12", "#12") or a commit hash in a code span.
|
|
650
|
+
*
|
|
651
|
+
* @remarks A repository name right before a reference ("systems PR #16") applies to it and to the
|
|
652
|
+
* next references of the cell. Without a name, a reference belongs to `repository`.
|
|
630
653
|
*/
|
|
631
|
-
function
|
|
632
|
-
const
|
|
633
|
-
const
|
|
634
|
-
const
|
|
635
|
-
const
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
for (const at of childKeys(lines, on)) {
|
|
642
|
-
const trigger = TRIGGERS.find((name) => keyValue(lines[at] ?? "", name) !== void 0);
|
|
643
|
-
if (trigger === void 0) continue;
|
|
644
|
-
if ((keyValue(lines[at] ?? "", trigger) ?? "") !== "") return { reason: `on.${trigger} has the flow form` };
|
|
645
|
-
let filtered = false;
|
|
646
|
-
for (const child of childKeys(lines, at)) {
|
|
647
|
-
const key = FILTERS.find((name) => keyValue(lines[child] ?? "", name) !== void 0);
|
|
648
|
-
if (key === void 0) continue;
|
|
649
|
-
const list = listItems(lines, child, keyValue(lines[child] ?? "", key) ?? "");
|
|
650
|
-
if (list === void 0) return { reason: `on.${trigger}.${key} is not a list` };
|
|
651
|
-
const before = filters[key];
|
|
652
|
-
if (before !== void 0 && before.join("\n") !== list.items.join("\n")) return { reason: `the triggers have different ${key}` };
|
|
653
|
-
filters[key] = list.items;
|
|
654
|
-
splices.push({
|
|
655
|
-
at: child,
|
|
656
|
-
remove: list.end - child,
|
|
657
|
-
insert: []
|
|
658
|
-
});
|
|
659
|
-
filtered = true;
|
|
660
|
-
}
|
|
661
|
-
if (filtered) {
|
|
662
|
-
const pad = " ".repeat(indentOf$1(lines[at] ?? ""));
|
|
663
|
-
splices.push({
|
|
664
|
-
at,
|
|
665
|
-
remove: 0,
|
|
666
|
-
insert: [`${pad}# Each pull request starts this workflow, so its summary check is always there. The job changes skips the`, `${pad}# work when the pull request changes no file of the gate (CI.md of the template, "A gate with paths").`]
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
if (Object.keys(filters).length === 0) return { reason: "the workflow has no path filter on a pull request trigger" };
|
|
671
|
-
const jobs = childKeys(lines, jobsAt);
|
|
672
|
-
const first = jobs[0];
|
|
673
|
-
if (first === void 0) return { reason: "the workflow has no job" };
|
|
674
|
-
const ids = jobs.map((at) => (lines[at] ?? "").trim().replace(/:$/, ""));
|
|
675
|
-
const jobIndent = " ".repeat(indentOf$1(lines[first] ?? ""));
|
|
676
|
-
const unit = " ".repeat((childIndent(lines, first) ?? indentOf$1(lines[first] ?? "") + 2) - jobIndent.length);
|
|
677
|
-
const nameAt = top("name");
|
|
678
|
-
const name = summaryName(nameAt >= 0 ? keyValue(lines[nameAt] ?? "", "name") ?? "" : (file.split("/").pop() ?? "").replace(/\.ya?ml$/, ""));
|
|
679
|
-
const summaryId = name.toLowerCase().replaceAll(" ", "-");
|
|
680
|
-
for (const id of ["changes", summaryId]) if (ids.includes(id)) return { reason: `the workflow already has a job ${id}` };
|
|
681
|
-
const needsOf = /* @__PURE__ */ new Map();
|
|
682
|
-
const own = /* @__PURE__ */ new Set();
|
|
683
|
-
for (const [index, at] of jobs.entries()) {
|
|
684
|
-
const id = ids[index] ?? "";
|
|
685
|
-
const keys = childKeys(lines, at);
|
|
686
|
-
const pad = " ".repeat(childIndent(lines, at) ?? indentOf$1(lines[at] ?? "") + unit.length);
|
|
687
|
-
const needsAt = keys.find((key) => keyValue(lines[key] ?? "", "needs") !== void 0);
|
|
688
|
-
const ifAt = keys.find((key) => keyValue(lines[key] ?? "", "if") !== void 0);
|
|
689
|
-
if (needsAt === void 0) {
|
|
690
|
-
needsOf.set(id, []);
|
|
691
|
-
splices.push({
|
|
692
|
-
at: at + 1,
|
|
693
|
-
remove: 0,
|
|
694
|
-
insert: [`${pad}needs: changes`]
|
|
695
|
-
});
|
|
696
|
-
} else {
|
|
697
|
-
const value = keyValue(lines[needsAt] ?? "", "needs") ?? "";
|
|
698
|
-
const list = value === "" || value.startsWith("[") ? listItems(lines, needsAt, value) : {
|
|
699
|
-
items: [value],
|
|
700
|
-
end: needsAt + 1
|
|
701
|
-
};
|
|
702
|
-
if (list === void 0) return { reason: `the needs of the job ${id} is not a list` };
|
|
703
|
-
needsOf.set(id, list.items);
|
|
704
|
-
if (value === "") {
|
|
705
|
-
const item = lines.findIndex((line, i) => i > needsAt && line.trim() !== "");
|
|
706
|
-
splices.push({
|
|
707
|
-
at: item,
|
|
708
|
-
remove: 0,
|
|
709
|
-
insert: [`${" ".repeat(indentOf$1(lines[item] ?? ""))}- changes`]
|
|
710
|
-
});
|
|
711
|
-
} else splices.push({
|
|
712
|
-
at: needsAt,
|
|
713
|
-
remove: 1,
|
|
714
|
-
insert: [`${pad}needs: [${["changes", ...list.items].join(", ")}]`]
|
|
715
|
-
});
|
|
716
|
-
}
|
|
717
|
-
if (ifAt === void 0) splices.push({
|
|
718
|
-
at: at + 1,
|
|
719
|
-
remove: 0,
|
|
720
|
-
insert: [`${pad}if: needs.changes.outputs.match == 'true'`]
|
|
654
|
+
function linksOf(cell, options = {}) {
|
|
655
|
+
const { repository = "" } = options;
|
|
656
|
+
const links = [];
|
|
657
|
+
const seen = /* @__PURE__ */ new Set();
|
|
658
|
+
const add = (label, url) => {
|
|
659
|
+
if (!url || seen.has(url)) return;
|
|
660
|
+
seen.add(url);
|
|
661
|
+
links.push({
|
|
662
|
+
label,
|
|
663
|
+
url
|
|
721
664
|
});
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
if (whole !== null) old = (whole[1] ?? "").trim();
|
|
727
|
-
if (old.includes("${{")) return { reason: `the if of the job ${id} has a part in \${{ }}` };
|
|
728
|
-
own.add(id);
|
|
729
|
-
splices.push({
|
|
730
|
-
at: ifAt,
|
|
731
|
-
remove: 1,
|
|
732
|
-
insert: [`${pad}if: ${ifValue(`needs.changes.outputs.match == 'true' && (${old})`)}`]
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
const skippable = new Set(own);
|
|
737
|
-
for (let grew = true; grew;) {
|
|
738
|
-
grew = false;
|
|
739
|
-
for (const [id, needs] of needsOf) {
|
|
740
|
-
if (skippable.has(id) || !needs.some((need) => skippable.has(need))) continue;
|
|
741
|
-
skippable.add(id);
|
|
742
|
-
grew = true;
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
const action = (step) => `mark1russell7/template/.github/actions/${step}@${commit} # main`;
|
|
746
|
-
const block = (indent, key, items) => [`${indent}${key}: |`, ...items.map((item) => `${indent}${unit}${item}`)];
|
|
747
|
-
const job = jobIndent + unit;
|
|
748
|
-
const step = job + unit;
|
|
749
|
-
const grouped = top("concurrency") >= 0;
|
|
750
|
-
const group = (id) => grouped ? [] : [
|
|
751
|
-
`${job}concurrency:`,
|
|
752
|
-
`${job}${unit}group: \${{ github.workflow }}-${id}-\${{ github.ref }}`,
|
|
753
|
-
`${job}${unit}cancel-in-progress: true`
|
|
754
|
-
];
|
|
755
|
-
const changes = [
|
|
756
|
-
`${jobIndent}changes:`,
|
|
757
|
-
`${job}runs-on: ubuntu-latest`,
|
|
758
|
-
`${job}timeout-minutes: 5`,
|
|
759
|
-
...group("changes"),
|
|
760
|
-
`${job}permissions:`,
|
|
761
|
-
`${job}${unit}contents: read`,
|
|
762
|
-
`${job}${unit}pull-requests: read`,
|
|
763
|
-
`${job}outputs:`,
|
|
764
|
-
`${job}${unit}match: \${{ steps.changes.outputs.match }}`,
|
|
765
|
-
`${job}steps:`,
|
|
766
|
-
`${step}- id: changes`,
|
|
767
|
-
`${step} uses: ${action("changes")}`,
|
|
768
|
-
`${step} with:`,
|
|
769
|
-
...block(`${step} ${unit}`, "paths", filters["paths"] ?? ["**"]),
|
|
770
|
-
...filters["paths-ignore"] === void 0 ? [] : block(`${step} ${unit}`, "paths-ignore", filters["paths-ignore"]),
|
|
771
|
-
""
|
|
772
|
-
];
|
|
773
|
-
const allow = ids.filter((id) => skippable.has(id));
|
|
774
|
-
const summary = [
|
|
775
|
-
"",
|
|
776
|
-
`${jobIndent}${summaryId}:`,
|
|
777
|
-
`${job}name: ${name}`,
|
|
778
|
-
`${job}if: always()`,
|
|
779
|
-
`${job}needs: [${["changes", ...ids].join(", ")}]`,
|
|
780
|
-
`${job}runs-on: ubuntu-latest`,
|
|
781
|
-
`${job}timeout-minutes: 2`,
|
|
782
|
-
...group(summaryId),
|
|
783
|
-
`${job}permissions: {}`,
|
|
784
|
-
`${job}steps:`,
|
|
785
|
-
`${step}- uses: ${action("gate-summary")}`,
|
|
786
|
-
`${step} with:`,
|
|
787
|
-
`${step} ${unit}needs: \${{ toJSON(needs) }}`,
|
|
788
|
-
...allow.length === 0 ? [] : [`${step} ${unit}allow-skip: ${allow.join(" ")}`]
|
|
789
|
-
];
|
|
790
|
-
let last = blockEnd(lines, jobsAt);
|
|
791
|
-
while (last > jobsAt + 1 && (lines[last - 1] ?? "").trim() === "") last -= 1;
|
|
792
|
-
splices.push({
|
|
793
|
-
at: first,
|
|
794
|
-
remove: 0,
|
|
795
|
-
insert: changes
|
|
796
|
-
}, {
|
|
797
|
-
at: last,
|
|
798
|
-
remove: 0,
|
|
799
|
-
insert: summary
|
|
665
|
+
};
|
|
666
|
+
const rest = replaceLinks(String(cell ?? ""), true, (label, target) => {
|
|
667
|
+
add(plainText(label), linkUrl(target, options));
|
|
668
|
+
return " ";
|
|
800
669
|
});
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
repo: "fleet",
|
|
815
|
-
rule: "gate-trigger",
|
|
816
|
-
doc: "docs/STRATEGY.md (2026-11-02, a gate with paths feeds a required summary)"
|
|
817
|
-
}],
|
|
818
|
-
options: { allow: {
|
|
819
|
-
type: "strings",
|
|
820
|
-
default: [],
|
|
821
|
-
description: "The file names of the workflows that can filter pull requests by path, because they are not a gate (for example a preview)."
|
|
822
|
-
} },
|
|
823
|
-
check(context, options) {
|
|
824
|
-
const files = context.gitFiles();
|
|
825
|
-
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
826
|
-
const workflows = files.filter((path) => WORKFLOW$1.test(path)).sort(byCode);
|
|
827
|
-
if (workflows.length === 0) return { skipped: "the repository has no workflow" };
|
|
828
|
-
const allow = Array.isArray(options["allow"]) ? options["allow"] : [];
|
|
829
|
-
const breaks = [];
|
|
830
|
-
for (const file of workflows) {
|
|
831
|
-
if (allow.includes(file.slice(file.lastIndexOf("/") + 1))) continue;
|
|
832
|
-
let text;
|
|
833
|
-
try {
|
|
834
|
-
text = readFileSync(join(context.root, file), "utf8");
|
|
835
|
-
} catch {
|
|
836
|
-
continue;
|
|
837
|
-
}
|
|
838
|
-
const filters = prPathFilters(text);
|
|
839
|
-
const first = filters[0];
|
|
840
|
-
if (first === void 0) continue;
|
|
841
|
-
const keys = filters.map((filter) => `on.${filter.trigger}.${filter.key}`).join(" and ");
|
|
842
|
-
const converted = convertGate(text, file);
|
|
843
|
-
breaks.push({
|
|
844
|
-
file,
|
|
845
|
-
line: first.line,
|
|
846
|
-
message: `${file}: ${keys}, so the workflow does not start on each pull request, and the ruleset cannot ask for its summary check.`,
|
|
847
|
-
..."text" in converted ? { edits: [{
|
|
848
|
-
file,
|
|
849
|
-
before: text,
|
|
850
|
-
after: converted.text
|
|
851
|
-
}] } : { fix: `A person must convert it, because ${converted.reason}. ${gateTrigger.fix}` }
|
|
852
|
-
});
|
|
853
|
-
}
|
|
854
|
-
return breaks;
|
|
670
|
+
if (!repository) return links;
|
|
671
|
+
const [owner, defaultRepo] = repository.split("/");
|
|
672
|
+
let current = defaultRepo;
|
|
673
|
+
let pulls = false;
|
|
674
|
+
const reference = /\bPRs?\s*#(\d+)|(?<![\w/&])#(\d+)\b|`([0-9a-f]{7,40})`/g;
|
|
675
|
+
for (let match = reference.exec(rest); match; match = reference.exec(rest)) {
|
|
676
|
+
const word = wordBefore(rest, match.index);
|
|
677
|
+
if (word && !NOT_REPOSITORIES.has(word.toLowerCase())) current = word;
|
|
678
|
+
const prefix = current === defaultRepo ? "" : `${current} `;
|
|
679
|
+
if (match[1] !== void 0) pulls = true;
|
|
680
|
+
const number = match[1] ?? match[2];
|
|
681
|
+
if (number !== void 0) add(`${prefix}#${number}`, `https://github.com/${owner}/${current}/${pulls ? "pull" : "issues"}/${number}`);
|
|
682
|
+
else if (match[3] !== void 0) add(`${prefix}${match[3].slice(0, 7)}`, `https://github.com/${owner}/${current}/commit/${match[3]}`);
|
|
855
683
|
}
|
|
856
|
-
|
|
857
|
-
|
|
684
|
+
return links;
|
|
685
|
+
}
|
|
858
686
|
/**
|
|
859
|
-
* The
|
|
860
|
-
*
|
|
687
|
+
* The heading of an item: "### `id`: Title". A dash can take the place of the colon. The title goes
|
|
688
|
+
* to `closeHeading`.
|
|
861
689
|
*/
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
if (typeof branch !== "string" || event.ref !== `refs/heads/${branch}`) return { skipped: "the push is not to the default branch: the pull request of the branch has the change" };
|
|
874
|
-
const before = typeof event.before === "string" ? event.before : "";
|
|
875
|
-
if (!/^[0-9a-f]{40,64}$/.test(before) || /^0+$/.test(before)) return { skipped: "the push has no commit before it" };
|
|
876
|
-
if (context.git([
|
|
877
|
-
"rev-parse",
|
|
878
|
-
"--verify",
|
|
879
|
-
"--quiet",
|
|
880
|
-
`${before}^{commit}`
|
|
881
|
-
]) === void 0) return { skipped: `the checkout does not have ${before}, the commit before the push: fetch it, or set fetch-depth to 0` };
|
|
882
|
-
return {
|
|
883
|
-
diff: [before, "HEAD"],
|
|
884
|
-
log: [`${before}..HEAD`],
|
|
885
|
-
ends: [before, "HEAD"]
|
|
886
|
-
};
|
|
887
|
-
}
|
|
888
|
-
/**
|
|
889
|
-
* This function gives the range of the change: the option `--base`, or the merge commit of a pull request. With the
|
|
890
|
-
* option `push`, a push to the default branch gives the commits of the push: from the commit before the push to HEAD.
|
|
891
|
-
*/
|
|
892
|
-
function rangeOf(context, options = {}) {
|
|
893
|
-
if (context.base !== void 0) {
|
|
894
|
-
if (context.git([
|
|
895
|
-
"rev-parse",
|
|
896
|
-
"--verify",
|
|
897
|
-
"--quiet",
|
|
898
|
-
`${context.base}^{commit}`
|
|
899
|
-
]) === void 0) return { skipped: `git does not know the base ${context.base}` };
|
|
900
|
-
return {
|
|
901
|
-
diff: [`${context.base}...HEAD`],
|
|
902
|
-
log: [`${context.base}..HEAD`],
|
|
903
|
-
ends: [context.base, "HEAD"]
|
|
690
|
+
const ITEM_HEADING = /^###\s+`([^`]+)`\s*[:–—-]\s*(\S[\s\S]*)?$/;
|
|
691
|
+
/** The other heading of an item: "### S1 · Title". The ID is one word before the middle dot. */
|
|
692
|
+
const ITEM_HEADING_DOT = /^###\s+([A-Za-z0-9][\w.-]*)\s+·\s+(\S[\s\S]*)?$/;
|
|
693
|
+
/** This function gives the ID and the title of an item heading, or null for another line. */
|
|
694
|
+
function itemHeadingOf(line) {
|
|
695
|
+
for (const pattern of [ITEM_HEADING, ITEM_HEADING_DOT]) {
|
|
696
|
+
const match = pattern.exec(line);
|
|
697
|
+
const title = match ? closeHeading(match[2] ?? "") : null;
|
|
698
|
+
if (match && title !== null) return {
|
|
699
|
+
id: match[1] ?? "",
|
|
700
|
+
title
|
|
904
701
|
};
|
|
905
702
|
}
|
|
906
|
-
|
|
907
|
-
if (event === "push" && options.push === true) return pushRange(context);
|
|
908
|
-
if (event !== "pull_request" && event !== "pull_request_target") return { skipped: "no base: the rule runs on a pull request, or with --base <ref>" };
|
|
909
|
-
if ((context.git([
|
|
910
|
-
"rev-list",
|
|
911
|
-
"--parents",
|
|
912
|
-
"-n",
|
|
913
|
-
"1",
|
|
914
|
-
"HEAD"
|
|
915
|
-
])?.trim().split(/\s+/) ?? []).length !== 3) return { skipped: "HEAD is not the merge commit of the pull request" };
|
|
916
|
-
if (context.git([
|
|
917
|
-
"cat-file",
|
|
918
|
-
"-e",
|
|
919
|
-
"HEAD^1^{commit}"
|
|
920
|
-
]) === void 0) return { skipped: "the checkout has no parent of HEAD: set fetch-depth to 2 or more" };
|
|
921
|
-
return {
|
|
922
|
-
diff: ["HEAD^1", "HEAD"],
|
|
923
|
-
log: ["HEAD^1..HEAD"],
|
|
924
|
-
ends: ["HEAD^1", "HEAD^2"]
|
|
925
|
-
};
|
|
703
|
+
return null;
|
|
926
704
|
}
|
|
927
705
|
/**
|
|
928
|
-
*
|
|
929
|
-
*
|
|
706
|
+
* A field of an item heading: "- Area: Docs", "- **Area:** Docs" or "- **Area**: Docs". The label
|
|
707
|
+
* matches without case.
|
|
930
708
|
*/
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
]);
|
|
941
|
-
if (out === void 0) return void 0;
|
|
942
|
-
return new Set(out.split(/\r?\n/).filter((file) => file !== ""));
|
|
943
|
-
}
|
|
709
|
+
const ITEM_FIELD = /^\s*[-*]\s+(\*\*|__)?([A-Za-z][A-Za-z ]*?)(?::\1|\1:)\s*(\S.*)?$/;
|
|
710
|
+
/** The fields of an item heading that give the optional fields of an item. */
|
|
711
|
+
const ITEM_FIELDS = {
|
|
712
|
+
area: "area",
|
|
713
|
+
owner: "owner",
|
|
714
|
+
"waits for": "needs",
|
|
715
|
+
needs: "needs",
|
|
716
|
+
"depends on": "needs"
|
|
717
|
+
};
|
|
944
718
|
/**
|
|
945
|
-
* This function gives the
|
|
946
|
-
*
|
|
719
|
+
* This function gives the items of the second form of a roadmap: each heading "### `id`: Title" or
|
|
720
|
+
* "### id · Title". The list item "Status:" gives the status. Without it, the "##" heading above
|
|
721
|
+
* the item gives the status, for example "Waiting on Mark", "Later" or "Shipped". A heading without
|
|
722
|
+
* a status is not an item.
|
|
723
|
+
*
|
|
724
|
+
* The list items "Area:", "Owner:" and "Waits for:" give the optional fields. The list item
|
|
725
|
+
* "Links:" and the other list items give the links. Fenced code is not read.
|
|
947
726
|
*/
|
|
948
|
-
function
|
|
949
|
-
const
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
"
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
...range.diff
|
|
961
|
-
]);
|
|
962
|
-
if (out === void 0) return void 0;
|
|
963
|
-
const lines = /* @__PURE__ */ new Map();
|
|
964
|
-
let file;
|
|
965
|
-
for (const line of out.split(/\r?\n/)) {
|
|
966
|
-
if (line.startsWith("+++ ")) {
|
|
967
|
-
file = line === "+++ /dev/null" ? void 0 : line.slice(6);
|
|
727
|
+
function headingItems(markdown, options) {
|
|
728
|
+
const lines = String(markdown).split(/\r?\n/);
|
|
729
|
+
const items = [];
|
|
730
|
+
let section = "";
|
|
731
|
+
let current;
|
|
732
|
+
let fence = null;
|
|
733
|
+
for (let index = 0; index < lines.length; index++) {
|
|
734
|
+
const line = lines[index] ?? "";
|
|
735
|
+
const fenceMark = /^\s*(`{3,}|~{3,})/.exec(line)?.[1];
|
|
736
|
+
if (fenceMark !== void 0) {
|
|
737
|
+
if (fence === null) fence = fenceMark[0] ?? null;
|
|
738
|
+
else if (fenceMark[0] === fence) fence = null;
|
|
968
739
|
continue;
|
|
969
740
|
}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
741
|
+
if (fence !== null) continue;
|
|
742
|
+
const heading = headingOf(line);
|
|
743
|
+
if (heading) {
|
|
744
|
+
const { level } = heading;
|
|
745
|
+
if (level > 3) continue;
|
|
746
|
+
current = void 0;
|
|
747
|
+
if (level === 2) section = plainText(heading.text);
|
|
748
|
+
if (level === 1) section = "";
|
|
749
|
+
if (level !== 3) continue;
|
|
750
|
+
const item = itemHeadingOf(line);
|
|
751
|
+
const id = plainText(item?.id);
|
|
752
|
+
if (!item || isEmpty(id)) continue;
|
|
753
|
+
current = {
|
|
754
|
+
id,
|
|
755
|
+
title: item.title,
|
|
756
|
+
status: section,
|
|
757
|
+
statusClass: statusClassOf(section),
|
|
758
|
+
section,
|
|
759
|
+
line: index + 1,
|
|
760
|
+
links: []
|
|
761
|
+
};
|
|
762
|
+
items.push(current);
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
if (!current) continue;
|
|
766
|
+
const field = ITEM_FIELD.exec(line);
|
|
767
|
+
const label = (field?.[2] ?? "").trim().toLowerCase();
|
|
768
|
+
const value = (field?.[3] ?? "").trim();
|
|
769
|
+
const key = field ? ITEM_FIELDS[label] : void 0;
|
|
770
|
+
if (field && label === "status") {
|
|
771
|
+
if (!isEmpty(value)) {
|
|
772
|
+
current.status = value;
|
|
773
|
+
current.statusClass = statusClassOf(plainText(value));
|
|
774
|
+
}
|
|
775
|
+
} else if (field && key !== void 0) {
|
|
776
|
+
if (!isEmpty(value)) current[key] = value;
|
|
777
|
+
} else if (/^\s*[-*]\s+/.test(line)) {
|
|
778
|
+
const seen = new Set(current.links.map((link) => link.url));
|
|
779
|
+
for (const link of linksOf(line, options)) if (!seen.has(link.url)) current.links.push(link);
|
|
780
|
+
}
|
|
977
781
|
}
|
|
978
|
-
return
|
|
782
|
+
return items.filter((item) => item.status !== "");
|
|
979
783
|
}
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
"
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
"
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
784
|
+
/**
|
|
785
|
+
* This function gives the items of a roadmap file in the order of the file. It reads two forms:
|
|
786
|
+
*
|
|
787
|
+
* - Each row of each table with an `ID` column and a `Status` column. The header names match without
|
|
788
|
+
* case. The title comes from `Item`, else from `Title`. `Owner`, `Area` and `Needs` are optional.
|
|
789
|
+
* `Where`, `Commit` and `Links` give the links.
|
|
790
|
+
* - Each heading "### `id`: Title" or "### id · Title". The list item "Status:", else the "##"
|
|
791
|
+
* heading above it, gives the status. The list items "Area:", "Owner:" and "Waits for:" give the
|
|
792
|
+
* optional fields, and "Links:" and the other list items give the links.
|
|
793
|
+
*
|
|
794
|
+
* @throws RoadmapParseError when the cells of a row do not match the header
|
|
795
|
+
*/
|
|
796
|
+
function roadmapItems(markdown, options = {}) {
|
|
797
|
+
const { file = "ROADMAP.md" } = options;
|
|
798
|
+
const items = [];
|
|
799
|
+
for (const table of markdownTables(markdown)) {
|
|
800
|
+
const column = (...names) => names.map((name) => table.header.indexOf(name)).find((index) => index >= 0) ?? -1;
|
|
801
|
+
const id = column("id");
|
|
802
|
+
const status = column("status");
|
|
803
|
+
if (id < 0 || status < 0) continue;
|
|
804
|
+
const title = column("item", "title");
|
|
805
|
+
const owner = column("owner");
|
|
806
|
+
const area = column("area");
|
|
807
|
+
const needs = column("needs");
|
|
808
|
+
const linkColumns = LINK_COLUMNS.map((name) => table.header.indexOf(name)).filter((index) => index >= 0);
|
|
809
|
+
for (const row of table.rows) {
|
|
810
|
+
if (row.cells.length !== table.header.length) throw new RoadmapParseError(`${file}:${row.line}: the row has ${row.cells.length} cells, and the header has ${table.header.length}`);
|
|
811
|
+
const idText = plainText(row.cells[id]);
|
|
812
|
+
if (isEmpty(idText)) continue;
|
|
813
|
+
const statusText = row.cells[status] ?? "";
|
|
814
|
+
const item = {
|
|
815
|
+
id: idText,
|
|
816
|
+
title: title >= 0 ? row.cells[title] ?? "" : "",
|
|
817
|
+
status: statusText,
|
|
818
|
+
statusClass: statusClassOf(plainText(statusText)),
|
|
819
|
+
section: table.section,
|
|
820
|
+
line: row.line,
|
|
821
|
+
links: linkColumns.flatMap((index) => linksOf(row.cells[index], {
|
|
822
|
+
...options,
|
|
823
|
+
file
|
|
824
|
+
}))
|
|
825
|
+
};
|
|
826
|
+
const optional = (index) => index >= 0 && !isEmpty(row.cells[index]) ? row.cells[index] : void 0;
|
|
827
|
+
const ownerText = optional(owner);
|
|
828
|
+
const areaText = optional(area);
|
|
829
|
+
const needsText = optional(needs);
|
|
830
|
+
if (ownerText !== void 0) item.owner = ownerText;
|
|
831
|
+
if (areaText !== void 0) item.area = areaText;
|
|
832
|
+
if (needsText !== void 0) item.needs = needsText;
|
|
833
|
+
items.push(item);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
const headings = headingItems(markdown, {
|
|
837
|
+
...options,
|
|
838
|
+
file
|
|
839
|
+
});
|
|
840
|
+
return headings.length === 0 ? items : [...items, ...headings].sort((a, b) => a.line - b.line);
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* This function gives the items of a roadmap file, as the Status page reads them. It fails when the file has no item.
|
|
844
|
+
*
|
|
845
|
+
* @throws RoadmapParseError when the cells of a row do not match the header
|
|
846
|
+
* @throws RoadmapParseError when the roadmap has no item: no table with an ID and a Status column, and no item heading
|
|
847
|
+
*/
|
|
848
|
+
function parseRoadmap(markdown, options = {}) {
|
|
849
|
+
const { file = "ROADMAP.md" } = options;
|
|
850
|
+
const items = roadmapItems(markdown, options);
|
|
851
|
+
if (items.length === 0) throw new RoadmapParseError(`${file}: no table with an ID column and a Status column, and no heading "### \`id\`: Title"`);
|
|
852
|
+
return items;
|
|
853
|
+
}
|
|
854
|
+
String.raw`
|
|
855
|
+
const boxes = Array.from(document.querySelectorAll("[data-sp-timeline]"));
|
|
856
|
+
const panels = new Map(Array.from(document.querySelectorAll("[data-sp-release]"), (panel) => [panel.dataset.version, panel]));
|
|
857
|
+
const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
858
|
+
let selected = (document.querySelector("[data-sp-release]:not([hidden])") || {}).dataset?.version;
|
|
859
|
+
const markIn = (box, version) => Array.from(box.querySelectorAll("[data-sp-mark]")).find((mark) => mark.dataset.version === version);
|
|
860
|
+
function reveal(box, version, smooth) {
|
|
861
|
+
const mark = markIn(box, version);
|
|
862
|
+
if (!mark || box.scrollWidth <= box.clientWidth) return;
|
|
863
|
+
const x = Number(mark.dataset.x);
|
|
864
|
+
const margin = Number(mark.dataset.half) + 16;
|
|
865
|
+
if (x - margin >= box.scrollLeft && x + margin <= box.scrollLeft + box.clientWidth) return;
|
|
866
|
+
box.scrollTo({ left: x - box.clientWidth / 2, behavior: smooth && !reduced ? "smooth" : "auto" });
|
|
867
|
+
}
|
|
868
|
+
function select(version, box) {
|
|
869
|
+
const panel = panels.get(version);
|
|
870
|
+
if (!panel) return;
|
|
871
|
+
selected = version;
|
|
872
|
+
for (const each of boxes) {
|
|
873
|
+
for (const mark of each.querySelectorAll("[data-sp-mark]")) {
|
|
874
|
+
const on = mark.dataset.version === version;
|
|
875
|
+
mark.classList.toggle("sp-selected", on);
|
|
876
|
+
mark.setAttribute("aria-pressed", String(on));
|
|
877
|
+
mark.setAttribute("tabindex", on ? "0" : "-1");
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
for (const [key, each] of panels) each.hidden = key !== version;
|
|
881
|
+
if (box) {
|
|
882
|
+
const mark = markIn(box, version);
|
|
883
|
+
if (mark) mark.focus({ preventScroll: true });
|
|
884
|
+
reveal(box, version, true);
|
|
885
|
+
}
|
|
886
|
+
try {
|
|
887
|
+
history.replaceState(null, "", "#" + encodeURIComponent(panel.id));
|
|
888
|
+
} catch {}
|
|
889
|
+
}
|
|
890
|
+
for (const box of boxes) {
|
|
891
|
+
box.addEventListener("click", (event) => {
|
|
892
|
+
const mark = event.target.closest("[data-sp-mark]");
|
|
893
|
+
if (mark) select(mark.dataset.version, box);
|
|
894
|
+
});
|
|
895
|
+
box.addEventListener("keydown", (event) => {
|
|
896
|
+
const mark = event.target.closest("[data-sp-mark]");
|
|
897
|
+
if (!mark || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
898
|
+
const marks = Array.from(box.querySelectorAll("[data-sp-mark]"));
|
|
899
|
+
const position = marks.indexOf(mark);
|
|
900
|
+
const targets = { ArrowLeft: position - 1, ArrowRight: position + 1, Home: 0, End: marks.length - 1, Enter: position, " ": position };
|
|
901
|
+
if (!(event.key in targets)) return;
|
|
902
|
+
event.preventDefault();
|
|
903
|
+
const next = marks[Math.max(0, Math.min(marks.length - 1, targets[event.key]))];
|
|
904
|
+
if (next) select(next.dataset.version, box);
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
document.addEventListener("click", (event) => {
|
|
908
|
+
const button = event.target.closest("[data-sp-toggle]");
|
|
909
|
+
const list = button && document.getElementById(button.getAttribute("aria-controls"));
|
|
910
|
+
if (!list) return;
|
|
911
|
+
const open = button.getAttribute("aria-expanded") !== "true";
|
|
912
|
+
for (const extra of list.querySelectorAll(":scope > .sp-extra")) extra.hidden = !open;
|
|
913
|
+
button.setAttribute("aria-expanded", String(open));
|
|
914
|
+
const label = button.querySelector("[data-sp-label]");
|
|
915
|
+
if (label) label.textContent = open ? button.dataset.less : button.dataset.more;
|
|
916
|
+
});
|
|
917
|
+
// A malformed hash, for example "#100%", must not stop the module
|
|
918
|
+
let hashed = "";
|
|
919
|
+
try {
|
|
920
|
+
hashed = decodeURIComponent(location.hash.slice(1));
|
|
921
|
+
} catch {}
|
|
922
|
+
for (const [version, panel] of panels) if (panel.id === hashed) select(version, null);
|
|
923
|
+
const revealAll = () => { for (const box of boxes) reveal(box, selected, false); };
|
|
924
|
+
revealAll();
|
|
925
|
+
window.addEventListener("resize", revealAll);
|
|
926
|
+
`;
|
|
927
|
+
String.raw`
|
|
928
|
+
function relativeTime(then, now) {
|
|
929
|
+
const seconds = Math.round((now - then) / 1000);
|
|
930
|
+
if (!Number.isFinite(seconds)) return "at an unknown time";
|
|
931
|
+
if (seconds < 60) return "just now";
|
|
932
|
+
const steps = [[60, "minute"], [3600, "hour"], [86400, "day"], [2592000, "month"], [31536000, "year"]];
|
|
933
|
+
let unit = steps[0];
|
|
934
|
+
for (const step of steps) if (seconds >= step[0]) unit = step;
|
|
935
|
+
const count = Math.floor(seconds / unit[0]);
|
|
936
|
+
return count + " " + unit[1] + (count === 1 ? "" : "s") + " ago";
|
|
937
|
+
}
|
|
938
|
+
function listOf(text) {
|
|
939
|
+
return (text || "").split(",").filter((part) => part !== "");
|
|
940
|
+
}
|
|
941
|
+
` + String.raw`
|
|
942
|
+
const now = Date.now();
|
|
943
|
+
for (const time of document.querySelectorAll("time[data-sp-rel]")) {
|
|
944
|
+
time.textContent = relativeTime(Date.parse(time.dateTime), now) + " (" + time.title + ")";
|
|
945
|
+
}
|
|
946
|
+
const board = document.querySelector("[data-sp-board]");
|
|
947
|
+
if (board) {
|
|
948
|
+
const classChips = Array.from(board.querySelectorAll("[data-sp-class]"));
|
|
949
|
+
const sectionChips = Array.from(board.querySelectorAll("[data-sp-section]"));
|
|
950
|
+
const groups = Array.from(board.querySelectorAll("[data-sp-group]"));
|
|
951
|
+
const shown = board.querySelector("[data-sp-shown]");
|
|
952
|
+
const empty = board.querySelector("[data-sp-empty]");
|
|
953
|
+
const clear = board.querySelector("[data-sp-clear]");
|
|
954
|
+
const done = board.querySelector("[data-sp-done]");
|
|
955
|
+
const query = new URLSearchParams(location.search);
|
|
956
|
+
const state = {
|
|
957
|
+
classes: listOf(query.get("status")).filter((value) => classChips.some((chip) => chip.dataset.spClass === value)),
|
|
958
|
+
sections: listOf(query.get("section")),
|
|
959
|
+
};
|
|
960
|
+
if (done && query.get("done") === "1") done.open = true;
|
|
961
|
+
const apply = (write) => {
|
|
962
|
+
for (const chip of classChips) chip.setAttribute("aria-pressed", String(state.classes.includes(chip.dataset.spClass)));
|
|
963
|
+
for (const chip of sectionChips) chip.setAttribute("aria-pressed", String(state.sections.includes(chip.dataset.spSection)));
|
|
964
|
+
let count = 0;
|
|
965
|
+
for (const group of groups) {
|
|
966
|
+
const isDone = group.dataset.class === "done";
|
|
967
|
+
const classOn = isDone || state.classes.length === 0 || state.classes.includes(group.dataset.class);
|
|
968
|
+
let visible = 0;
|
|
969
|
+
for (const row of group.querySelectorAll("tr[data-section]")) {
|
|
970
|
+
const on = classOn && (state.sections.length === 0 || state.sections.includes(row.dataset.section));
|
|
971
|
+
row.hidden = !on;
|
|
972
|
+
if (on) visible++;
|
|
973
|
+
}
|
|
974
|
+
if (isDone) {
|
|
975
|
+
const none = group.querySelector("[data-sp-done-empty]");
|
|
976
|
+
if (none) none.hidden = visible > 0;
|
|
977
|
+
} else {
|
|
978
|
+
group.hidden = visible === 0;
|
|
979
|
+
const badge = group.querySelector("[data-sp-group-count]");
|
|
980
|
+
if (badge) badge.textContent = String(visible);
|
|
981
|
+
count += visible;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
if (shown) shown.textContent = count + " of " + shown.dataset.label;
|
|
985
|
+
if (empty) empty.hidden = count > 0;
|
|
986
|
+
if (clear) clear.hidden = state.classes.length === 0 && state.sections.length === 0;
|
|
987
|
+
if (done) {
|
|
988
|
+
const label = done.querySelector("[data-sp-done-label]");
|
|
989
|
+
if (label) label.textContent = done.open ? "Hide the done items" : "Show the done items";
|
|
990
|
+
}
|
|
991
|
+
if (!write) return;
|
|
992
|
+
const next = new URLSearchParams(location.search);
|
|
993
|
+
const put = (key, value) => (value ? next.set(key, value) : next.delete(key));
|
|
994
|
+
put("status", state.classes.join(","));
|
|
995
|
+
put("section", state.sections.join(","));
|
|
996
|
+
put("done", done && done.open ? "1" : "");
|
|
997
|
+
const search = next.toString();
|
|
998
|
+
try {
|
|
999
|
+
history.replaceState(null, "", location.pathname + (search ? "?" + search : "") + location.hash);
|
|
1000
|
+
} catch {}
|
|
1001
|
+
};
|
|
1002
|
+
const toggle = (list, value) => (list.includes(value) ? list.filter((each) => each !== value) : list.concat(value));
|
|
1003
|
+
board.addEventListener("click", (event) => {
|
|
1004
|
+
const chip = event.target.closest("button");
|
|
1005
|
+
if (!chip) return;
|
|
1006
|
+
if (chip.dataset.spClass) state.classes = toggle(state.classes, chip.dataset.spClass);
|
|
1007
|
+
else if (chip.dataset.spSection) state.sections = toggle(state.sections, chip.dataset.spSection);
|
|
1008
|
+
else if (chip.hasAttribute("data-sp-clear")) {
|
|
1009
|
+
state.classes = [];
|
|
1010
|
+
state.sections = [];
|
|
1011
|
+
} else return;
|
|
1012
|
+
apply(true);
|
|
1013
|
+
});
|
|
1014
|
+
if (done) done.addEventListener("toggle", () => apply(true));
|
|
1015
|
+
apply(false);
|
|
1016
|
+
}
|
|
1017
|
+
`;
|
|
1018
|
+
// src/rules/changelog-version.ts
|
|
1019
|
+
/**
|
|
1020
|
+
* The rule `changelog-version`: the top release section of the changelog of a package is not above the version of
|
|
1021
|
+
* its `package.json`.
|
|
1022
|
+
*/
|
|
1023
|
+
/** This function gives the version and the line (from 1) of the first version section of a changelog, or undefined. */
|
|
1024
|
+
function topSection(text) {
|
|
1025
|
+
const top = parseChangelog(text)[0];
|
|
1026
|
+
if (top === void 0) return void 0;
|
|
1027
|
+
const index = text.split(/\r?\n/).findIndex((line) => /^##\s/.test(line) && line.replace(/^##\s+/, "").trim() === top.heading);
|
|
1028
|
+
return {
|
|
1029
|
+
version: top.version,
|
|
1030
|
+
line: index + 1
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
/** The packages with a release version: the root package and the code packages that are not private and have a name and a version. */
|
|
1034
|
+
function versioned(context) {
|
|
1035
|
+
const all = [context.rootPackage, ...codePackages(context)];
|
|
1036
|
+
return all.filter((pkg, index) => all.findIndex((other) => other.file === pkg.file) === index).filter((pkg) => pkg.manifest["private"] !== true && typeof pkg.manifest["name"] === "string" && typeof pkg.manifest["version"] === "string");
|
|
1037
|
+
}
|
|
1038
|
+
const changelogVersion = {
|
|
1039
|
+
id: "changelog-version",
|
|
1040
|
+
title: "The top release section of the changelog of a package is not above the version of its package.json. With the option `everyVersion`, it is the same version.",
|
|
1041
|
+
reason: "On 2026-11-03 a pull request added the section 0.5.0 with two breaking changes to a changelog, and left package.json at 0.4.1. The next change of a dependency range made the train plan a PATCH 0.4.2, so the breaking changes were about to ship under a PATCH number.",
|
|
1042
|
+
fix: "Set the version of package.json to the version of the top section in the same change, by the rules of Semantic Versioning. Or, if the release is not ready, name the section Unreleased.",
|
|
1043
|
+
sources: [
|
|
1044
|
+
{
|
|
1045
|
+
repo: "packing",
|
|
1046
|
+
rule: "changelog",
|
|
1047
|
+
doc: "packages/packing/CHANGELOG.md (#249 added 0.5.0, package.json stayed 0.4.1; #253 set 0.5.0)"
|
|
1048
|
+
},
|
|
1049
|
+
{
|
|
1050
|
+
repo: "release-train",
|
|
1051
|
+
rule: "cascade",
|
|
1052
|
+
doc: "the train plans a PATCH for a change of a dependency range"
|
|
1053
|
+
},
|
|
1054
|
+
{
|
|
1055
|
+
repo: "fleet",
|
|
1056
|
+
rule: "semver",
|
|
1057
|
+
doc: "the global CLAUDE.md, npm packages use Semantic Versioning"
|
|
1058
|
+
}
|
|
1059
|
+
],
|
|
1060
|
+
options: {
|
|
1061
|
+
file: {
|
|
1062
|
+
type: "string",
|
|
1063
|
+
default: "CHANGELOG.md",
|
|
1064
|
+
description: "The name of the changelog in the folder of each package."
|
|
1065
|
+
},
|
|
1066
|
+
everyVersion: {
|
|
1067
|
+
type: "boolean",
|
|
1068
|
+
default: false,
|
|
1069
|
+
description: "When true, the top section also names the version of package.json: each version has its section."
|
|
1070
|
+
}
|
|
1071
|
+
},
|
|
1072
|
+
check(context, options) {
|
|
1073
|
+
const name = String(options["file"]);
|
|
1074
|
+
const breaks = [];
|
|
1075
|
+
let found = 0;
|
|
1076
|
+
for (const pkg of versioned(context)) {
|
|
1077
|
+
const file = pkg.folder === "" ? name : `${pkg.folder}/${name}`;
|
|
1078
|
+
if (!existsSync(join(context.root, file))) continue;
|
|
1079
|
+
found += 1;
|
|
1080
|
+
const version = String(pkg.manifest["version"]);
|
|
1081
|
+
const top = topSection(readFileSync(join(context.root, file), "utf8"));
|
|
1082
|
+
if (top === void 0) {
|
|
1083
|
+
if (options["everyVersion"] === true) breaks.push({
|
|
1084
|
+
file,
|
|
1085
|
+
message: `${file} has no section for a version, and ${pkg.file} is at ${version}.`
|
|
1086
|
+
});
|
|
1087
|
+
continue;
|
|
1088
|
+
}
|
|
1089
|
+
const order = compareVersions(top.version, version);
|
|
1090
|
+
if (order > 0) breaks.push({
|
|
1091
|
+
file,
|
|
1092
|
+
line: top.line,
|
|
1093
|
+
message: `${file} has the section ${top.version}, and ${pkg.file} is still at ${version}. Set the version to ${top.version} in this change. Else a change of a dependency range releases a PATCH of ${version} under the notes of ${top.version}.`
|
|
1094
|
+
});
|
|
1095
|
+
else if (order < 0 && options["everyVersion"] === true) breaks.push({
|
|
1096
|
+
file,
|
|
1097
|
+
line: top.line,
|
|
1098
|
+
message: `${pkg.file} is at ${version}, and the top section of ${file} is ${top.version}. Add the section ${version}.`
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
if (found === 0) return { skipped: `no package with a release version has a file ${name}` };
|
|
1102
|
+
return breaks;
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
// src/rules/cue-preset.ts
|
|
1106
|
+
/**
|
|
1107
|
+
* The rule `cue-preset`: the `tsconfig.json` of each package extends a preset of `@mark1russell7/cue`.
|
|
1108
|
+
* No config of a package turns off a strict option of its preset.
|
|
1109
|
+
*/
|
|
1110
|
+
/** The compiler options that make the type check strict. A package does not turn them off. */
|
|
1111
|
+
const STRICT_OPTIONS = [
|
|
1112
|
+
"strict",
|
|
1113
|
+
"noImplicitAny",
|
|
1114
|
+
"strictNullChecks",
|
|
1115
|
+
"strictFunctionTypes",
|
|
1116
|
+
"strictBindCallApply",
|
|
1117
|
+
"strictPropertyInitialization",
|
|
1118
|
+
"strictBuiltinIteratorReturn",
|
|
1119
|
+
"noImplicitThis",
|
|
1120
|
+
"useUnknownInCatchVariables",
|
|
1121
|
+
"alwaysStrict",
|
|
1122
|
+
"noUncheckedIndexedAccess",
|
|
1123
|
+
"exactOptionalPropertyTypes",
|
|
1124
|
+
"noImplicitOverride",
|
|
1125
|
+
"noImplicitReturns",
|
|
1126
|
+
"noFallthroughCasesInSwitch",
|
|
1127
|
+
"noPropertyAccessFromIndexSignature"
|
|
1128
|
+
];
|
|
1129
|
+
/** The options that `strict` turns on when a config does not set them. */
|
|
1130
|
+
const STRICT_FAMILY = /* @__PURE__ */ new Set([
|
|
1131
|
+
"noImplicitAny",
|
|
1132
|
+
"strictNullChecks",
|
|
1133
|
+
"strictFunctionTypes",
|
|
1134
|
+
"strictBindCallApply",
|
|
1135
|
+
"strictPropertyInitialization",
|
|
1136
|
+
"strictBuiltinIteratorReturn",
|
|
1137
|
+
"noImplicitThis",
|
|
1138
|
+
"useUnknownInCatchVariables",
|
|
1139
|
+
"alwaysStrict"
|
|
1140
|
+
]);
|
|
1141
|
+
const asObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
1142
|
+
/** This function gives the `extends` list of a tsconfig. */
|
|
1143
|
+
const extendsOf = (config) => {
|
|
1144
|
+
const value = config["extends"];
|
|
1145
|
+
if (typeof value === "string") return [value];
|
|
1146
|
+
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
1147
|
+
};
|
|
1148
|
+
/**
|
|
1149
|
+
* This function gives the compiler options of the configs that `config` extends, with the options of
|
|
1150
|
+
* a later config over an earlier one.
|
|
1151
|
+
*/
|
|
1152
|
+
function inheritedOptions(config, dir, depth = 0) {
|
|
1153
|
+
if (depth > 10) return {
|
|
1154
|
+
options: {},
|
|
1155
|
+
complete: false
|
|
1156
|
+
};
|
|
1157
|
+
let options = {};
|
|
1158
|
+
let complete = true;
|
|
1159
|
+
for (const base of extendsOf(config)) {
|
|
1160
|
+
let file;
|
|
1161
|
+
if (base.startsWith(".")) file = resolve(dir, base.endsWith(".json") ? base : `${base}.json`);
|
|
1162
|
+
else try {
|
|
1163
|
+
file = createRequire(join(dir, "package.json")).resolve(base);
|
|
1164
|
+
} catch {
|
|
1165
|
+
file = void 0;
|
|
1166
|
+
}
|
|
1167
|
+
const parent = file === void 0 ? void 0 : readJsonc(file);
|
|
1168
|
+
if (parent === void 0 || file === void 0) {
|
|
1169
|
+
complete = false;
|
|
1170
|
+
continue;
|
|
1171
|
+
}
|
|
1172
|
+
const above = inheritedOptions(asObject(parent), dirname(file), depth + 1);
|
|
1173
|
+
complete &&= above.complete;
|
|
1174
|
+
options = {
|
|
1175
|
+
...options,
|
|
1176
|
+
...above.options,
|
|
1177
|
+
...asObject(asObject(parent)["compilerOptions"])
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
return {
|
|
1181
|
+
options,
|
|
1182
|
+
complete
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* This function tells if a config that extends configs with the options `inherited` turns on the
|
|
1187
|
+
* option. When the rule cannot read each config, it gives true: the package turns off a strict option.
|
|
1188
|
+
*/
|
|
1189
|
+
function inheritedOn(option, inherited) {
|
|
1190
|
+
if (!inherited.complete) return true;
|
|
1191
|
+
const value = inherited.options[option];
|
|
1192
|
+
if (typeof value === "boolean") return value;
|
|
1193
|
+
return STRICT_FAMILY.has(option) && inherited.options["strict"] === true;
|
|
1194
|
+
}
|
|
1195
|
+
const cuePreset = {
|
|
1196
|
+
id: "cue-preset",
|
|
1197
|
+
title: "The `tsconfig.json` of each package extends a preset of `@mark1russell7/cue`, and no config of a package turns off a strict option.",
|
|
1198
|
+
reason: "`pnpm package add` writes the configs from a preset, so each package checks its types with the same strict options. A config by hand or a strict option turned off lets the packages drift apart.",
|
|
1199
|
+
fix: "Make the package with `pnpm package add <name> --preset=<preset>`, or set `extends` to `@mark1russell7/cue/ts/config/<preset>.json`. Correct the code, not the strict option.",
|
|
1200
|
+
sources: [
|
|
1201
|
+
{
|
|
1202
|
+
repo: "client",
|
|
1203
|
+
rule: "cue-config",
|
|
1204
|
+
doc: "CLAUDE.md:64"
|
|
1205
|
+
},
|
|
1206
|
+
{
|
|
1207
|
+
repo: "client",
|
|
1208
|
+
rule: "no-manual-tsconfig",
|
|
1209
|
+
doc: "CLAUDE.md:64"
|
|
1210
|
+
},
|
|
1211
|
+
{
|
|
1212
|
+
repo: "Graph",
|
|
1213
|
+
rule: "cue-preset-strict",
|
|
1214
|
+
doc: "docs/architecture/ecosystem-and-structure.md:58"
|
|
1215
|
+
},
|
|
1216
|
+
{
|
|
1217
|
+
repo: "Graph",
|
|
1218
|
+
rule: "strict-preset",
|
|
1219
|
+
doc: "docs/architecture/ecosystem-and-structure.md:58"
|
|
1220
|
+
},
|
|
1221
|
+
{
|
|
1222
|
+
repo: "Graph",
|
|
1223
|
+
rule: "new-package-via-cli",
|
|
1224
|
+
doc: "CLAUDE.md:14"
|
|
1225
|
+
},
|
|
1226
|
+
{
|
|
1227
|
+
repo: "coeval",
|
|
1228
|
+
rule: "package-scaffold",
|
|
1229
|
+
doc: "CLAUDE.md:16"
|
|
1230
|
+
},
|
|
1231
|
+
{
|
|
1232
|
+
repo: "crawler",
|
|
1233
|
+
rule: "package-scaffold",
|
|
1234
|
+
doc: "CLAUDE.md:16"
|
|
1235
|
+
},
|
|
1236
|
+
{
|
|
1237
|
+
repo: "headroom",
|
|
1238
|
+
rule: "package-scaffold",
|
|
1239
|
+
doc: "CLAUDE.md:30"
|
|
1240
|
+
},
|
|
1241
|
+
{
|
|
1242
|
+
repo: "Vex",
|
|
1243
|
+
rule: "package-scaffold",
|
|
1244
|
+
doc: "CLAUDE.md:22"
|
|
1245
|
+
}
|
|
1246
|
+
],
|
|
1247
|
+
options: {
|
|
1248
|
+
prefix: {
|
|
1249
|
+
type: "string",
|
|
1250
|
+
default: "@mark1russell7/cue/",
|
|
1251
|
+
description: "The start of the `extends` path of a preset."
|
|
1252
|
+
},
|
|
1253
|
+
extends: {
|
|
1254
|
+
type: "boolean",
|
|
1255
|
+
default: true,
|
|
1256
|
+
description: "When false, the rule does not examine `extends`. It still reports each strict option that a config turns off. For a package that publishes its own presets."
|
|
1257
|
+
}
|
|
1258
|
+
},
|
|
1259
|
+
check(context, options) {
|
|
1260
|
+
const prefix = typeof options["prefix"] === "string" ? options["prefix"] : "@mark1russell7/cue/";
|
|
1261
|
+
const breaks = [];
|
|
1262
|
+
for (const info of codePackages(context)) {
|
|
1263
|
+
if (!hasFile(info.dir, "tsconfig.json")) continue;
|
|
1264
|
+
for (const name of ["tsconfig.json", "tsconfig.test.json"]) {
|
|
1265
|
+
const path = join(info.dir, name);
|
|
1266
|
+
const file = inFolder(info.folder, name);
|
|
1267
|
+
const value = readJsonc(path);
|
|
1268
|
+
if (value === void 0) {
|
|
1269
|
+
if (hasFile(info.dir, name)) breaks.push({
|
|
1270
|
+
file,
|
|
1271
|
+
message: `${name} is not JSON.`,
|
|
1272
|
+
fix: "Correct the JSON."
|
|
1273
|
+
});
|
|
1274
|
+
continue;
|
|
1275
|
+
}
|
|
1276
|
+
const config = asObject(value);
|
|
1277
|
+
if (name === "tsconfig.json" && options["extends"] !== false && !extendsOf(config).some((base) => base.startsWith(prefix))) {
|
|
1278
|
+
const line = lineOf(readFileSync(path, "utf8"), "\"extends\"");
|
|
1279
|
+
breaks.push({
|
|
1280
|
+
file,
|
|
1281
|
+
...line === void 0 ? {} : { line },
|
|
1282
|
+
message: `tsconfig.json does not extend a preset of ${prefix.replace(/\/$/, "")}.`
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
const own = asObject(config["compilerOptions"]);
|
|
1286
|
+
const inherited = inheritedOptions(config, info.dir);
|
|
1287
|
+
for (const option of STRICT_OPTIONS) {
|
|
1288
|
+
if (own[option] !== false || !inheritedOn(option, inherited)) continue;
|
|
1289
|
+
breaks.push({
|
|
1290
|
+
file,
|
|
1291
|
+
message: `${name} turns off the strict option ${option}.`,
|
|
1292
|
+
fix: `Remove "${option}": false, and correct the code that it hides.`
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
return breaks;
|
|
1298
|
+
}
|
|
1299
|
+
};
|
|
1300
|
+
// src/workflow.ts
|
|
1301
|
+
/**
|
|
1302
|
+
* A small reader of GitHub workflow files, by the indent of the lines. The rules that read workflows share it. It
|
|
1303
|
+
* knows the block form, the inline values of keys and the block scalars (`|` and `>`) that the workflows of the template
|
|
1304
|
+
* use. `readWorkflow` gives the parts of a shared workflow that the site of the template shows.
|
|
1305
|
+
*/
|
|
1306
|
+
/** A workflow file. */
|
|
1307
|
+
const WORKFLOW$1 = /^\.github\/workflows\/[^/]+\.ya?ml$/;
|
|
1308
|
+
const indentOf$1 = (line) => line.length - line.trimStart().length;
|
|
1309
|
+
/** This function gives the lines of a workflow, with each line of a comment made empty. */
|
|
1310
|
+
const workflowLines = (text) => text.split(/\r?\n/).map((line) => line.trimStart().startsWith("#") ? "" : line);
|
|
1311
|
+
/** This function removes a comment at the end of a value, and the quotes around it. */
|
|
1312
|
+
function valueOf$1(raw) {
|
|
1313
|
+
const comment = raw.search(/\s#/);
|
|
1314
|
+
let value = (comment >= 0 ? raw.slice(0, comment) : raw).trim();
|
|
1315
|
+
const quote = value.charAt(0);
|
|
1316
|
+
if (value.length >= 2 && (quote === "\"" || quote === "'") && value.endsWith(quote)) value = value.slice(1, -1).trim();
|
|
1317
|
+
return value;
|
|
1318
|
+
}
|
|
1319
|
+
/** This function gives the value of the key `key` on a line, or undefined when the line has another key. A quoted key ("on") counts too. */
|
|
1320
|
+
function keyValue(line, key) {
|
|
1321
|
+
let text = line.trimStart();
|
|
1322
|
+
if (text.startsWith("- ")) text = text.slice(2).trimStart();
|
|
1323
|
+
for (const form of [
|
|
1324
|
+
key,
|
|
1325
|
+
`"${key}"`,
|
|
1326
|
+
`'${key}'`
|
|
1327
|
+
]) if (text.startsWith(`${form}:`)) return valueOf$1(text.slice(form.length + 1));
|
|
1328
|
+
}
|
|
1329
|
+
/** This function gives the end of the block under the line `index`. The end is the next line with the same indent or a smaller one. */
|
|
1330
|
+
function blockEnd(lines, index) {
|
|
1331
|
+
const indent = indentOf$1(lines[index] ?? "");
|
|
1332
|
+
let end = index + 1;
|
|
1333
|
+
while (end < lines.length) {
|
|
1334
|
+
const line = lines[end] ?? "";
|
|
1335
|
+
if (line.trim() !== "" && indentOf$1(line) <= indent) break;
|
|
1336
|
+
end += 1;
|
|
1337
|
+
}
|
|
1338
|
+
return end;
|
|
1339
|
+
}
|
|
1340
|
+
/** This function gives the indent of the first key of the block under the line `index`, or undefined for an empty block. */
|
|
1341
|
+
function childIndent(lines, index) {
|
|
1342
|
+
const end = blockEnd(lines, index);
|
|
1343
|
+
for (let i = index + 1; i < end; i++) if ((lines[i] ?? "").trim() !== "") return indentOf$1(lines[i] ?? "");
|
|
1344
|
+
}
|
|
1345
|
+
/** This function gives the indexes of the keys of the block under the line `index`: the lines at the indent of its first key. */
|
|
1346
|
+
function childKeys(lines, index) {
|
|
1347
|
+
const indent = childIndent(lines, index);
|
|
1348
|
+
if (indent === void 0) return [];
|
|
1349
|
+
const keys = [];
|
|
1350
|
+
for (let i = index + 1; i < blockEnd(lines, index); i++) if ((lines[i] ?? "").trim() !== "" && indentOf$1(lines[i] ?? "") === indent) keys.push(i);
|
|
1351
|
+
return keys;
|
|
1352
|
+
}
|
|
1353
|
+
/** This function gives the text of a block scalar (`|`, `|-`, `>`, `>-`) under the line `index`. */
|
|
1354
|
+
function scalar(lines, index, style) {
|
|
1355
|
+
const body = lines.slice(index + 1, blockEnd(lines, index));
|
|
1356
|
+
const indent = Math.min(...body.filter((l) => l.trim() !== "").map(indentOf$1));
|
|
1357
|
+
const text = body.map((l) => l.slice(indent).trimEnd());
|
|
1358
|
+
return (style.startsWith(">") ? text.join(" ").replace(/\s+/g, " ") : text.join("\n")).trim();
|
|
1359
|
+
}
|
|
1360
|
+
/** This function gives the keys of the lines `start` to `end` at the indent `indent`. A first line can start with `- `. */
|
|
1361
|
+
function entries(lines, start, end, indent) {
|
|
1362
|
+
const map = /* @__PURE__ */ new Map();
|
|
1363
|
+
for (let i = start; i < end; i++) {
|
|
1364
|
+
const line = lines[i] ?? "";
|
|
1365
|
+
if (line.trim() === "") continue;
|
|
1366
|
+
let text = line;
|
|
1367
|
+
if (i === start && line.trimStart().startsWith("- ")) text = " ".repeat(indentOf$1(line) + 2) + line.trimStart().slice(2);
|
|
1368
|
+
if (indentOf$1(text) !== indent) continue;
|
|
1369
|
+
const match = /^\s*("[^"]+"|'[^']+'|[^\s:][^:]*):(?:\s(.*))?$/.exec(text);
|
|
1370
|
+
if (!match?.[1]) continue;
|
|
1371
|
+
const key = match[1].replace(/^["']|["']$/g, "");
|
|
1372
|
+
const raw = valueOf$1((match[2] ?? "").trim());
|
|
1373
|
+
map.set(key, {
|
|
1374
|
+
line: i,
|
|
1375
|
+
value: /^[|>][-+]?$/.test(raw) ? scalar(lines, i, raw) : raw
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
return map;
|
|
1379
|
+
}
|
|
1380
|
+
/** This function gives the keys of the block under the line `index`. */
|
|
1381
|
+
function childrenOf(lines, index) {
|
|
1382
|
+
const end = blockEnd(lines, index);
|
|
1383
|
+
const first = lines.slice(index + 1, end).find((l) => l.trim() !== "");
|
|
1384
|
+
return first === void 0 ? /* @__PURE__ */ new Map() : entries(lines, index + 1, end, indentOf$1(first));
|
|
1385
|
+
}
|
|
1386
|
+
/** This function gives the first line of each item of the list under the line `index`. */
|
|
1387
|
+
function itemsOf(lines, index) {
|
|
1388
|
+
const end = blockEnd(lines, index);
|
|
1389
|
+
const items = [];
|
|
1390
|
+
let indent;
|
|
1391
|
+
for (let i = index + 1; i < end; i++) {
|
|
1392
|
+
const line = lines[i] ?? "";
|
|
1393
|
+
if (!line.trimStart().startsWith("- ") && line.trim() !== "-") continue;
|
|
1394
|
+
indent ??= indentOf$1(line);
|
|
1395
|
+
if (indentOf$1(line) === indent) items.push(i);
|
|
1396
|
+
}
|
|
1397
|
+
return items;
|
|
1398
|
+
}
|
|
1399
|
+
/** This function gives the values of a list: an inline list (`[a, b]`), one value, or a block list. */
|
|
1400
|
+
function listOf(lines, entry) {
|
|
1401
|
+
if (entry === void 0) return [];
|
|
1402
|
+
const inline = entry.value.trim();
|
|
1403
|
+
if (inline.startsWith("[")) return inline.slice(1, -1).split(",").map(valueOf$1).filter(Boolean);
|
|
1404
|
+
if (inline !== "") return [inline];
|
|
1405
|
+
return itemsOf(lines, entry.line).map((i) => valueOf$1((lines[i] ?? "").trimStart().slice(2)));
|
|
1406
|
+
}
|
|
1407
|
+
/** This function gives an action of a `uses` value with no pin: `actions/checkout@<sha> # v7` gives `actions/checkout`. */
|
|
1408
|
+
const actionOf = (uses) => uses.split("@", 1)[0] ?? uses;
|
|
1409
|
+
/** This function gives the label of a step: its name, else its action, its id or its first command. */
|
|
1410
|
+
function stepLabel(step) {
|
|
1411
|
+
const name = step.get("name")?.value;
|
|
1412
|
+
if (name) return name;
|
|
1413
|
+
const uses = step.get("uses")?.value;
|
|
1414
|
+
if (uses) return actionOf(uses);
|
|
1415
|
+
const run = step.get("run")?.value.split("\n")[0];
|
|
1416
|
+
if (run) return run;
|
|
1417
|
+
return step.get("id")?.value ?? "step";
|
|
1418
|
+
}
|
|
1419
|
+
/** This function gives the summary of a workflow: the first paragraph of the comment at the top of the file. */
|
|
1420
|
+
function summaryOf(lines) {
|
|
1421
|
+
const words = [];
|
|
1422
|
+
for (const line of lines) {
|
|
1423
|
+
if (!line.startsWith("#")) break;
|
|
1424
|
+
const text = line.replace(/^#\s?/, "").trim();
|
|
1425
|
+
if (text === "") {
|
|
1426
|
+
if (words.length > 0) break;
|
|
1427
|
+
continue;
|
|
1428
|
+
}
|
|
1429
|
+
words.push(text);
|
|
1430
|
+
}
|
|
1431
|
+
return words.join(" ");
|
|
1432
|
+
}
|
|
1433
|
+
/** This function reads a shared workflow file. The file name goes into the result. */
|
|
1434
|
+
function readWorkflow(file, text) {
|
|
1435
|
+
const raw = text.split(/\r?\n/);
|
|
1436
|
+
const lines = raw.map((line) => line.trimStart().startsWith("#") ? "" : line);
|
|
1437
|
+
const top = entries(lines, 0, lines.length, 0);
|
|
1438
|
+
const on = top.get("on");
|
|
1439
|
+
const call = on ? childrenOf(lines, on.line).get("workflow_call") : void 0;
|
|
1440
|
+
const inputsEntry = call ? childrenOf(lines, call.line).get("inputs") : void 0;
|
|
1441
|
+
const inputs = [];
|
|
1442
|
+
if (inputsEntry) for (const [name, entry] of childrenOf(lines, inputsEntry.line)) {
|
|
1443
|
+
const keys = childrenOf(lines, entry.line);
|
|
1444
|
+
inputs.push({
|
|
1445
|
+
name,
|
|
1446
|
+
type: keys.get("type")?.value ?? "string",
|
|
1447
|
+
description: keys.get("description")?.value ?? "",
|
|
1448
|
+
default: keys.get("default")?.value ?? "",
|
|
1449
|
+
required: keys.get("required")?.value === "true"
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
const jobs = [];
|
|
1453
|
+
const jobsEntry = top.get("jobs");
|
|
1454
|
+
if (jobsEntry) for (const [id, entry] of childrenOf(lines, jobsEntry.line)) {
|
|
1455
|
+
const keys = childrenOf(lines, entry.line);
|
|
1456
|
+
const stepsEntry = keys.get("steps");
|
|
1457
|
+
const steps = [];
|
|
1458
|
+
if (stepsEntry) {
|
|
1459
|
+
const items = itemsOf(lines, stepsEntry.line);
|
|
1460
|
+
const last = blockEnd(lines, stepsEntry.line);
|
|
1461
|
+
items.forEach((start, n) => {
|
|
1462
|
+
const step = entries(lines, start, items[n + 1] ?? last, indentOf$1(lines[start] ?? "") + 2);
|
|
1463
|
+
steps.push({
|
|
1464
|
+
label: stepLabel(step),
|
|
1465
|
+
if: step.get("if")?.value ?? "",
|
|
1466
|
+
uses: actionOf(step.get("uses")?.value ?? "")
|
|
1467
|
+
});
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
const uses = keys.get("uses")?.value;
|
|
1471
|
+
if (steps.length === 0 && uses) steps.push({
|
|
1472
|
+
label: `calls ${actionOf(uses)}`,
|
|
1473
|
+
if: "",
|
|
1474
|
+
uses: actionOf(uses)
|
|
1475
|
+
});
|
|
1476
|
+
jobs.push({
|
|
1477
|
+
id,
|
|
1478
|
+
if: keys.get("if")?.value ?? "",
|
|
1479
|
+
needs: listOf(lines, keys.get("needs")),
|
|
1480
|
+
steps
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
return {
|
|
1484
|
+
file,
|
|
1485
|
+
name: top.get("name")?.value ?? file,
|
|
1486
|
+
summary: summaryOf(raw),
|
|
1487
|
+
inputs,
|
|
1488
|
+
jobs
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
// src/rules/gate-trigger.ts
|
|
1492
|
+
/**
|
|
1493
|
+
* The rule `gate-trigger`: a workflow that runs on pull requests starts on each pull request, with no path filter. The
|
|
1494
|
+
* ruleset needs the summary check "<Name> OK" of each gate. A workflow with `on.pull_request.paths` does not start
|
|
1495
|
+
* on each pull request, so its check is not always there, and the ruleset cannot ask for it.
|
|
1496
|
+
*/
|
|
1497
|
+
const TRIGGERS = ["pull_request", "pull_request_target"];
|
|
1498
|
+
const FILTERS = ["paths", "paths-ignore"];
|
|
1499
|
+
/** This function gives the path filters of the pull request triggers of a workflow. */
|
|
1500
|
+
function prPathFilters(text) {
|
|
1501
|
+
const lines = workflowLines(text);
|
|
1502
|
+
const on = lines.findIndex((line) => indentOf$1(line) === 0 && keyValue(line, "on") !== void 0);
|
|
1503
|
+
if (on < 0) return [];
|
|
1504
|
+
if ((keyValue(lines[on] ?? "", "on") ?? "") !== "") return [];
|
|
1505
|
+
const found = [];
|
|
1506
|
+
for (const at of childKeys(lines, on)) for (const trigger of TRIGGERS) {
|
|
1507
|
+
const value = keyValue(lines[at] ?? "", trigger);
|
|
1508
|
+
if (value === void 0) continue;
|
|
1509
|
+
for (const key of FILTERS) if (new RegExp(`(^|[{,\\s])${key}\\s*:`).test(value)) found.push({
|
|
1510
|
+
line: at + 1,
|
|
1511
|
+
trigger,
|
|
1512
|
+
key
|
|
1513
|
+
});
|
|
1514
|
+
for (const child of childKeys(lines, at)) for (const key of FILTERS) if (keyValue(lines[child] ?? "", key) !== void 0) found.push({
|
|
1515
|
+
line: child + 1,
|
|
1516
|
+
trigger,
|
|
1517
|
+
key
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
return found;
|
|
1521
|
+
}
|
|
1522
|
+
/** The commit of the template with the actions `changes` and `gate-summary`. Renovate updates the pins after the fix. */
|
|
1523
|
+
const ACTIONS_COMMIT = "f05c6eeb35e33a040bdfdcd7d07a1d2c00640f8d";
|
|
1524
|
+
/** This function gives the items of a list value: the flow form `[a, "b"]`, or the block form under the line `index`. */
|
|
1525
|
+
function listItems(lines, index, value) {
|
|
1526
|
+
if (value.startsWith("[") && value.endsWith("]")) return {
|
|
1527
|
+
items: value.slice(1, -1).split(",").map((item) => valueOf$1(item)).filter((item) => item !== ""),
|
|
1528
|
+
end: index + 1
|
|
1529
|
+
};
|
|
1530
|
+
if (value !== "") return void 0;
|
|
1531
|
+
const indent = indentOf$1(lines[index] ?? "");
|
|
1532
|
+
const items = [];
|
|
1533
|
+
let end = index + 1;
|
|
1534
|
+
for (let i = index + 1; i < lines.length; i++) {
|
|
1535
|
+
const line = lines[i] ?? "";
|
|
1536
|
+
if (line.trim() === "") continue;
|
|
1537
|
+
if (!(indentOf$1(line) > indent || indentOf$1(line) === indent && line.trimStart().startsWith("- "))) break;
|
|
1538
|
+
if (!line.trimStart().startsWith("- ")) return void 0;
|
|
1539
|
+
items.push(valueOf$1(line.trimStart().slice(2)));
|
|
1540
|
+
end = i + 1;
|
|
1541
|
+
}
|
|
1542
|
+
return {
|
|
1543
|
+
items,
|
|
1544
|
+
end
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
/** This function gives the name of the summary check of a workflow: its name with "OK", in the form that ruleset-ci-ok.ts reads. */
|
|
1548
|
+
function summaryName(workflowName) {
|
|
1549
|
+
const words = workflowName.replace(/[^A-Za-z0-9]+/g, " ").trim();
|
|
1550
|
+
return `${words === "" ? "Gate" : words.charAt(0).toUpperCase() + words.slice(1)} OK`;
|
|
1551
|
+
}
|
|
1552
|
+
/** This function puts an expression into the value of an `if`, as YAML that keeps it. */
|
|
1553
|
+
const ifValue = (expression) => {
|
|
1554
|
+
const value = `\${{ ${expression} }}`;
|
|
1555
|
+
return value.includes(": ") || value.includes(" #") ? `"${value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}"` : value;
|
|
1556
|
+
};
|
|
1557
|
+
/**
|
|
1558
|
+
* This function converts a gate workflow with a path filter on its pull request trigger. The trigger loses the filter,
|
|
1559
|
+
* and a job `changes` gets the same patterns. Each other job needs it and runs only on a match. A summary job
|
|
1560
|
+
* `<Name> OK` with the action gate-summary needs each job. The function gives the new text, or the reason why a
|
|
1561
|
+
* person must convert the workflow.
|
|
1562
|
+
*/
|
|
1563
|
+
function convertGate(text, file, commit = ACTIONS_COMMIT) {
|
|
1564
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
1565
|
+
const original = text.split(/\r?\n/);
|
|
1566
|
+
const lines = workflowLines(text);
|
|
1567
|
+
const top = (key) => lines.findIndex((line) => indentOf$1(line) === 0 && keyValue(line, key) !== void 0);
|
|
1568
|
+
const on = top("on");
|
|
1569
|
+
const jobsAt = top("jobs");
|
|
1570
|
+
if (on < 0 || jobsAt < 0) return { reason: "the workflow has no on block or no jobs block" };
|
|
1571
|
+
const splices = [];
|
|
1572
|
+
const filters = {};
|
|
1573
|
+
for (const at of childKeys(lines, on)) {
|
|
1574
|
+
const trigger = TRIGGERS.find((name) => keyValue(lines[at] ?? "", name) !== void 0);
|
|
1575
|
+
if (trigger === void 0) continue;
|
|
1576
|
+
if ((keyValue(lines[at] ?? "", trigger) ?? "") !== "") return { reason: `on.${trigger} has the flow form` };
|
|
1577
|
+
let filtered = false;
|
|
1578
|
+
for (const child of childKeys(lines, at)) {
|
|
1579
|
+
const key = FILTERS.find((name) => keyValue(lines[child] ?? "", name) !== void 0);
|
|
1580
|
+
if (key === void 0) continue;
|
|
1581
|
+
const list = listItems(lines, child, keyValue(lines[child] ?? "", key) ?? "");
|
|
1582
|
+
if (list === void 0) return { reason: `on.${trigger}.${key} is not a list` };
|
|
1583
|
+
const before = filters[key];
|
|
1584
|
+
if (before !== void 0 && before.join("\n") !== list.items.join("\n")) return { reason: `the triggers have different ${key}` };
|
|
1585
|
+
filters[key] = list.items;
|
|
1586
|
+
splices.push({
|
|
1587
|
+
at: child,
|
|
1588
|
+
remove: list.end - child,
|
|
1589
|
+
insert: []
|
|
1590
|
+
});
|
|
1591
|
+
filtered = true;
|
|
1592
|
+
}
|
|
1593
|
+
if (filtered) {
|
|
1594
|
+
const pad = " ".repeat(indentOf$1(lines[at] ?? ""));
|
|
1595
|
+
splices.push({
|
|
1596
|
+
at,
|
|
1597
|
+
remove: 0,
|
|
1598
|
+
insert: [`${pad}# Each pull request starts this workflow, so its summary check is always there. The job changes skips the`, `${pad}# work when the pull request changes no file of the gate (CI.md of the template, "A gate with paths").`]
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
if (Object.keys(filters).length === 0) return { reason: "the workflow has no path filter on a pull request trigger" };
|
|
1603
|
+
const jobs = childKeys(lines, jobsAt);
|
|
1604
|
+
const first = jobs[0];
|
|
1605
|
+
if (first === void 0) return { reason: "the workflow has no job" };
|
|
1606
|
+
const ids = jobs.map((at) => (lines[at] ?? "").trim().replace(/:$/, ""));
|
|
1607
|
+
const jobIndent = " ".repeat(indentOf$1(lines[first] ?? ""));
|
|
1608
|
+
const unit = " ".repeat((childIndent(lines, first) ?? indentOf$1(lines[first] ?? "") + 2) - jobIndent.length);
|
|
1609
|
+
const nameAt = top("name");
|
|
1610
|
+
const name = summaryName(nameAt >= 0 ? keyValue(lines[nameAt] ?? "", "name") ?? "" : (file.split("/").pop() ?? "").replace(/\.ya?ml$/, ""));
|
|
1611
|
+
const summaryId = name.toLowerCase().replaceAll(" ", "-");
|
|
1612
|
+
for (const id of ["changes", summaryId]) if (ids.includes(id)) return { reason: `the workflow already has a job ${id}` };
|
|
1613
|
+
const needsOf = /* @__PURE__ */ new Map();
|
|
1614
|
+
const own = /* @__PURE__ */ new Set();
|
|
1615
|
+
for (const [index, at] of jobs.entries()) {
|
|
1616
|
+
const id = ids[index] ?? "";
|
|
1617
|
+
const keys = childKeys(lines, at);
|
|
1618
|
+
const pad = " ".repeat(childIndent(lines, at) ?? indentOf$1(lines[at] ?? "") + unit.length);
|
|
1619
|
+
const needsAt = keys.find((key) => keyValue(lines[key] ?? "", "needs") !== void 0);
|
|
1620
|
+
const ifAt = keys.find((key) => keyValue(lines[key] ?? "", "if") !== void 0);
|
|
1621
|
+
if (needsAt === void 0) {
|
|
1622
|
+
needsOf.set(id, []);
|
|
1623
|
+
splices.push({
|
|
1624
|
+
at: at + 1,
|
|
1625
|
+
remove: 0,
|
|
1626
|
+
insert: [`${pad}needs: changes`]
|
|
1627
|
+
});
|
|
1628
|
+
} else {
|
|
1629
|
+
const value = keyValue(lines[needsAt] ?? "", "needs") ?? "";
|
|
1630
|
+
const list = value === "" || value.startsWith("[") ? listItems(lines, needsAt, value) : {
|
|
1631
|
+
items: [value],
|
|
1632
|
+
end: needsAt + 1
|
|
1633
|
+
};
|
|
1634
|
+
if (list === void 0) return { reason: `the needs of the job ${id} is not a list` };
|
|
1635
|
+
needsOf.set(id, list.items);
|
|
1636
|
+
if (value === "") {
|
|
1637
|
+
const item = lines.findIndex((line, i) => i > needsAt && line.trim() !== "");
|
|
1638
|
+
splices.push({
|
|
1639
|
+
at: item,
|
|
1640
|
+
remove: 0,
|
|
1641
|
+
insert: [`${" ".repeat(indentOf$1(lines[item] ?? ""))}- changes`]
|
|
1642
|
+
});
|
|
1643
|
+
} else splices.push({
|
|
1644
|
+
at: needsAt,
|
|
1645
|
+
remove: 1,
|
|
1646
|
+
insert: [`${pad}needs: [${["changes", ...list.items].join(", ")}]`]
|
|
1647
|
+
});
|
|
1648
|
+
}
|
|
1649
|
+
if (ifAt === void 0) splices.push({
|
|
1650
|
+
at: at + 1,
|
|
1651
|
+
remove: 0,
|
|
1652
|
+
insert: [`${pad}if: needs.changes.outputs.match == 'true'`]
|
|
1653
|
+
});
|
|
1654
|
+
else {
|
|
1655
|
+
let old = keyValue(lines[ifAt] ?? "", "if") ?? "";
|
|
1656
|
+
if (/^[>|]/.test(old)) return { reason: `the if of the job ${id} has more than one line` };
|
|
1657
|
+
const whole = /^\$\{\{(.*)\}\}$/.exec(old);
|
|
1658
|
+
if (whole !== null) old = (whole[1] ?? "").trim();
|
|
1659
|
+
if (old.includes("${{")) return { reason: `the if of the job ${id} has a part in \${{ }}` };
|
|
1660
|
+
own.add(id);
|
|
1661
|
+
splices.push({
|
|
1662
|
+
at: ifAt,
|
|
1663
|
+
remove: 1,
|
|
1664
|
+
insert: [`${pad}if: ${ifValue(`needs.changes.outputs.match == 'true' && (${old})`)}`]
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
const skippable = new Set(own);
|
|
1669
|
+
for (let grew = true; grew;) {
|
|
1670
|
+
grew = false;
|
|
1671
|
+
for (const [id, needs] of needsOf) {
|
|
1672
|
+
if (skippable.has(id) || !needs.some((need) => skippable.has(need))) continue;
|
|
1673
|
+
skippable.add(id);
|
|
1674
|
+
grew = true;
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
const action = (step) => `mark1russell7/template/.github/actions/${step}@${commit} # main`;
|
|
1678
|
+
const block = (indent, key, items) => [`${indent}${key}: |`, ...items.map((item) => `${indent}${unit}${item}`)];
|
|
1679
|
+
const job = jobIndent + unit;
|
|
1680
|
+
const step = job + unit;
|
|
1681
|
+
const grouped = top("concurrency") >= 0;
|
|
1682
|
+
const group = (id) => grouped ? [] : [
|
|
1683
|
+
`${job}concurrency:`,
|
|
1684
|
+
`${job}${unit}group: \${{ github.workflow }}-${id}-\${{ github.ref }}`,
|
|
1685
|
+
`${job}${unit}cancel-in-progress: true`
|
|
1686
|
+
];
|
|
1687
|
+
const changes = [
|
|
1688
|
+
`${jobIndent}changes:`,
|
|
1689
|
+
`${job}runs-on: ubuntu-latest`,
|
|
1690
|
+
`${job}timeout-minutes: 5`,
|
|
1691
|
+
...group("changes"),
|
|
1692
|
+
`${job}permissions:`,
|
|
1693
|
+
`${job}${unit}contents: read`,
|
|
1694
|
+
`${job}${unit}pull-requests: read`,
|
|
1695
|
+
`${job}outputs:`,
|
|
1696
|
+
`${job}${unit}match: \${{ steps.changes.outputs.match }}`,
|
|
1697
|
+
`${job}steps:`,
|
|
1698
|
+
`${step}- id: changes`,
|
|
1699
|
+
`${step} uses: ${action("changes")}`,
|
|
1700
|
+
`${step} with:`,
|
|
1701
|
+
...block(`${step} ${unit}`, "paths", filters["paths"] ?? ["**"]),
|
|
1702
|
+
...filters["paths-ignore"] === void 0 ? [] : block(`${step} ${unit}`, "paths-ignore", filters["paths-ignore"]),
|
|
1703
|
+
""
|
|
1704
|
+
];
|
|
1705
|
+
const allow = ids.filter((id) => skippable.has(id));
|
|
1706
|
+
const summary = [
|
|
1707
|
+
"",
|
|
1708
|
+
`${jobIndent}${summaryId}:`,
|
|
1709
|
+
`${job}name: ${name}`,
|
|
1710
|
+
`${job}if: always()`,
|
|
1711
|
+
`${job}needs: [${["changes", ...ids].join(", ")}]`,
|
|
1712
|
+
`${job}runs-on: ubuntu-latest`,
|
|
1713
|
+
`${job}timeout-minutes: 2`,
|
|
1714
|
+
...group(summaryId),
|
|
1715
|
+
`${job}permissions: {}`,
|
|
1716
|
+
`${job}steps:`,
|
|
1717
|
+
`${step}- uses: ${action("gate-summary")}`,
|
|
1718
|
+
`${step} with:`,
|
|
1719
|
+
`${step} ${unit}needs: \${{ toJSON(needs) }}`,
|
|
1720
|
+
...allow.length === 0 ? [] : [`${step} ${unit}allow-skip: ${allow.join(" ")}`]
|
|
1721
|
+
];
|
|
1722
|
+
let last = blockEnd(lines, jobsAt);
|
|
1723
|
+
while (last > jobsAt + 1 && (lines[last - 1] ?? "").trim() === "") last -= 1;
|
|
1724
|
+
splices.push({
|
|
1725
|
+
at: first,
|
|
1726
|
+
remove: 0,
|
|
1727
|
+
insert: changes
|
|
1728
|
+
}, {
|
|
1729
|
+
at: last,
|
|
1730
|
+
remove: 0,
|
|
1731
|
+
insert: summary
|
|
1732
|
+
});
|
|
1733
|
+
const out = [...original];
|
|
1734
|
+
for (const item of splices.map((value, order) => ({
|
|
1735
|
+
...value,
|
|
1736
|
+
order
|
|
1737
|
+
})).sort((a, b) => b.at - a.at || b.remove - a.remove || b.order - a.order)) out.splice(item.at, item.remove, ...item.insert);
|
|
1738
|
+
return { text: out.join(eol) };
|
|
1739
|
+
}
|
|
1740
|
+
const gateTrigger = {
|
|
1741
|
+
id: "gate-trigger",
|
|
1742
|
+
title: "A workflow that runs on pull requests starts on each pull request: it has no on.pull_request.paths or paths-ignore.",
|
|
1743
|
+
reason: "The ruleset requires the summary check \"<Name> OK\" of each gate. A workflow with a path filter does not start on a pull request that changes no file of the filter, so its check is not there, and the ruleset cannot require it. Then a pull request can merge before such a gate ends. On 2026-11-02, 19 such workflows in 11 repositories fed no required check.",
|
|
1744
|
+
fix: "Remove the paths from on.pull_request. Add a job \"changes\" with the action mark1russell7/template/.github/actions/changes and the same paths, and \"if: needs.changes.outputs.match == 'true'\" on each gate job. Add a job \"<Name> OK\" with \"if: always()\", \"needs\" with each job, and the action gate-summary (CI.md, \"A gate with paths\"). Then start ruleset-ci-ok.ts again. A workflow that is not a gate can go in the option allow.",
|
|
1745
|
+
sources: [{
|
|
1746
|
+
repo: "fleet",
|
|
1747
|
+
rule: "gate-trigger",
|
|
1748
|
+
doc: "docs/STRATEGY.md (2026-11-02, a gate with paths feeds a required summary)"
|
|
1749
|
+
}],
|
|
1750
|
+
options: { allow: {
|
|
1751
|
+
type: "strings",
|
|
1752
|
+
default: [],
|
|
1753
|
+
description: "The file names of the workflows that can filter pull requests by path, because they are not a gate (for example a preview)."
|
|
1754
|
+
} },
|
|
1755
|
+
check(context, options) {
|
|
1756
|
+
const files = context.gitFiles();
|
|
1757
|
+
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
1758
|
+
const workflows = files.filter((path) => WORKFLOW$1.test(path)).sort(byCode);
|
|
1759
|
+
if (workflows.length === 0) return { skipped: "the repository has no workflow" };
|
|
1760
|
+
const allow = Array.isArray(options["allow"]) ? options["allow"] : [];
|
|
1761
|
+
const breaks = [];
|
|
1762
|
+
for (const file of workflows) {
|
|
1763
|
+
if (allow.includes(file.slice(file.lastIndexOf("/") + 1))) continue;
|
|
1764
|
+
let text;
|
|
1765
|
+
try {
|
|
1766
|
+
text = readFileSync(join(context.root, file), "utf8");
|
|
1767
|
+
} catch {
|
|
1768
|
+
continue;
|
|
1769
|
+
}
|
|
1770
|
+
const filters = prPathFilters(text);
|
|
1771
|
+
const first = filters[0];
|
|
1772
|
+
if (first === void 0) continue;
|
|
1773
|
+
const keys = filters.map((filter) => `on.${filter.trigger}.${filter.key}`).join(" and ");
|
|
1774
|
+
const converted = convertGate(text, file);
|
|
1775
|
+
breaks.push({
|
|
1776
|
+
file,
|
|
1777
|
+
line: first.line,
|
|
1778
|
+
message: `${file}: ${keys}, so the workflow does not start on each pull request, and the ruleset cannot ask for its summary check.`,
|
|
1779
|
+
..."text" in converted ? { edits: [{
|
|
1780
|
+
file,
|
|
1781
|
+
before: text,
|
|
1782
|
+
after: converted.text
|
|
1783
|
+
}] } : { fix: `A person must convert it, because ${converted.reason}. ${gateTrigger.fix}` }
|
|
1784
|
+
});
|
|
1785
|
+
}
|
|
1786
|
+
return breaks;
|
|
1787
|
+
}
|
|
1788
|
+
};
|
|
1789
|
+
// src/change.ts
|
|
1790
|
+
/**
|
|
1791
|
+
* The change that a check examines: the option `--base`, the merge commit of a pull request, or a push to the default
|
|
1792
|
+
* branch. The rule release-files reads its changed files, and the runner reads the files that it adds.
|
|
1793
|
+
*/
|
|
1794
|
+
/** This function gives the range of the commits of a push to the default branch, from the event file of GitHub Actions. */
|
|
1795
|
+
function pushRange(context) {
|
|
1796
|
+
const file = context.env["GITHUB_EVENT_PATH"];
|
|
1797
|
+
let event;
|
|
1798
|
+
try {
|
|
1799
|
+
event = file === void 0 || file === "" || !existsSync(file) ? void 0 : JSON.parse(readFileSync(file, "utf8"));
|
|
1800
|
+
} catch {
|
|
1801
|
+
event = void 0;
|
|
1802
|
+
}
|
|
1803
|
+
if (event === void 0) return { skipped: "the push has no event file (GITHUB_EVENT_PATH)" };
|
|
1804
|
+
const branch = event.repository?.default_branch;
|
|
1805
|
+
if (typeof branch !== "string" || event.ref !== `refs/heads/${branch}`) return { skipped: "the push is not to the default branch: the pull request of the branch has the change" };
|
|
1806
|
+
const before = typeof event.before === "string" ? event.before : "";
|
|
1807
|
+
if (!/^[0-9a-f]{40,64}$/.test(before) || /^0+$/.test(before)) return { skipped: "the push has no commit before it" };
|
|
1808
|
+
if (context.git([
|
|
1809
|
+
"rev-parse",
|
|
1810
|
+
"--verify",
|
|
1811
|
+
"--quiet",
|
|
1812
|
+
`${before}^{commit}`
|
|
1813
|
+
]) === void 0) return { skipped: `the checkout does not have ${before}, the commit before the push: fetch it, or set fetch-depth to 0` };
|
|
1814
|
+
return {
|
|
1815
|
+
diff: [before, "HEAD"],
|
|
1816
|
+
log: [`${before}..HEAD`],
|
|
1817
|
+
ends: [before, "HEAD"]
|
|
1818
|
+
};
|
|
1819
|
+
}
|
|
1820
|
+
/**
|
|
1821
|
+
* This function gives the range of the change: the option `--base`, or the merge commit of a pull request. With the
|
|
1822
|
+
* option `push`, a push to the default branch gives the commits of the push: from the commit before the push to HEAD.
|
|
1823
|
+
*/
|
|
1824
|
+
function rangeOf(context, options = {}) {
|
|
1825
|
+
if (context.base !== void 0) {
|
|
1826
|
+
if (context.git([
|
|
1827
|
+
"rev-parse",
|
|
1828
|
+
"--verify",
|
|
1829
|
+
"--quiet",
|
|
1830
|
+
`${context.base}^{commit}`
|
|
1831
|
+
]) === void 0) return { skipped: `git does not know the base ${context.base}` };
|
|
1832
|
+
return {
|
|
1833
|
+
diff: [`${context.base}...HEAD`],
|
|
1834
|
+
log: [`${context.base}..HEAD`],
|
|
1835
|
+
ends: [context.base, "HEAD"]
|
|
1836
|
+
};
|
|
1837
|
+
}
|
|
1838
|
+
const event = context.env["GITHUB_EVENT_NAME"];
|
|
1839
|
+
if (event === "push" && options.push === true) return pushRange(context);
|
|
1840
|
+
if (event !== "pull_request" && event !== "pull_request_target") return { skipped: "no base: the rule runs on a pull request, or with --base <ref>" };
|
|
1841
|
+
if ((context.git([
|
|
1842
|
+
"rev-list",
|
|
1843
|
+
"--parents",
|
|
1844
|
+
"-n",
|
|
1845
|
+
"1",
|
|
1846
|
+
"HEAD"
|
|
1847
|
+
])?.trim().split(/\s+/) ?? []).length !== 3) return { skipped: "HEAD is not the merge commit of the pull request" };
|
|
1848
|
+
if (context.git([
|
|
1849
|
+
"cat-file",
|
|
1850
|
+
"-e",
|
|
1851
|
+
"HEAD^1^{commit}"
|
|
1852
|
+
]) === void 0) return { skipped: "the checkout has no parent of HEAD: set fetch-depth to 2 or more" };
|
|
1853
|
+
return {
|
|
1854
|
+
diff: ["HEAD^1", "HEAD"],
|
|
1855
|
+
log: ["HEAD^1..HEAD"],
|
|
1856
|
+
ends: ["HEAD^1", "HEAD^2"]
|
|
1857
|
+
};
|
|
1858
|
+
}
|
|
1859
|
+
/**
|
|
1860
|
+
* This function gives the files that the change adds, relative to the root, with `/`. A renamed file is not added.
|
|
1861
|
+
* With no change (no base and no pull request), it gives undefined.
|
|
1862
|
+
*/
|
|
1863
|
+
function addedFiles(context) {
|
|
1864
|
+
const range = rangeOf(context);
|
|
1865
|
+
if ("skipped" in range) return void 0;
|
|
1866
|
+
const out = context.git([
|
|
1867
|
+
"diff",
|
|
1868
|
+
"--name-only",
|
|
1869
|
+
"--find-renames",
|
|
1870
|
+
"--diff-filter=A",
|
|
1871
|
+
...range.diff
|
|
1872
|
+
]);
|
|
1873
|
+
if (out === void 0) return void 0;
|
|
1874
|
+
return new Set(out.split(/\r?\n/).filter((file) => file !== ""));
|
|
1875
|
+
}
|
|
1876
|
+
/**
|
|
1877
|
+
* This function gives the lines that the change adds, for each changed file: the numbers (from 1) of the new file.
|
|
1878
|
+
* A renamed file with no other change has no added lines. With no change (no base and no pull request), it gives undefined.
|
|
1879
|
+
*/
|
|
1880
|
+
function addedLines(context) {
|
|
1881
|
+
const range = rangeOf(context);
|
|
1882
|
+
if ("skipped" in range) return void 0;
|
|
1883
|
+
const out = context.git([
|
|
1884
|
+
"diff",
|
|
1885
|
+
"--unified=0",
|
|
1886
|
+
"--no-color",
|
|
1887
|
+
"--no-ext-diff",
|
|
1888
|
+
"--src-prefix=a/",
|
|
1889
|
+
"--dst-prefix=b/",
|
|
1890
|
+
"--find-renames",
|
|
1891
|
+
"--diff-filter=AMR",
|
|
1892
|
+
...range.diff
|
|
1893
|
+
]);
|
|
1894
|
+
if (out === void 0) return void 0;
|
|
1895
|
+
const lines = /* @__PURE__ */ new Map();
|
|
1896
|
+
let file;
|
|
1897
|
+
for (const line of out.split(/\r?\n/)) {
|
|
1898
|
+
if (line.startsWith("+++ ")) {
|
|
1899
|
+
file = line === "+++ /dev/null" ? void 0 : line.slice(6);
|
|
1900
|
+
continue;
|
|
1901
|
+
}
|
|
1902
|
+
const hunk = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/.exec(line);
|
|
1903
|
+
if (hunk === null || file === void 0) continue;
|
|
1904
|
+
const start = Number(hunk[1]);
|
|
1905
|
+
const count = hunk[2] === void 0 ? 1 : Number(hunk[2]);
|
|
1906
|
+
let set = lines.get(file);
|
|
1907
|
+
if (set === void 0) lines.set(file, set = /* @__PURE__ */ new Set());
|
|
1908
|
+
for (let index = 0; index < count; index++) set.add(start + index);
|
|
1909
|
+
}
|
|
1910
|
+
return lines;
|
|
1911
|
+
}
|
|
1912
|
+
// src/home-exports.ts
|
|
1913
|
+
/** The names of the values that each home package exports, with the version that the names come from. */
|
|
1914
|
+
const HOME_EXPORTS = {
|
|
1915
|
+
"@mark1russell7/algebra": {
|
|
1916
|
+
version: "0.8.0",
|
|
1917
|
+
names: [
|
|
1918
|
+
"FIRED",
|
|
1919
|
+
"ReplayOptions",
|
|
1920
|
+
"Replayable",
|
|
1921
|
+
"Transition",
|
|
1922
|
+
"algebraProblems",
|
|
1923
|
+
"arr",
|
|
1924
|
+
"detection",
|
|
1925
|
+
"errnoOf",
|
|
1926
|
+
"evaluate",
|
|
1927
|
+
"exprKnobs",
|
|
1928
|
+
"fromStates",
|
|
1929
|
+
"machineProblems",
|
|
1930
|
+
"machineSchema",
|
|
1931
|
+
"modelSource",
|
|
1932
|
+
"overValues",
|
|
1933
|
+
"parseExpr",
|
|
1934
|
+
"readsFired",
|
|
1935
|
+
"realizationKnobs",
|
|
1936
|
+
"realizationOf",
|
|
1937
|
+
"recovery",
|
|
1938
|
+
"replay",
|
|
1939
|
+
"stackedDetection",
|
|
1940
|
+
"timerOf",
|
|
1941
|
+
"timerUnder",
|
|
1942
|
+
"transitionOn"
|
|
1943
|
+
]
|
|
1944
|
+
},
|
|
1945
|
+
"@mark1russell7/api-report": {
|
|
1946
|
+
version: "0.2.1",
|
|
1947
|
+
names: [
|
|
1948
|
+
"DEFAULT_TOOL",
|
|
1949
|
+
"HEADER_LINES",
|
|
1950
|
+
"PUBLISH_CONFIG_FIELDS",
|
|
1951
|
+
"REPORT_FILE",
|
|
1952
|
+
"USAGE",
|
|
1953
|
+
"apiReport",
|
|
1954
|
+
"binsOf",
|
|
1955
|
+
"byCode",
|
|
1956
|
+
"declarationPathOf",
|
|
1957
|
+
"diffLines",
|
|
1958
|
+
"entriesOf",
|
|
1959
|
+
"formatResult",
|
|
1960
|
+
"globFolders",
|
|
1961
|
+
"globToRegExp",
|
|
1962
|
+
"packageFolders",
|
|
1963
|
+
"packageReport",
|
|
1964
|
+
"parseDeclarations",
|
|
1965
|
+
"patternMatch",
|
|
1966
|
+
"publishedManifest",
|
|
1967
|
+
"readConfig",
|
|
1968
|
+
"runCli",
|
|
1969
|
+
"runReports",
|
|
1970
|
+
"statementsOf",
|
|
1971
|
+
"summaryMarkdown",
|
|
1972
|
+
"targetOf",
|
|
1973
|
+
"unifiedDiff",
|
|
1974
|
+
"workspaceGlobs"
|
|
1975
|
+
]
|
|
1976
|
+
},
|
|
1977
|
+
"@mark1russell7/boundaries": {
|
|
1978
|
+
version: "0.2.0",
|
|
1979
|
+
names: [
|
|
1980
|
+
"BoundaryOptions",
|
|
1981
|
+
"Config",
|
|
1982
|
+
"DefaultOptionsInput",
|
|
1983
|
+
"Rule",
|
|
1984
|
+
"RuleOptions",
|
|
1985
|
+
"ScopeOptions",
|
|
1986
|
+
"WorkspacePackage",
|
|
1987
|
+
"boundaries",
|
|
1988
|
+
"boundaryRules",
|
|
1989
|
+
"declaredDependencies",
|
|
1990
|
+
"defaultOptions",
|
|
1059
1991
|
"doNotFollowPaths",
|
|
1060
1992
|
"entryPattern",
|
|
1061
1993
|
"packageEntries",
|
|
@@ -6811,1257 +7743,683 @@ function fixImports(text, needs) {
|
|
|
6811
7743
|
const isImport = (line) => /^\s*import\b/.test(line);
|
|
6812
7744
|
for (const [name, module] of needs) {
|
|
6813
7745
|
if (lines.some((line) => isImport(line) && new RegExp(`\\b${name}\\b`).test(line))) continue;
|
|
6814
|
-
const found = namedImport(lines, module) ?? namedImport(lines, module.replace(/^node:/, ""));
|
|
6815
|
-
if (found) {
|
|
6816
|
-
lines = lines.map((line, index) => index === found[0] ? importLine(found[1], [...found[2], name], found[3]) : line);
|
|
6817
|
-
continue;
|
|
6818
|
-
}
|
|
6819
|
-
let last = -1;
|
|
6820
|
-
lines.forEach((line, index) => {
|
|
6821
|
-
if (isImport(line) && /from\s*["'][^"']+["'];?\s*$/.test(line)) last = index;
|
|
6822
|
-
});
|
|
6823
|
-
const at = last >= 0 ? last + 1 : lines[0]?.startsWith("#!") ? 1 : 0;
|
|
6824
|
-
const style = lines.find((line) => isImport(line) && /from\s*["']/.test(line)) ?? "";
|
|
6825
|
-
const quote = /from\s*'/.test(style) ? "'" : "\"";
|
|
6826
|
-
const semi = style === "" || /;\s*$/.test(style) ? ";" : "";
|
|
6827
|
-
lines = [
|
|
6828
|
-
...lines.slice(0, at),
|
|
6829
|
-
`import { ${name} } from ${quote}${module}${quote}${semi}`,
|
|
6830
|
-
...lines.slice(at)
|
|
6831
|
-
];
|
|
6832
|
-
}
|
|
6833
|
-
for (const name of PATH_NAMES) {
|
|
6834
|
-
if (lines.some((line) => !isImport(line) && new RegExp(`\\b${name}\\b`).test(line))) continue;
|
|
6835
|
-
for (const module of [
|
|
6836
|
-
"node:url",
|
|
6837
|
-
"node:path",
|
|
6838
|
-
"node:fs",
|
|
6839
|
-
"url",
|
|
6840
|
-
"path",
|
|
6841
|
-
"fs"
|
|
6842
|
-
]) {
|
|
6843
|
-
const found = namedImport(lines, module);
|
|
6844
|
-
if (!found || !found[2].some((part) => imported(part) === name)) continue;
|
|
6845
|
-
const kept = found[2].filter((part) => imported(part) !== name);
|
|
6846
|
-
lines = kept.length === 0 ? lines.filter((_, index) => index !== found[0]) : lines.map((line, index) => index === found[0] ? importLine(found[1], kept, found[3]) : line);
|
|
6847
|
-
}
|
|
6848
|
-
}
|
|
6849
|
-
return lines.join(eol);
|
|
6850
|
-
}
|
|
6851
|
-
const mainCheck = {
|
|
6852
|
-
id: "main-check",
|
|
6853
|
-
title: "A script finds out that it is the main module with `import.meta.main`, or with a real path of each side, not by a compare of `process.argv[1]` with its path.",
|
|
6854
|
-
reason: "Through a link, `process.argv[1]` has the path of the link, and the module has the real path. The compare is false, so the script does nothing and ends with exit code 0: a check that looks done but did not start.",
|
|
6855
|
-
fix: "Write `if (import.meta.main)` when `engines.node` allows only versions that have it (`^22.18`, `>=24.2`). Else compare `realpathSync(process.argv[1])` with `realpathSync(fileURLToPath(import.meta.url))`. `conventions fix` writes the one that fits.",
|
|
6856
|
-
sources: [{
|
|
6857
|
-
repo: "fleet",
|
|
6858
|
-
rule: "main-check",
|
|
6859
|
-
doc: "docs/STRATEGY.md (2026-11-02, the main check through a link)"
|
|
6860
|
-
}],
|
|
6861
|
-
options: {},
|
|
6862
|
-
check(context) {
|
|
6863
|
-
const files = context.gitFiles();
|
|
6864
|
-
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
6865
|
-
const packages = [...codePackages(context), context.rootPackage].sort((a, b) => b.folder.length - a.folder.length);
|
|
6866
|
-
const breaks = [];
|
|
6867
|
-
for (const file of files) {
|
|
6868
|
-
if (!SCRIPT.has(extname(file).toLowerCase()) || /(^|\/)(node_modules|dist)\//.test(file)) continue;
|
|
6869
|
-
const path = join(context.root, file);
|
|
6870
|
-
let text;
|
|
6871
|
-
try {
|
|
6872
|
-
if (statSync(path).size > MAX_BYTES$1) continue;
|
|
6873
|
-
text = readFileSync(path, "utf8");
|
|
6874
|
-
} catch {
|
|
6875
|
-
continue;
|
|
6876
|
-
}
|
|
6877
|
-
if (!text.includes("process.argv[1]")) continue;
|
|
6878
|
-
const engines = (packages.find((p) => p.folder === "" || file.startsWith(`${p.folder}/`))?.manifest)?.engines?.node;
|
|
6879
|
-
const main = hasImportMetaMain(engines);
|
|
6880
|
-
const lines = text.split(/\r?\n/);
|
|
6881
|
-
for (let index = 0; index < lines.length; index++) {
|
|
6882
|
-
const line = lines[index] ?? "";
|
|
6883
|
-
const next = lines[index + 1] ?? "";
|
|
6884
|
-
if (!(isPathCompare(line) || line.includes("process.argv[1]") && !/import\.meta/.test(line) && !isPathCompare(next) && isPathCompare(`${line} ${next}`))) continue;
|
|
6885
|
-
const fixed = fixLine(line, main ? "import.meta.main" : REAL_COMPARE);
|
|
6886
|
-
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
6887
|
-
const after = fixed === void 0 ? void 0 : fixImports([
|
|
6888
|
-
...lines.slice(0, index),
|
|
6889
|
-
fixed,
|
|
6890
|
-
...lines.slice(index + 1)
|
|
6891
|
-
].join(eol), main ? [] : REAL_IMPORTS);
|
|
6892
|
-
breaks.push({
|
|
6893
|
-
file,
|
|
6894
|
-
line: index + 1,
|
|
6895
|
-
message: "The script compares process.argv[1] with its own path, which is false through a link.",
|
|
6896
|
-
...after === void 0 ? { fix: "Change the condition by hand: it has more than the main check, or it is on more than one line." } : { edits: [{
|
|
6897
|
-
file,
|
|
6898
|
-
before: text,
|
|
6899
|
-
after
|
|
6900
|
-
}] }
|
|
6901
|
-
});
|
|
6902
|
-
}
|
|
6903
|
-
}
|
|
6904
|
-
return breaks;
|
|
6905
|
-
}
|
|
6906
|
-
};
|
|
6907
|
-
// src/rules/no-build-output.ts
|
|
6908
|
-
/**
|
|
6909
|
-
* The rule `no-build-output`: git does not keep build output.
|
|
6910
|
-
*/
|
|
6911
|
-
const noBuildOutput = {
|
|
6912
|
-
id: "no-build-output",
|
|
6913
|
-
title: "Git keeps no build output: no tracked file is in a folder named `dist` or `build`.",
|
|
6914
|
-
reason: "The release workflow builds each package from the source. Build output in git goes stale, makes noise in each diff, and a user can get old code from a git install.",
|
|
6915
|
-
fix: "Remove the folder from git with `git rm -r --cached <folder>`, and keep its name in `.gitignore`.",
|
|
6916
|
-
sources: [
|
|
6917
|
-
{
|
|
6918
|
-
repo: "client",
|
|
6919
|
-
rule: "no-build-output",
|
|
6920
|
-
doc: "CLAUDE.md:48"
|
|
6921
|
-
},
|
|
6922
|
-
{
|
|
6923
|
-
repo: "client",
|
|
6924
|
-
rule: "no-dist",
|
|
6925
|
-
doc: "CLAUDE.md:48"
|
|
6926
|
-
},
|
|
6927
|
-
{
|
|
6928
|
-
repo: "client",
|
|
6929
|
-
rule: "no-dist-commit",
|
|
6930
|
-
doc: "CLAUDE.md:48"
|
|
6931
|
-
}
|
|
6932
|
-
],
|
|
6933
|
-
options: { folders: {
|
|
6934
|
-
type: "strings",
|
|
6935
|
-
default: ["dist", "build"],
|
|
6936
|
-
description: "The names of the folders of build output."
|
|
6937
|
-
} },
|
|
6938
|
-
check(context, options) {
|
|
6939
|
-
const files = context.gitFiles();
|
|
6940
|
-
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
6941
|
-
const names = new Set(Array.isArray(options["folders"]) ? options["folders"] : ["dist", "build"]);
|
|
6942
|
-
const counts = /* @__PURE__ */ new Map();
|
|
6943
|
-
for (const file of files) {
|
|
6944
|
-
const segments = file.split("/");
|
|
6945
|
-
const index = segments.slice(0, -1).findIndex((segment) => names.has(segment));
|
|
6946
|
-
if (index < 0) continue;
|
|
6947
|
-
const folder = segments.slice(0, index + 1).join("/");
|
|
6948
|
-
counts.set(folder, (counts.get(folder) ?? 0) + 1);
|
|
6949
|
-
}
|
|
6950
|
-
return [...counts.keys()].sort(byCode).map((folder) => ({
|
|
6951
|
-
file: `${folder}/`,
|
|
6952
|
-
message: `Git keeps ${counts.get(folder) ?? 0} file(s) in ${folder}/.`,
|
|
6953
|
-
fix: `Start \`git rm -r --cached ${folder}\`, and keep ${folder.split("/").pop() ?? folder}/ in .gitignore.`
|
|
6954
|
-
}));
|
|
6955
|
-
}
|
|
6956
|
-
};
|
|
6957
|
-
// src/rules/no-local-paths.ts
|
|
6958
|
-
/**
|
|
6959
|
-
* The rule `no-local-paths`: no tracked file names the home folder of a user of a computer.
|
|
6960
|
-
*/
|
|
6961
|
-
/** The extensions of files that are not text. The rule does not read them. */
|
|
6962
|
-
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(" "));
|
|
6963
|
-
/** The largest file that the rule reads, in bytes. */
|
|
6964
|
-
const MAX_BYTES = 2097152;
|
|
6965
|
-
/** The names in a home path that do not identify a person: CI users, container users and placeholders. */
|
|
6966
|
-
const DEFAULT_ALLOWED = [
|
|
6967
|
-
"runner",
|
|
6968
|
-
"runneradmin",
|
|
6969
|
-
"user",
|
|
6970
|
-
"username",
|
|
6971
|
-
"you",
|
|
6972
|
-
"me",
|
|
6973
|
-
"name",
|
|
6974
|
-
"yourname",
|
|
6975
|
-
"your-name",
|
|
6976
|
-
"example",
|
|
6977
|
-
"node",
|
|
6978
|
-
"ubuntu",
|
|
6979
|
-
"vscode",
|
|
6980
|
-
"codespace",
|
|
6981
|
-
"public",
|
|
6982
|
-
"default",
|
|
6983
|
-
"shared",
|
|
6984
|
-
"all users"
|
|
6985
|
-
];
|
|
6986
|
-
/** The forms of a home folder: Windows, macOS and Linux. The group `user` is the name of the user. */
|
|
6987
|
-
const HOME_PATTERNS = [
|
|
6988
|
-
/\b[A-Za-z]:(?:\\{1,2}|\/)[Uu][Ss][Ee][Rr][Ss](?:\\{1,2}|\/)(?<user>[^\\/\s"'`<>|:*?%$(){}[\],;]+)/g,
|
|
6989
|
-
/(?<![\w.~-])\/Users\/(?<user>[^/\s"'`<>|:*?%$(){}[\],;]+)/g,
|
|
6990
|
-
/(?<![\w.~-])\/home\/(?<user>[^/\s"'`<>|:*?%$(){}[\],;]+)/g
|
|
6991
|
-
];
|
|
6992
|
-
const noLocalPaths = {
|
|
6993
|
-
id: "no-local-paths",
|
|
6994
|
-
title: "No tracked file has the home folder of a user (`C:\\Users\\<name>`, `/Users/<name>`, `/home/<name>`).",
|
|
6995
|
-
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.",
|
|
6996
|
-
fix: "Use a path relative to the repository, `~`, an environment variable, or a placeholder such as `<you>`.",
|
|
6997
|
-
sources: [
|
|
6998
|
-
{
|
|
6999
|
-
repo: "client",
|
|
7000
|
-
rule: "I12",
|
|
7001
|
-
doc: "packages/documentation/ARCHITECTURE.md:201"
|
|
7002
|
-
},
|
|
7003
|
-
{
|
|
7004
|
-
repo: "systems",
|
|
7005
|
-
rule: "no-identifying-names",
|
|
7006
|
-
doc: "CLAUDE.md:12"
|
|
7007
|
-
},
|
|
7008
|
-
{
|
|
7009
|
-
repo: "systems",
|
|
7010
|
-
rule: "no-private-identifiers",
|
|
7011
|
-
doc: "CLAUDE.md:12"
|
|
7012
|
-
},
|
|
7013
|
-
{
|
|
7014
|
-
repo: "systems",
|
|
7015
|
-
rule: "no-private-names",
|
|
7016
|
-
doc: "CLAUDE.md:12"
|
|
7017
|
-
},
|
|
7018
|
-
{
|
|
7019
|
-
repo: "coeval",
|
|
7020
|
-
rule: "no-private-names",
|
|
7021
|
-
doc: "CLAUDE.md:22"
|
|
7022
|
-
}
|
|
7023
|
-
],
|
|
7024
|
-
options: {
|
|
7025
|
-
allow: {
|
|
7026
|
-
type: "strings",
|
|
7027
|
-
default: [],
|
|
7028
|
-
description: "More user names that do not identify a person."
|
|
7029
|
-
},
|
|
7030
|
-
patterns: {
|
|
7031
|
-
type: "strings",
|
|
7032
|
-
default: [],
|
|
7033
|
-
description: "More regular expressions of text that no file has. The environment variable CONVENTIONS_PRIVATE_PATTERNS adds one on each line, so a private name stays out of package.json."
|
|
7746
|
+
const found = namedImport(lines, module) ?? namedImport(lines, module.replace(/^node:/, ""));
|
|
7747
|
+
if (found) {
|
|
7748
|
+
lines = lines.map((line, index) => index === found[0] ? importLine(found[1], [...found[2], name], found[3]) : line);
|
|
7749
|
+
continue;
|
|
7034
7750
|
}
|
|
7035
|
-
|
|
7036
|
-
|
|
7751
|
+
let last = -1;
|
|
7752
|
+
lines.forEach((line, index) => {
|
|
7753
|
+
if (isImport(line) && /from\s*["'][^"']+["'];?\s*$/.test(line)) last = index;
|
|
7754
|
+
});
|
|
7755
|
+
const at = last >= 0 ? last + 1 : lines[0]?.startsWith("#!") ? 1 : 0;
|
|
7756
|
+
const style = lines.find((line) => isImport(line) && /from\s*["']/.test(line)) ?? "";
|
|
7757
|
+
const quote = /from\s*'/.test(style) ? "'" : "\"";
|
|
7758
|
+
const semi = style === "" || /;\s*$/.test(style) ? ";" : "";
|
|
7759
|
+
lines = [
|
|
7760
|
+
...lines.slice(0, at),
|
|
7761
|
+
`import { ${name} } from ${quote}${module}${quote}${semi}`,
|
|
7762
|
+
...lines.slice(at)
|
|
7763
|
+
];
|
|
7764
|
+
}
|
|
7765
|
+
for (const name of PATH_NAMES) {
|
|
7766
|
+
if (lines.some((line) => !isImport(line) && new RegExp(`\\b${name}\\b`).test(line))) continue;
|
|
7767
|
+
for (const module of [
|
|
7768
|
+
"node:url",
|
|
7769
|
+
"node:path",
|
|
7770
|
+
"node:fs",
|
|
7771
|
+
"url",
|
|
7772
|
+
"path",
|
|
7773
|
+
"fs"
|
|
7774
|
+
]) {
|
|
7775
|
+
const found = namedImport(lines, module);
|
|
7776
|
+
if (!found || !found[2].some((part) => imported(part) === name)) continue;
|
|
7777
|
+
const kept = found[2].filter((part) => imported(part) !== name);
|
|
7778
|
+
lines = kept.length === 0 ? lines.filter((_, index) => index !== found[0]) : lines.map((line, index) => index === found[0] ? importLine(found[1], kept, found[3]) : line);
|
|
7779
|
+
}
|
|
7780
|
+
}
|
|
7781
|
+
return lines.join(eol);
|
|
7782
|
+
}
|
|
7783
|
+
const mainCheck = {
|
|
7784
|
+
id: "main-check",
|
|
7785
|
+
title: "A script finds out that it is the main module with `import.meta.main`, or with a real path of each side, not by a compare of `process.argv[1]` with its path.",
|
|
7786
|
+
reason: "Through a link, `process.argv[1]` has the path of the link, and the module has the real path. The compare is false, so the script does nothing and ends with exit code 0: a check that looks done but did not start.",
|
|
7787
|
+
fix: "Write `if (import.meta.main)` when `engines.node` allows only versions that have it (`^22.18`, `>=24.2`). Else compare `realpathSync(process.argv[1])` with `realpathSync(fileURLToPath(import.meta.url))`. `conventions fix` writes the one that fits.",
|
|
7788
|
+
sources: [{
|
|
7789
|
+
repo: "fleet",
|
|
7790
|
+
rule: "main-check",
|
|
7791
|
+
doc: "docs/STRATEGY.md (2026-11-02, the main check through a link)"
|
|
7792
|
+
}],
|
|
7793
|
+
options: {},
|
|
7794
|
+
check(context) {
|
|
7037
7795
|
const files = context.gitFiles();
|
|
7038
7796
|
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
7039
|
-
const
|
|
7040
|
-
const fromEnv = (context.env["CONVENTIONS_PRIVATE_PATTERNS"] ?? "").split("\n").map((line) => line.trim()).filter((line) => line !== "");
|
|
7041
|
-
const extra = [...Array.isArray(options["patterns"]) ? options["patterns"] : [], ...fromEnv].map((source) => new RegExp(source, "g"));
|
|
7042
|
-
const rootFile = context.rootPackage.file;
|
|
7797
|
+
const packages = [...codePackages(context), context.rootPackage].sort((a, b) => b.folder.length - a.folder.length);
|
|
7043
7798
|
const breaks = [];
|
|
7044
7799
|
for (const file of files) {
|
|
7045
|
-
if (
|
|
7800
|
+
if (!SCRIPT.has(extname(file).toLowerCase()) || /(^|\/)(node_modules|dist)\//.test(file)) continue;
|
|
7046
7801
|
const path = join(context.root, file);
|
|
7047
7802
|
let text;
|
|
7048
7803
|
try {
|
|
7049
|
-
if (statSync(path).size > MAX_BYTES) continue;
|
|
7804
|
+
if (statSync(path).size > MAX_BYTES$1) continue;
|
|
7050
7805
|
text = readFileSync(path, "utf8");
|
|
7051
7806
|
} catch {
|
|
7052
7807
|
continue;
|
|
7053
7808
|
}
|
|
7054
|
-
if (text.includes("
|
|
7809
|
+
if (!text.includes("process.argv[1]")) continue;
|
|
7810
|
+
const engines = (packages.find((p) => p.folder === "" || file.startsWith(`${p.folder}/`))?.manifest)?.engines?.node;
|
|
7811
|
+
const main = hasImportMetaMain(engines);
|
|
7055
7812
|
const lines = text.split(/\r?\n/);
|
|
7056
7813
|
for (let index = 0; index < lines.length; index++) {
|
|
7057
7814
|
const line = lines[index] ?? "";
|
|
7058
|
-
const
|
|
7059
|
-
|
|
7060
|
-
|
|
7061
|
-
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
}
|
|
7068
|
-
for (const pattern of extra) {
|
|
7069
|
-
if (file === rootFile && line.trim().replace(/,$/, "") === JSON.stringify(pattern.source)) continue;
|
|
7070
|
-
for (const match of line.matchAll(pattern)) breaks.push({
|
|
7071
|
-
file,
|
|
7072
|
-
line: index + 1,
|
|
7073
|
-
message: `The text "${match[0]}" matches the pattern ${pattern.source}.`,
|
|
7074
|
-
fix: "Remove the text."
|
|
7075
|
-
});
|
|
7076
|
-
}
|
|
7077
|
-
}
|
|
7078
|
-
}
|
|
7079
|
-
return breaks;
|
|
7080
|
-
}
|
|
7081
|
-
};
|
|
7082
|
-
// src/rules/pages-site.ts
|
|
7083
|
-
/**
|
|
7084
|
-
* The rule `pages-site`: a public repository has a site. A workflow uses the Pages workflow of the template, and the
|
|
7085
|
-
* call deploys.
|
|
7086
|
-
*/
|
|
7087
|
-
/** The Pages workflow of the template, as a call from another repository and as a call from the template itself. */
|
|
7088
|
-
const PAGES_WORKFLOWS = ["mark1russell7/template/.github/workflows/reusable-pages.yml", "./.github/workflows/reusable-pages.yml"];
|
|
7089
|
-
/** This function gives each call of a workflow of `workflows` in the text of a workflow file. The ref after `@` can be any ref. */
|
|
7090
|
-
function pagesCalls(text, workflows = PAGES_WORKFLOWS) {
|
|
7091
|
-
const lines = workflowLines(text);
|
|
7092
|
-
const names = new Set(workflows.map((name) => name.toLowerCase()));
|
|
7093
|
-
const calls = [];
|
|
7094
|
-
lines.forEach((line, index) => {
|
|
7095
|
-
const uses = keyValue(line, "uses");
|
|
7096
|
-
if (uses === void 0 || !names.has((uses.split("@")[0] ?? "").toLowerCase())) return;
|
|
7097
|
-
let job = index - 1;
|
|
7098
|
-
while (job >= 0 && ((lines[job] ?? "").trim() === "" || indentOf$1(lines[job] ?? "") >= indentOf$1(line))) job -= 1;
|
|
7099
|
-
const body = job < 0 ? [line] : lines.slice(job, blockEnd(lines, job));
|
|
7100
|
-
calls.push({
|
|
7101
|
-
line: index + 1,
|
|
7102
|
-
deploys: !body.some((text) => keyValue(text, "deploy") === "false")
|
|
7103
|
-
});
|
|
7104
|
-
});
|
|
7105
|
-
return calls;
|
|
7106
|
-
}
|
|
7107
|
-
const pagesSite = {
|
|
7108
|
-
id: "pages-site",
|
|
7109
|
-
title: "A public repository has a workflow that calls the Pages workflow of the template (`reusable-pages.yml`, any ref), and the call deploys.",
|
|
7110
|
-
reason: "Each public project has a site with its Releases page and its Status page, so a reader sees the versions and the open work. On 2026-11-02 eight public repositories had no site: typeset, algebra, headroom, release-train, optional, ste-lint, lag-hud and template.",
|
|
7111
|
-
fix: "Add `.github/workflows/pages.yml` with a job `uses: mark1russell7/template/.github/workflows/reusable-pages.yml@<commit> # main` and the permissions of CI.md (\"Pages\"). Give `build`, `out` and `roadmap: docs/ROADMAP.md`. After the build, the job starts `site-pages build`, which adds the Releases page and the Status page. Then set the Pages source to \"GitHub Actions\": `gh api -X POST repos/<owner>/<repo>/pages -f build_type=workflow`.",
|
|
7112
|
-
sources: [
|
|
7113
|
-
"vex",
|
|
7114
|
-
"crawler",
|
|
7115
|
-
"client",
|
|
7116
|
-
"coeval"
|
|
7117
|
-
].map((repo) => ({
|
|
7118
|
-
repo,
|
|
7119
|
-
rule: "pages-site",
|
|
7120
|
-
doc: ".github/workflows/pages.yml (a call of reusable-pages.yml of the template)"
|
|
7121
|
-
})),
|
|
7122
|
-
options: { workflows: {
|
|
7123
|
-
type: "strings",
|
|
7124
|
-
default: PAGES_WORKFLOWS,
|
|
7125
|
-
description: "The workflows that deploy a site, without the ref after `@`."
|
|
7126
|
-
} },
|
|
7127
|
-
check(context, options) {
|
|
7128
|
-
const visible = repositoryIsPublic(context);
|
|
7129
|
-
if (visible === void 0) return { skipped: "outside a GitHub Actions run, the rule cannot tell if the repository is public" };
|
|
7130
|
-
if (!visible) return [];
|
|
7131
|
-
const files = context.gitFiles();
|
|
7132
|
-
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
7133
|
-
const calls = files.filter((path) => WORKFLOW$1.test(path)).sort(byCode).flatMap((file) => pagesCalls(readFileSync(join(context.root, file), "utf8"), options["workflows"]).map((call) => ({
|
|
7134
|
-
file,
|
|
7135
|
-
...call
|
|
7136
|
-
})));
|
|
7137
|
-
if (calls.some((call) => call.deploys)) return [];
|
|
7138
|
-
return [{
|
|
7139
|
-
file: ".github/workflows/pages.yml",
|
|
7140
|
-
message: `The repository is public, and no workflow deploys its site with the Pages workflow of the template.${calls.length === 0 ? "" : ` The calls in ${[...new Set(calls.map((call) => call.file))].join(", ")} have deploy: false.`}`
|
|
7141
|
-
}];
|
|
7142
|
-
}
|
|
7143
|
-
};
|
|
7144
|
-
// src/rules/pinned-git-deps.ts
|
|
7145
|
-
/**
|
|
7146
|
-
* The rule `pinned-git-deps`: a dependency from git names a full commit.
|
|
7147
|
-
*/
|
|
7148
|
-
/** The fields of the root `package.json` that replace the specifiers of dependencies. */
|
|
7149
|
-
const OVERRIDE_FIELDS = ["overrides", "resolutions"];
|
|
7150
|
-
/** This function tells if a specifier gets the package from git, not from a registry or the workspace. */
|
|
7151
|
-
function isGitSpecifier(spec) {
|
|
7152
|
-
const value = spec.trim();
|
|
7153
|
-
if (/^(github|gitlab|bitbucket|gist):/i.test(value)) return true;
|
|
7154
|
-
if (/^git(\+[a-z]+)?:/i.test(value) || /^git@/i.test(value)) return true;
|
|
7155
|
-
if (/^https?:\/\/(www\.)?(github\.com|gitlab\.com|bitbucket\.org|codeload\.github\.com)\//i.test(value)) return true;
|
|
7156
|
-
return /^[\w-][\w.-]*\/[\w.-]+(#.*)?$/.test(value) && !value.startsWith("@");
|
|
7157
|
-
}
|
|
7158
|
-
/**
|
|
7159
|
-
* This function tells if a git specifier names a commit. A specifier names a commit when its ref
|
|
7160
|
-
* (after `#`) is a commit SHA, or when a tarball URL has the SHA in its path.
|
|
7161
|
-
*/
|
|
7162
|
-
function isPinned(spec, fullSha) {
|
|
7163
|
-
const sha = fullSha ? /^[0-9a-f]{40}$/i : /^[0-9a-f]{7,40}$/i;
|
|
7164
|
-
const hash = spec.indexOf("#");
|
|
7165
|
-
if (hash >= 0) return spec.slice(hash + 1).split("&").some((part) => sha.test(part.replace(/^commit=/, "")));
|
|
7166
|
-
const path = /^https?:\/\/[^/]+\/(.*)$/i.exec(spec.trim())?.[1];
|
|
7167
|
-
return path !== void 0 && path.split(/[/.]/).some((part) => sha.test(part));
|
|
7168
|
-
}
|
|
7169
|
-
/** This function gives the specifiers of the fields of overrides, also the field `overrides` of `pnpm`. */
|
|
7170
|
-
function overridesOf(manifest) {
|
|
7171
|
-
const out = [];
|
|
7172
|
-
for (const field of OVERRIDE_FIELDS) for (const [name, spec] of specifiersOf(manifest, field)) out.push([
|
|
7173
|
-
field,
|
|
7174
|
-
name,
|
|
7175
|
-
spec
|
|
7176
|
-
]);
|
|
7177
|
-
const pnpm = manifest["pnpm"];
|
|
7178
|
-
if (typeof pnpm === "object" && pnpm !== null) for (const [name, spec] of specifiersOf(pnpm, "overrides")) out.push([
|
|
7179
|
-
"pnpm",
|
|
7180
|
-
name,
|
|
7181
|
-
spec
|
|
7182
|
-
]);
|
|
7183
|
-
return out;
|
|
7184
|
-
}
|
|
7185
|
-
const pinnedGitDeps = {
|
|
7186
|
-
id: "pinned-git-deps",
|
|
7187
|
-
title: "A dependency from git (github:, git+https: or owner/repo) names a full commit SHA.",
|
|
7188
|
-
reason: "A git ref without a commit moves with the branch. Then an install today and an install tomorrow get different code, and the lockfile hides the change.",
|
|
7189
|
-
fix: "Use the npm version, `workspace:*` for a package of this repository, or `github:owner/repo#<full commit SHA>`.",
|
|
7190
|
-
sources: [
|
|
7191
|
-
{
|
|
7192
|
-
repo: "coeval",
|
|
7193
|
-
rule: "pinned-deps",
|
|
7194
|
-
doc: "CLAUDE.md:41"
|
|
7195
|
-
},
|
|
7196
|
-
{
|
|
7197
|
-
repo: "coeval",
|
|
7198
|
-
rule: "unpublished-dep-pinned",
|
|
7199
|
-
doc: "CLAUDE.md:41"
|
|
7200
|
-
},
|
|
7201
|
-
{
|
|
7202
|
-
repo: "headroom",
|
|
7203
|
-
rule: "non-npm-deps-pinned",
|
|
7204
|
-
doc: "CLAUDE.md:38"
|
|
7205
|
-
},
|
|
7206
|
-
{
|
|
7207
|
-
repo: "headroom",
|
|
7208
|
-
rule: "pinned-github-specifier",
|
|
7209
|
-
doc: "CLAUDE.md:38"
|
|
7210
|
-
},
|
|
7211
|
-
{
|
|
7212
|
-
repo: "Graph",
|
|
7213
|
-
rule: "github-dep-full-sha",
|
|
7214
|
-
doc: "docs/decisions.md:1384"
|
|
7215
|
-
},
|
|
7216
|
-
{
|
|
7217
|
-
repo: "Graph",
|
|
7218
|
-
rule: "github-dep-pinned",
|
|
7219
|
-
doc: "docs/decisions.md:1384"
|
|
7220
|
-
},
|
|
7221
|
-
{
|
|
7222
|
-
repo: "client",
|
|
7223
|
-
rule: "general-npm-version",
|
|
7224
|
-
doc: "CLAUDE.md:54"
|
|
7225
|
-
}
|
|
7226
|
-
],
|
|
7227
|
-
options: { fullSha: {
|
|
7228
|
-
type: "boolean",
|
|
7229
|
-
default: true,
|
|
7230
|
-
description: "When false, a short SHA of 7 or more characters is also a commit."
|
|
7231
|
-
} },
|
|
7232
|
-
check(context, options) {
|
|
7233
|
-
const fullSha = options["fullSha"] !== false;
|
|
7234
|
-
const breaks = [];
|
|
7235
|
-
for (const info of [context.rootPackage, ...context.packages]) {
|
|
7236
|
-
const found = [];
|
|
7237
|
-
for (const field of DEPENDENCY_FIELDS) for (const [name, spec] of specifiersOf(info.manifest, field)) found.push([
|
|
7238
|
-
field,
|
|
7239
|
-
name,
|
|
7240
|
-
spec
|
|
7241
|
-
]);
|
|
7242
|
-
found.push(...overridesOf(info.manifest));
|
|
7243
|
-
for (const [field, name, spec] of found) {
|
|
7244
|
-
if (!isGitSpecifier(spec) || isPinned(spec, fullSha)) continue;
|
|
7245
|
-
const line = keyLine(info.text, field, name);
|
|
7815
|
+
const next = lines[index + 1] ?? "";
|
|
7816
|
+
if (!(isPathCompare(line) || line.includes("process.argv[1]") && !/import\.meta/.test(line) && !isPathCompare(next) && isPathCompare(`${line} ${next}`))) continue;
|
|
7817
|
+
const fixed = fixLine(line, main ? "import.meta.main" : REAL_COMPARE);
|
|
7818
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
7819
|
+
const after = fixed === void 0 ? void 0 : fixImports([
|
|
7820
|
+
...lines.slice(0, index),
|
|
7821
|
+
fixed,
|
|
7822
|
+
...lines.slice(index + 1)
|
|
7823
|
+
].join(eol), main ? [] : REAL_IMPORTS);
|
|
7246
7824
|
breaks.push({
|
|
7247
|
-
file
|
|
7248
|
-
|
|
7249
|
-
message:
|
|
7825
|
+
file,
|
|
7826
|
+
line: index + 1,
|
|
7827
|
+
message: "The script compares process.argv[1] with its own path, which is false through a link.",
|
|
7828
|
+
...after === void 0 ? { fix: "Change the condition by hand: it has more than the main check, or it is on more than one line." } : { edits: [{
|
|
7829
|
+
file,
|
|
7830
|
+
before: text,
|
|
7831
|
+
after
|
|
7832
|
+
}] }
|
|
7250
7833
|
});
|
|
7251
7834
|
}
|
|
7252
7835
|
}
|
|
7253
7836
|
return breaks;
|
|
7254
7837
|
}
|
|
7255
7838
|
};
|
|
7256
|
-
// src/rules/
|
|
7839
|
+
// src/rules/no-build-output.ts
|
|
7257
7840
|
/**
|
|
7258
|
-
* The rule `
|
|
7259
|
-
* that everyone can see.
|
|
7841
|
+
* The rule `no-build-output`: git does not keep build output.
|
|
7260
7842
|
*/
|
|
7261
|
-
|
|
7262
|
-
|
|
7263
|
-
|
|
7264
|
-
|
|
7265
|
-
|
|
7266
|
-
const event = JSON.parse(readFileSync(file, "utf8"));
|
|
7267
|
-
const body = typeof event.pull_request?.body === "string" ? event.pull_request.body : "";
|
|
7268
|
-
const commits = event.pull_request?.commits;
|
|
7269
|
-
return typeof commits === "number" ? {
|
|
7270
|
-
body,
|
|
7271
|
-
commits
|
|
7272
|
-
} : { body };
|
|
7273
|
-
} catch {
|
|
7274
|
-
return { body: "" };
|
|
7275
|
-
}
|
|
7276
|
-
}
|
|
7277
|
-
/** This function escapes the special characters of a regular expression. */
|
|
7278
|
-
const escape = (text) => text.replace(/[\\^$.|?*+()[\]{}]/g, "\\$&");
|
|
7279
|
-
const releaseFiles = {
|
|
7280
|
-
id: "release-files",
|
|
7281
|
-
title: "A pull request changes `.github/workflows/release.yml` or `scripts/release/` only with a `Release-Edit: <reason>` line.",
|
|
7282
|
-
reason: "The release flow publishes to npm with trusted publishing. A change of its files by a session that does not own the release can stop or break each release.",
|
|
7283
|
-
fix: "Revert the change of the release files. When the owner asked for the change, add the line `Release-Edit: <reason>` to the last commit message or to the body of the pull request. A re-run of a job reads the body of the event that started the run, so after a change of the body, push a commit.",
|
|
7843
|
+
const noBuildOutput = {
|
|
7844
|
+
id: "no-build-output",
|
|
7845
|
+
title: "Git keeps no build output: no tracked file is in a folder named `dist` or `build`.",
|
|
7846
|
+
reason: "The release workflow builds each package from the source. Build output in git goes stale, makes noise in each diff, and a user can get old code from a git install.",
|
|
7847
|
+
fix: "Remove the folder from git with `git rm -r --cached <folder>`, and keep its name in `.gitignore`.",
|
|
7284
7848
|
sources: [
|
|
7285
7849
|
{
|
|
7286
|
-
repo: "
|
|
7287
|
-
rule: "no-
|
|
7288
|
-
doc: "CLAUDE.md:
|
|
7289
|
-
},
|
|
7290
|
-
{
|
|
7291
|
-
repo: "coeval",
|
|
7292
|
-
rule: "no-release-edits",
|
|
7293
|
-
doc: "CLAUDE.md:40"
|
|
7294
|
-
},
|
|
7295
|
-
{
|
|
7296
|
-
repo: "crawler",
|
|
7297
|
-
rule: "no-release-edit",
|
|
7298
|
-
doc: "CLAUDE.md:80"
|
|
7299
|
-
},
|
|
7300
|
-
{
|
|
7301
|
-
repo: "crawler",
|
|
7302
|
-
rule: "no-release-edits",
|
|
7303
|
-
doc: "CLAUDE.md:80"
|
|
7850
|
+
repo: "client",
|
|
7851
|
+
rule: "no-build-output",
|
|
7852
|
+
doc: "CLAUDE.md:48"
|
|
7304
7853
|
},
|
|
7305
7854
|
{
|
|
7306
|
-
repo: "
|
|
7307
|
-
rule: "no-
|
|
7308
|
-
doc: "CLAUDE.md:
|
|
7855
|
+
repo: "client",
|
|
7856
|
+
rule: "no-dist",
|
|
7857
|
+
doc: "CLAUDE.md:48"
|
|
7309
7858
|
},
|
|
7310
7859
|
{
|
|
7311
|
-
repo: "
|
|
7312
|
-
rule: "
|
|
7313
|
-
doc: "CLAUDE.md:
|
|
7860
|
+
repo: "client",
|
|
7861
|
+
rule: "no-dist-commit",
|
|
7862
|
+
doc: "CLAUDE.md:48"
|
|
7314
7863
|
}
|
|
7315
7864
|
],
|
|
7316
|
-
options: {
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
},
|
|
7322
|
-
trailer: {
|
|
7323
|
-
type: "string",
|
|
7324
|
-
default: "Release-Edit",
|
|
7325
|
-
description: "The key of the line that gives the reason of a change."
|
|
7326
|
-
},
|
|
7327
|
-
authors: {
|
|
7328
|
-
type: "strings",
|
|
7329
|
-
default: ["mark1russell7-release-train[bot]"],
|
|
7330
|
-
description: "The authors of the release flow. A change of the release files in commits of only these authors (the sync of the template) needs no reason."
|
|
7331
|
-
}
|
|
7332
|
-
},
|
|
7865
|
+
options: { folders: {
|
|
7866
|
+
type: "strings",
|
|
7867
|
+
default: ["dist", "build"],
|
|
7868
|
+
description: "The names of the folders of build output."
|
|
7869
|
+
} },
|
|
7333
7870
|
check(context, options) {
|
|
7334
|
-
const
|
|
7335
|
-
if (
|
|
7336
|
-
const
|
|
7337
|
-
const
|
|
7338
|
-
|
|
7339
|
-
"
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
7347
|
-
|
|
7348
|
-
|
|
7349
|
-
"--verify",
|
|
7350
|
-
"--quiet",
|
|
7351
|
-
`${range.ends[1]}^2`
|
|
7352
|
-
]) === void 0) && context.git(["merge-base", ...range.ends]) === void 0) throw new Error(`The checkout does not have the merge base of ${range.ends.join(" and ")}, so the rule cannot read each commit of the change. Use fetch-depth 0, or the CI of the template, which deepens the checkout of a pull request to its merge base.`);
|
|
7353
|
-
const messages = context.git([
|
|
7354
|
-
"log",
|
|
7355
|
-
"--no-merges",
|
|
7356
|
-
"--format=%B",
|
|
7357
|
-
...range.log
|
|
7358
|
-
]) ?? "";
|
|
7359
|
-
if (line.test(messages)) return [];
|
|
7360
|
-
const authors = new Set(Array.isArray(options["authors"]) ? options["authors"] : []);
|
|
7361
|
-
const changers = (context.git([
|
|
7362
|
-
"log",
|
|
7363
|
-
"--no-merges",
|
|
7364
|
-
"--format=%an",
|
|
7365
|
-
...range.log,
|
|
7366
|
-
"--",
|
|
7367
|
-
...changed
|
|
7368
|
-
]) ?? "").split(/\r?\n/).filter((name) => name !== "");
|
|
7369
|
-
if (changers.length > 0 && changers.every((name) => authors.has(name))) return [];
|
|
7370
|
-
return changed.map((file) => ({
|
|
7371
|
-
file,
|
|
7372
|
-
message: `The change edits ${file}, a file of the release flow, with no "${trailer}: <reason>" line.`
|
|
7871
|
+
const files = context.gitFiles();
|
|
7872
|
+
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
7873
|
+
const names = new Set(Array.isArray(options["folders"]) ? options["folders"] : ["dist", "build"]);
|
|
7874
|
+
const counts = /* @__PURE__ */ new Map();
|
|
7875
|
+
for (const file of files) {
|
|
7876
|
+
const segments = file.split("/");
|
|
7877
|
+
const index = segments.slice(0, -1).findIndex((segment) => names.has(segment));
|
|
7878
|
+
if (index < 0) continue;
|
|
7879
|
+
const folder = segments.slice(0, index + 1).join("/");
|
|
7880
|
+
counts.set(folder, (counts.get(folder) ?? 0) + 1);
|
|
7881
|
+
}
|
|
7882
|
+
return [...counts.keys()].sort(byCode).map((folder) => ({
|
|
7883
|
+
file: `${folder}/`,
|
|
7884
|
+
message: `Git keeps ${counts.get(folder) ?? 0} file(s) in ${folder}/.`,
|
|
7885
|
+
fix: `Start \`git rm -r --cached ${folder}\`, and keep ${folder.split("/").pop() ?? folder}/ in .gitignore.`
|
|
7373
7886
|
}));
|
|
7374
7887
|
}
|
|
7375
7888
|
};
|
|
7376
|
-
// src/rules/
|
|
7377
|
-
/**
|
|
7378
|
-
* The rule `required-scripts`: the root `package.json` keeps the scripts that the shared CI starts.
|
|
7379
|
-
*/
|
|
7380
|
-
/** The package of the STE linter. */
|
|
7381
|
-
const STE_LINT = "@mark1russell7/ste-lint";
|
|
7382
|
-
/** The configuration file of the STE linter. */
|
|
7383
|
-
const STE_CONFIG = "ste.config.json";
|
|
7384
|
-
/** The examples of the scripts that the fix shows. */
|
|
7385
|
-
const EXAMPLES = {
|
|
7386
|
-
"lint:ste": "ste-lint",
|
|
7387
|
-
typecheck: "pnpm -r run typecheck"
|
|
7388
|
-
};
|
|
7889
|
+
// src/rules/no-local-paths.ts
|
|
7389
7890
|
/**
|
|
7390
|
-
*
|
|
7391
|
-
* dependency on `@mark1russell7/ste-lint`, or the root has a `ste.config.json`.
|
|
7891
|
+
* The rule `no-local-paths`: no tracked file names the home folder of a user of a computer.
|
|
7392
7892
|
*/
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
const
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7893
|
+
/** The extensions of files that are not text. The rule does not read them. */
|
|
7894
|
+
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(" "));
|
|
7895
|
+
/** The largest file that the rule reads, in bytes. */
|
|
7896
|
+
const MAX_BYTES = 2097152;
|
|
7897
|
+
/** The names in a home path that do not identify a person: CI users, container users and placeholders. */
|
|
7898
|
+
const DEFAULT_ALLOWED = [
|
|
7899
|
+
"runner",
|
|
7900
|
+
"runneradmin",
|
|
7901
|
+
"user",
|
|
7902
|
+
"username",
|
|
7903
|
+
"you",
|
|
7904
|
+
"me",
|
|
7905
|
+
"name",
|
|
7906
|
+
"yourname",
|
|
7907
|
+
"your-name",
|
|
7908
|
+
"example",
|
|
7909
|
+
"node",
|
|
7910
|
+
"ubuntu",
|
|
7911
|
+
"vscode",
|
|
7912
|
+
"codespace",
|
|
7913
|
+
"public",
|
|
7914
|
+
"default",
|
|
7915
|
+
"shared",
|
|
7916
|
+
"all users"
|
|
7917
|
+
];
|
|
7918
|
+
/** The forms of a home folder: Windows, macOS and Linux. The group `user` is the name of the user. */
|
|
7919
|
+
const HOME_PATTERNS = [
|
|
7920
|
+
/\b[A-Za-z]:(?:\\{1,2}|\/)[Uu][Ss][Ee][Rr][Ss](?:\\{1,2}|\/)(?<user>[^\\/\s"'`<>|:*?%$(){}[\],;]+)/g,
|
|
7921
|
+
/(?<![\w.~-])\/Users\/(?<user>[^/\s"'`<>|:*?%$(){}[\],;]+)/g,
|
|
7922
|
+
/(?<![\w.~-])\/home\/(?<user>[^/\s"'`<>|:*?%$(){}[\],;]+)/g
|
|
7923
|
+
];
|
|
7924
|
+
const noLocalPaths = {
|
|
7925
|
+
id: "no-local-paths",
|
|
7926
|
+
title: "No tracked file has the home folder of a user (`C:\\Users\\<name>`, `/Users/<name>`, `/home/<name>`).",
|
|
7927
|
+
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.",
|
|
7928
|
+
fix: "Use a path relative to the repository, `~`, an environment variable, or a placeholder such as `<you>`.",
|
|
7403
7929
|
sources: [
|
|
7404
7930
|
{
|
|
7405
7931
|
repo: "client",
|
|
7406
|
-
rule: "
|
|
7407
|
-
doc: "
|
|
7408
|
-
},
|
|
7409
|
-
{
|
|
7410
|
-
repo: "coeval",
|
|
7411
|
-
rule: "ste-prose",
|
|
7412
|
-
doc: "CLAUDE.md:5"
|
|
7413
|
-
},
|
|
7414
|
-
{
|
|
7415
|
-
repo: "crawler",
|
|
7416
|
-
rule: "ste-prose",
|
|
7417
|
-
doc: "CLAUDE.md:5"
|
|
7418
|
-
},
|
|
7419
|
-
{
|
|
7420
|
-
repo: "Graph",
|
|
7421
|
-
rule: "ste-prose",
|
|
7422
|
-
doc: "CLAUDE.md:5"
|
|
7423
|
-
},
|
|
7424
|
-
{
|
|
7425
|
-
repo: "headroom",
|
|
7426
|
-
rule: "ste-prose",
|
|
7427
|
-
doc: "CLAUDE.md:19"
|
|
7932
|
+
rule: "I12",
|
|
7933
|
+
doc: "packages/documentation/ARCHITECTURE.md:201"
|
|
7428
7934
|
},
|
|
7429
7935
|
{
|
|
7430
7936
|
repo: "systems",
|
|
7431
|
-
rule: "
|
|
7432
|
-
doc: "CLAUDE.md:
|
|
7433
|
-
},
|
|
7434
|
-
{
|
|
7435
|
-
repo: "Vex",
|
|
7436
|
-
rule: "ste-prose",
|
|
7437
|
-
doc: "CLAUDE.md:5"
|
|
7438
|
-
},
|
|
7439
|
-
{
|
|
7440
|
-
repo: "coeval",
|
|
7441
|
-
rule: "tsconfig-test",
|
|
7442
|
-
doc: "CLAUDE.md:18"
|
|
7937
|
+
rule: "no-identifying-names",
|
|
7938
|
+
doc: "CLAUDE.md:12"
|
|
7443
7939
|
},
|
|
7444
7940
|
{
|
|
7445
|
-
repo: "
|
|
7446
|
-
rule: "
|
|
7447
|
-
doc: "CLAUDE.md:
|
|
7941
|
+
repo: "systems",
|
|
7942
|
+
rule: "no-private-identifiers",
|
|
7943
|
+
doc: "CLAUDE.md:12"
|
|
7448
7944
|
},
|
|
7449
7945
|
{
|
|
7450
|
-
repo: "
|
|
7451
|
-
rule: "
|
|
7452
|
-
doc: "CLAUDE.md:
|
|
7946
|
+
repo: "systems",
|
|
7947
|
+
rule: "no-private-names",
|
|
7948
|
+
doc: "CLAUDE.md:12"
|
|
7453
7949
|
},
|
|
7454
7950
|
{
|
|
7455
|
-
repo: "
|
|
7456
|
-
rule: "
|
|
7457
|
-
doc: "CLAUDE.md:
|
|
7951
|
+
repo: "coeval",
|
|
7952
|
+
rule: "no-private-names",
|
|
7953
|
+
doc: "CLAUDE.md:22"
|
|
7458
7954
|
}
|
|
7459
7955
|
],
|
|
7460
7956
|
options: {
|
|
7461
|
-
|
|
7957
|
+
allow: {
|
|
7462
7958
|
type: "strings",
|
|
7463
|
-
default: [
|
|
7464
|
-
description: "
|
|
7959
|
+
default: [],
|
|
7960
|
+
description: "More user names that do not identify a person."
|
|
7465
7961
|
},
|
|
7466
|
-
|
|
7962
|
+
patterns: {
|
|
7467
7963
|
type: "strings",
|
|
7468
|
-
default: [
|
|
7469
|
-
description: "
|
|
7964
|
+
default: [],
|
|
7965
|
+
description: "More regular expressions of text that no file has. The environment variable CONVENTIONS_PRIVATE_PATTERNS adds one on each line, so a private name stays out of package.json."
|
|
7470
7966
|
}
|
|
7471
7967
|
},
|
|
7472
7968
|
check(context, options) {
|
|
7473
|
-
const
|
|
7474
|
-
|
|
7475
|
-
const
|
|
7476
|
-
const
|
|
7477
|
-
const
|
|
7478
|
-
const
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
}
|
|
7488
|
-
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7492
|
-
|
|
7493
|
-
|
|
7494
|
-
const
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
]
|
|
7502
|
-
|
|
7503
|
-
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
|
|
7513
|
-
const match = pattern.exec(lower);
|
|
7514
|
-
if (match && match.index < best.index) best = {
|
|
7515
|
-
index: match.index,
|
|
7516
|
-
value
|
|
7517
|
-
};
|
|
7518
|
-
}
|
|
7519
|
-
return best.value;
|
|
7520
|
-
}
|
|
7521
|
-
/** This function gives the cells of a table row. A "|" in a code span or after "\" is text. */
|
|
7522
|
-
function splitRow(line) {
|
|
7523
|
-
const cells = [];
|
|
7524
|
-
let cell = "";
|
|
7525
|
-
let code = false;
|
|
7526
|
-
const text = line.trim().replace(/^\|/, "").replace(/\|$/, "");
|
|
7527
|
-
for (let index = 0; index < text.length; index++) {
|
|
7528
|
-
const char = text[index];
|
|
7529
|
-
if (char === "\\" && text[index + 1] === "|") {
|
|
7530
|
-
cell += "|";
|
|
7531
|
-
index++;
|
|
7532
|
-
} else if (char === "`") {
|
|
7533
|
-
code = !code;
|
|
7534
|
-
cell += char;
|
|
7535
|
-
} else if (char === "|" && !code) {
|
|
7536
|
-
cells.push(cell.trim());
|
|
7537
|
-
cell = "";
|
|
7538
|
-
} else cell += char;
|
|
7539
|
-
}
|
|
7540
|
-
cells.push(cell.trim());
|
|
7541
|
-
return cells;
|
|
7542
|
-
}
|
|
7543
|
-
/** A whitespace character, as `\s` of a regular expression and `String.prototype.trim` read it. */
|
|
7544
|
-
const SPACE = /\s/;
|
|
7545
|
-
/** A character that `.` of a regular expression does not match. */
|
|
7546
|
-
const LINE_TERMINATOR = /[\n\r\u2028\u2029]/;
|
|
7547
|
-
/** The first whitespace character at or after `lastIndex`. */
|
|
7548
|
-
const NEXT_SPACE = /\s/g;
|
|
7549
|
-
/**
|
|
7550
|
-
* This function replaces each Markdown link `[label](target)` of a text with the result of
|
|
7551
|
-
* `replace`. The label ends at the first `]`, and the target ends at the first `)`. In `strict`
|
|
7552
|
-
* mode, the label and the target are not empty, and the target has no whitespace.
|
|
7553
|
-
*
|
|
7554
|
-
* @remarks The function reads the text one time. A regular expression for these links can
|
|
7555
|
-
* backtrack (CodeQL `js/polynomial-redos`). For a long text with many `[` characters, its time
|
|
7556
|
-
* grows with the square of the length.
|
|
7557
|
-
*/
|
|
7558
|
-
function replaceLinks(text, strict, replace) {
|
|
7559
|
-
let result = "";
|
|
7560
|
-
let copied = 0;
|
|
7561
|
-
let close = -1;
|
|
7562
|
-
let end = -1;
|
|
7563
|
-
let space = -1;
|
|
7564
|
-
for (let open = text.indexOf("["); open !== -1; open = text.indexOf("[", open + 1)) {
|
|
7565
|
-
if (close <= open) close = text.indexOf("]", open + 1);
|
|
7566
|
-
if (close === -1) break;
|
|
7567
|
-
if (text[close + 1] !== "(" || strict && close === open + 1) continue;
|
|
7568
|
-
const start = close + 2;
|
|
7569
|
-
if (end < start) end = text.indexOf(")", start);
|
|
7570
|
-
if (end === -1) break;
|
|
7571
|
-
if (strict) {
|
|
7572
|
-
if (space !== Infinity && space < start) {
|
|
7573
|
-
NEXT_SPACE.lastIndex = start;
|
|
7574
|
-
space = NEXT_SPACE.exec(text)?.index ?? Infinity;
|
|
7969
|
+
const files = context.gitFiles();
|
|
7970
|
+
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
7971
|
+
const allowed = new Set([...DEFAULT_ALLOWED, ...Array.isArray(options["allow"]) ? options["allow"] : []].map((name) => name.toLowerCase()));
|
|
7972
|
+
const fromEnv = (context.env["CONVENTIONS_PRIVATE_PATTERNS"] ?? "").split("\n").map((line) => line.trim()).filter((line) => line !== "");
|
|
7973
|
+
const extra = [...Array.isArray(options["patterns"]) ? options["patterns"] : [], ...fromEnv].map((source) => new RegExp(source, "g"));
|
|
7974
|
+
const rootFile = context.rootPackage.file;
|
|
7975
|
+
const breaks = [];
|
|
7976
|
+
for (const file of files) {
|
|
7977
|
+
if (BINARY.has(extname(file).toLowerCase())) continue;
|
|
7978
|
+
const path = join(context.root, file);
|
|
7979
|
+
let text;
|
|
7980
|
+
try {
|
|
7981
|
+
if (statSync(path).size > MAX_BYTES) continue;
|
|
7982
|
+
text = readFileSync(path, "utf8");
|
|
7983
|
+
} catch {
|
|
7984
|
+
continue;
|
|
7985
|
+
}
|
|
7986
|
+
if (text.includes("\0")) continue;
|
|
7987
|
+
const lines = text.split(/\r?\n/);
|
|
7988
|
+
for (let index = 0; index < lines.length; index++) {
|
|
7989
|
+
const line = lines[index] ?? "";
|
|
7990
|
+
const isReason = file === rootFile && /^\s*"(?:reason|off)"\s*:/.test(line);
|
|
7991
|
+
for (const pattern of isReason ? [] : HOME_PATTERNS) for (const match of line.matchAll(pattern)) {
|
|
7992
|
+
const user = match.groups?.["user"] ?? "";
|
|
7993
|
+
if (user.length < 2 || allowed.has(user.toLowerCase())) continue;
|
|
7994
|
+
breaks.push({
|
|
7995
|
+
file,
|
|
7996
|
+
line: index + 1,
|
|
7997
|
+
message: `The text "${match[0]}" is the home folder of a user.`
|
|
7998
|
+
});
|
|
7999
|
+
}
|
|
8000
|
+
for (const pattern of extra) {
|
|
8001
|
+
if (file === rootFile && line.trim().replace(/,$/, "") === JSON.stringify(pattern.source)) continue;
|
|
8002
|
+
for (const match of line.matchAll(pattern)) breaks.push({
|
|
8003
|
+
file,
|
|
8004
|
+
line: index + 1,
|
|
8005
|
+
message: `The text "${match[0]}" matches the pattern ${pattern.source}.`,
|
|
8006
|
+
fix: "Remove the text."
|
|
8007
|
+
});
|
|
8008
|
+
}
|
|
7575
8009
|
}
|
|
7576
|
-
if (end === start || space < end) continue;
|
|
7577
8010
|
}
|
|
7578
|
-
|
|
7579
|
-
copied = end + 1;
|
|
7580
|
-
open = end;
|
|
8011
|
+
return breaks;
|
|
7581
8012
|
}
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
/**
|
|
7585
|
-
* This function gives the text of an ATX heading without its closing sequence: the whitespace,
|
|
7586
|
-
* then the `#` characters, then the whitespace at the end. It gives null when the rest has a line
|
|
7587
|
-
* terminator, as the regular expression `(.*?)\s*#*\s*$` does.
|
|
7588
|
-
*/
|
|
7589
|
-
function closeHeading(text) {
|
|
7590
|
-
let end = text.length;
|
|
7591
|
-
while (end > 0 && SPACE.test(text[end - 1] ?? "")) end--;
|
|
7592
|
-
while (end > 0 && text[end - 1] === "#") end--;
|
|
7593
|
-
while (end > 0 && SPACE.test(text[end - 1] ?? "")) end--;
|
|
7594
|
-
const rest = text.slice(0, end);
|
|
7595
|
-
return LINE_TERMINATOR.test(rest) ? null : rest;
|
|
7596
|
-
}
|
|
7597
|
-
/** The start of an ATX heading. The text after the whitespace goes to `closeHeading`. */
|
|
7598
|
-
const HEADING = /^(#{1,6})\s+(\S[\s\S]*)?$/;
|
|
7599
|
-
/** This function gives the level and the text of an ATX heading line, or null for another line. */
|
|
7600
|
-
function headingOf(line) {
|
|
7601
|
-
const match = HEADING.exec(line);
|
|
7602
|
-
const text = match ? closeHeading(match[2] ?? "") : null;
|
|
7603
|
-
return match && text !== null ? {
|
|
7604
|
-
level: match[1]?.length ?? 0,
|
|
7605
|
-
text
|
|
7606
|
-
} : null;
|
|
7607
|
-
}
|
|
7608
|
-
/** This function gives the plain text of inline Markdown: no code marks, no emphasis, the text of each link. */
|
|
7609
|
-
function plainText(markdown) {
|
|
7610
|
-
return replaceLinks(String(markdown ?? ""), false, (label) => label).replace(/[`*_]/g, "").replace(/\s+/g, " ").trim();
|
|
7611
|
-
}
|
|
7612
|
-
/** A cell with no value: empty, or a dash. */
|
|
7613
|
-
function isEmpty(cell) {
|
|
7614
|
-
return cell === void 0 || /^(?:[-–—]|n\/a)?$/i.test(cell.trim());
|
|
7615
|
-
}
|
|
8013
|
+
};
|
|
8014
|
+
// src/rules/pages-site.ts
|
|
7616
8015
|
/**
|
|
7617
|
-
*
|
|
7618
|
-
*
|
|
8016
|
+
* The rule `pages-site`: a public repository has a site. A workflow uses the Pages workflow of the template, and the
|
|
8017
|
+
* call deploys.
|
|
7619
8018
|
*/
|
|
7620
|
-
|
|
7621
|
-
|
|
7622
|
-
|
|
7623
|
-
|
|
7624
|
-
|
|
7625
|
-
|
|
7626
|
-
|
|
7627
|
-
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
|
|
7631
|
-
|
|
7632
|
-
|
|
7633
|
-
|
|
7634
|
-
const heading = headingOf(line);
|
|
7635
|
-
if (heading) {
|
|
7636
|
-
section = plainText(heading.text);
|
|
7637
|
-
continue;
|
|
7638
|
-
}
|
|
7639
|
-
if (!line.trim().startsWith("|")) continue;
|
|
7640
|
-
const separator = lines[index + 1] ?? "";
|
|
7641
|
-
if (!/^\s*(?:\|\s*)?:?-{3,}/.test(separator)) continue;
|
|
7642
|
-
const header = splitRow(line).map((name) => plainText(name).toLowerCase());
|
|
7643
|
-
const rows = [];
|
|
7644
|
-
let next = index + 2;
|
|
7645
|
-
for (; next < lines.length && (lines[next] ?? "").trim().startsWith("|"); next++) rows.push({
|
|
7646
|
-
line: next + 1,
|
|
7647
|
-
cells: splitRow(lines[next] ?? "")
|
|
7648
|
-
});
|
|
7649
|
-
tables.push({
|
|
7650
|
-
section,
|
|
8019
|
+
/** The Pages workflow of the template, as a call from another repository and as a call from the template itself. */
|
|
8020
|
+
const PAGES_WORKFLOWS = ["mark1russell7/template/.github/workflows/reusable-pages.yml", "./.github/workflows/reusable-pages.yml"];
|
|
8021
|
+
/** This function gives each call of a workflow of `workflows` in the text of a workflow file. The ref after `@` can be any ref. */
|
|
8022
|
+
function pagesCalls(text, workflows = PAGES_WORKFLOWS) {
|
|
8023
|
+
const lines = workflowLines(text);
|
|
8024
|
+
const names = new Set(workflows.map((name) => name.toLowerCase()));
|
|
8025
|
+
const calls = [];
|
|
8026
|
+
lines.forEach((line, index) => {
|
|
8027
|
+
const uses = keyValue(line, "uses");
|
|
8028
|
+
if (uses === void 0 || !names.has((uses.split("@")[0] ?? "").toLowerCase())) return;
|
|
8029
|
+
let job = index - 1;
|
|
8030
|
+
while (job >= 0 && ((lines[job] ?? "").trim() === "" || indentOf$1(lines[job] ?? "") >= indentOf$1(line))) job -= 1;
|
|
8031
|
+
const body = job < 0 ? [line] : lines.slice(job, blockEnd(lines, job));
|
|
8032
|
+
calls.push({
|
|
7651
8033
|
line: index + 1,
|
|
7652
|
-
|
|
7653
|
-
rows
|
|
8034
|
+
deploys: !body.some((text) => keyValue(text, "deploy") === "false")
|
|
7654
8035
|
});
|
|
7655
|
-
|
|
7656
|
-
|
|
7657
|
-
return tables;
|
|
7658
|
-
}
|
|
7659
|
-
/** The columns whose cells hold the links of an item. */
|
|
7660
|
-
const LINK_COLUMNS = [
|
|
7661
|
-
"where",
|
|
7662
|
-
"commit",
|
|
7663
|
-
"commits",
|
|
7664
|
-
"link",
|
|
7665
|
-
"links",
|
|
7666
|
-
"pr",
|
|
7667
|
-
"prs"
|
|
7668
|
-
];
|
|
7669
|
-
/** Words before a reference that do not name a repository. */
|
|
7670
|
-
const NOT_REPOSITORIES = new Set("a an and also at by commit commits done fixed for from in into issue issues merged of on or plus pr prs run see the then to via with".split(" "));
|
|
7671
|
-
/** The URL of a link target of the roadmap file: an absolute URL stays, and a relative one goes to GitHub. */
|
|
7672
|
-
function linkUrl(target, { file = "", repository = "", ref = "HEAD" }) {
|
|
7673
|
-
if (/^[a-z][a-z0-9+.-]*:/i.test(target)) return target;
|
|
7674
|
-
if (!repository) return null;
|
|
7675
|
-
const [path = "", anchor = ""] = target.split("#", 2);
|
|
7676
|
-
const resolved = path === "" ? file : posix.normalize(posix.join(posix.dirname(file), path));
|
|
7677
|
-
if (resolved.startsWith("..")) return null;
|
|
7678
|
-
return `https://github.com/${repository}/blob/${ref}/${resolved}${anchor ? `#${anchor}` : ""}`;
|
|
8036
|
+
});
|
|
8037
|
+
return calls;
|
|
7679
8038
|
}
|
|
8039
|
+
const pagesSite = {
|
|
8040
|
+
id: "pages-site",
|
|
8041
|
+
title: "A public repository has a workflow that calls the Pages workflow of the template (`reusable-pages.yml`, any ref), and the call deploys.",
|
|
8042
|
+
reason: "Each public project has a site with its Releases page and its Status page, so a reader sees the versions and the open work. On 2026-11-02 eight public repositories had no site: typeset, algebra, headroom, release-train, optional, ste-lint, lag-hud and template.",
|
|
8043
|
+
fix: "Add `.github/workflows/pages.yml` with a job `uses: mark1russell7/template/.github/workflows/reusable-pages.yml@<commit> # main` and the permissions of CI.md (\"Pages\"). Give `build`, `out` and `roadmap: docs/ROADMAP.md`. After the build, the job starts `site-pages build`, which adds the Releases page and the Status page. Then set the Pages source to \"GitHub Actions\": `gh api -X POST repos/<owner>/<repo>/pages -f build_type=workflow`.",
|
|
8044
|
+
sources: [
|
|
8045
|
+
"vex",
|
|
8046
|
+
"crawler",
|
|
8047
|
+
"client",
|
|
8048
|
+
"coeval"
|
|
8049
|
+
].map((repo) => ({
|
|
8050
|
+
repo,
|
|
8051
|
+
rule: "pages-site",
|
|
8052
|
+
doc: ".github/workflows/pages.yml (a call of reusable-pages.yml of the template)"
|
|
8053
|
+
})),
|
|
8054
|
+
options: { workflows: {
|
|
8055
|
+
type: "strings",
|
|
8056
|
+
default: PAGES_WORKFLOWS,
|
|
8057
|
+
description: "The workflows that deploy a site, without the ref after `@`."
|
|
8058
|
+
} },
|
|
8059
|
+
check(context, options) {
|
|
8060
|
+
const visible = repositoryIsPublic(context);
|
|
8061
|
+
if (visible === void 0) return { skipped: "outside a GitHub Actions run, the rule cannot tell if the repository is public" };
|
|
8062
|
+
if (!visible) return [];
|
|
8063
|
+
const files = context.gitFiles();
|
|
8064
|
+
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
8065
|
+
const calls = files.filter((path) => WORKFLOW$1.test(path)).sort(byCode).flatMap((file) => pagesCalls(readFileSync(join(context.root, file), "utf8"), options["workflows"]).map((call) => ({
|
|
8066
|
+
file,
|
|
8067
|
+
...call
|
|
8068
|
+
})));
|
|
8069
|
+
if (calls.some((call) => call.deploys)) return [];
|
|
8070
|
+
return [{
|
|
8071
|
+
file: ".github/workflows/pages.yml",
|
|
8072
|
+
message: `The repository is public, and no workflow deploys its site with the Pages workflow of the template.${calls.length === 0 ? "" : ` The calls in ${[...new Set(calls.map((call) => call.file))].join(", ")} have deploy: false.`}`
|
|
8073
|
+
}];
|
|
8074
|
+
}
|
|
8075
|
+
};
|
|
8076
|
+
// src/rules/pinned-git-deps.ts
|
|
7680
8077
|
/**
|
|
7681
|
-
*
|
|
7682
|
-
* regular expression `([A-Za-z][\w.-]*)\s+$` does. The word starts with a letter. The function
|
|
7683
|
-
* reads only the characters of the word and of the whitespace.
|
|
8078
|
+
* The rule `pinned-git-deps`: a dependency from git names a full commit.
|
|
7684
8079
|
*/
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
8080
|
+
/** The fields of the root `package.json` that replace the specifiers of dependencies. */
|
|
8081
|
+
const OVERRIDE_FIELDS = ["overrides", "resolutions"];
|
|
8082
|
+
/** This function tells if a specifier gets the package from git, not from a registry or the workspace. */
|
|
8083
|
+
function isGitSpecifier(spec) {
|
|
8084
|
+
const value = spec.trim();
|
|
8085
|
+
if (/^(github|gitlab|bitbucket|gist):/i.test(value)) return true;
|
|
8086
|
+
if (/^git(\+[a-z]+)?:/i.test(value) || /^git@/i.test(value)) return true;
|
|
8087
|
+
if (/^https?:\/\/(www\.)?(github\.com|gitlab\.com|bitbucket\.org|codeload\.github\.com)\//i.test(value)) return true;
|
|
8088
|
+
return /^[\w-][\w.-]*\/[\w.-]+(#.*)?$/.test(value) && !value.startsWith("@");
|
|
7693
8089
|
}
|
|
7694
8090
|
/**
|
|
7695
|
-
* This function
|
|
7696
|
-
*
|
|
7697
|
-
*
|
|
7698
|
-
* @remarks A repository name right before a reference ("systems PR #16") applies to it and to the
|
|
7699
|
-
* next references of the cell. Without a name, a reference belongs to `repository`.
|
|
8091
|
+
* This function tells if a git specifier names a commit. A specifier names a commit when its ref
|
|
8092
|
+
* (after `#`) is a commit SHA, or when a tarball URL has the SHA in its path.
|
|
7700
8093
|
*/
|
|
7701
|
-
function
|
|
7702
|
-
const
|
|
7703
|
-
const
|
|
7704
|
-
|
|
7705
|
-
const
|
|
7706
|
-
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
|
|
7713
|
-
|
|
7714
|
-
|
|
7715
|
-
|
|
7716
|
-
|
|
7717
|
-
if (
|
|
7718
|
-
|
|
7719
|
-
|
|
7720
|
-
|
|
7721
|
-
|
|
7722
|
-
|
|
7723
|
-
const word = wordBefore(rest, match.index);
|
|
7724
|
-
if (word && !NOT_REPOSITORIES.has(word.toLowerCase())) current = word;
|
|
7725
|
-
const prefix = current === defaultRepo ? "" : `${current} `;
|
|
7726
|
-
if (match[1] !== void 0) pulls = true;
|
|
7727
|
-
const number = match[1] ?? match[2];
|
|
7728
|
-
if (number !== void 0) add(`${prefix}#${number}`, `https://github.com/${owner}/${current}/${pulls ? "pull" : "issues"}/${number}`);
|
|
7729
|
-
else if (match[3] !== void 0) add(`${prefix}${match[3].slice(0, 7)}`, `https://github.com/${owner}/${current}/commit/${match[3]}`);
|
|
7730
|
-
}
|
|
7731
|
-
return links;
|
|
8094
|
+
function isPinned(spec, fullSha) {
|
|
8095
|
+
const sha = fullSha ? /^[0-9a-f]{40}$/i : /^[0-9a-f]{7,40}$/i;
|
|
8096
|
+
const hash = spec.indexOf("#");
|
|
8097
|
+
if (hash >= 0) return spec.slice(hash + 1).split("&").some((part) => sha.test(part.replace(/^commit=/, "")));
|
|
8098
|
+
const path = /^https?:\/\/[^/]+\/(.*)$/i.exec(spec.trim())?.[1];
|
|
8099
|
+
return path !== void 0 && path.split(/[/.]/).some((part) => sha.test(part));
|
|
8100
|
+
}
|
|
8101
|
+
/** This function gives the specifiers of the fields of overrides, also the field `overrides` of `pnpm`. */
|
|
8102
|
+
function overridesOf(manifest) {
|
|
8103
|
+
const out = [];
|
|
8104
|
+
for (const field of OVERRIDE_FIELDS) for (const [name, spec] of specifiersOf(manifest, field)) out.push([
|
|
8105
|
+
field,
|
|
8106
|
+
name,
|
|
8107
|
+
spec
|
|
8108
|
+
]);
|
|
8109
|
+
const pnpm = manifest["pnpm"];
|
|
8110
|
+
if (typeof pnpm === "object" && pnpm !== null) for (const [name, spec] of specifiersOf(pnpm, "overrides")) out.push([
|
|
8111
|
+
"pnpm",
|
|
8112
|
+
name,
|
|
8113
|
+
spec
|
|
8114
|
+
]);
|
|
8115
|
+
return out;
|
|
7732
8116
|
}
|
|
8117
|
+
const pinnedGitDeps = {
|
|
8118
|
+
id: "pinned-git-deps",
|
|
8119
|
+
title: "A dependency from git (github:, git+https: or owner/repo) names a full commit SHA.",
|
|
8120
|
+
reason: "A git ref without a commit moves with the branch. Then an install today and an install tomorrow get different code, and the lockfile hides the change.",
|
|
8121
|
+
fix: "Use the npm version, `workspace:*` for a package of this repository, or `github:owner/repo#<full commit SHA>`.",
|
|
8122
|
+
sources: [
|
|
8123
|
+
{
|
|
8124
|
+
repo: "coeval",
|
|
8125
|
+
rule: "pinned-deps",
|
|
8126
|
+
doc: "CLAUDE.md:41"
|
|
8127
|
+
},
|
|
8128
|
+
{
|
|
8129
|
+
repo: "coeval",
|
|
8130
|
+
rule: "unpublished-dep-pinned",
|
|
8131
|
+
doc: "CLAUDE.md:41"
|
|
8132
|
+
},
|
|
8133
|
+
{
|
|
8134
|
+
repo: "headroom",
|
|
8135
|
+
rule: "non-npm-deps-pinned",
|
|
8136
|
+
doc: "CLAUDE.md:38"
|
|
8137
|
+
},
|
|
8138
|
+
{
|
|
8139
|
+
repo: "headroom",
|
|
8140
|
+
rule: "pinned-github-specifier",
|
|
8141
|
+
doc: "CLAUDE.md:38"
|
|
8142
|
+
},
|
|
8143
|
+
{
|
|
8144
|
+
repo: "Graph",
|
|
8145
|
+
rule: "github-dep-full-sha",
|
|
8146
|
+
doc: "docs/decisions.md:1384"
|
|
8147
|
+
},
|
|
8148
|
+
{
|
|
8149
|
+
repo: "Graph",
|
|
8150
|
+
rule: "github-dep-pinned",
|
|
8151
|
+
doc: "docs/decisions.md:1384"
|
|
8152
|
+
},
|
|
8153
|
+
{
|
|
8154
|
+
repo: "client",
|
|
8155
|
+
rule: "general-npm-version",
|
|
8156
|
+
doc: "CLAUDE.md:54"
|
|
8157
|
+
}
|
|
8158
|
+
],
|
|
8159
|
+
options: { fullSha: {
|
|
8160
|
+
type: "boolean",
|
|
8161
|
+
default: true,
|
|
8162
|
+
description: "When false, a short SHA of 7 or more characters is also a commit."
|
|
8163
|
+
} },
|
|
8164
|
+
check(context, options) {
|
|
8165
|
+
const fullSha = options["fullSha"] !== false;
|
|
8166
|
+
const breaks = [];
|
|
8167
|
+
for (const info of [context.rootPackage, ...context.packages]) {
|
|
8168
|
+
const found = [];
|
|
8169
|
+
for (const field of DEPENDENCY_FIELDS) for (const [name, spec] of specifiersOf(info.manifest, field)) found.push([
|
|
8170
|
+
field,
|
|
8171
|
+
name,
|
|
8172
|
+
spec
|
|
8173
|
+
]);
|
|
8174
|
+
found.push(...overridesOf(info.manifest));
|
|
8175
|
+
for (const [field, name, spec] of found) {
|
|
8176
|
+
if (!isGitSpecifier(spec) || isPinned(spec, fullSha)) continue;
|
|
8177
|
+
const line = keyLine(info.text, field, name);
|
|
8178
|
+
breaks.push({
|
|
8179
|
+
file: info.file,
|
|
8180
|
+
...line === void 0 ? {} : { line },
|
|
8181
|
+
message: `${field} "${name}" is "${spec}": a git dependency without a ${fullSha ? "full " : ""}commit SHA.`
|
|
8182
|
+
});
|
|
8183
|
+
}
|
|
8184
|
+
}
|
|
8185
|
+
return breaks;
|
|
8186
|
+
}
|
|
8187
|
+
};
|
|
8188
|
+
// src/rules/release-files.ts
|
|
7733
8189
|
/**
|
|
7734
|
-
* The
|
|
7735
|
-
*
|
|
8190
|
+
* The rule `release-files`: a pull request changes a file of the release flow only with a reason
|
|
8191
|
+
* that everyone can see.
|
|
7736
8192
|
*/
|
|
7737
|
-
|
|
7738
|
-
|
|
7739
|
-
const
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
const
|
|
7744
|
-
const
|
|
7745
|
-
|
|
7746
|
-
|
|
7747
|
-
|
|
7748
|
-
};
|
|
8193
|
+
/** This function gives the pull request of the event file of GitHub Actions. With no event file, the body is empty. */
|
|
8194
|
+
function pullRequestOf(context) {
|
|
8195
|
+
const file = context.env["GITHUB_EVENT_PATH"];
|
|
8196
|
+
if (file === void 0 || file === "" || !existsSync(file)) return { body: "" };
|
|
8197
|
+
try {
|
|
8198
|
+
const event = JSON.parse(readFileSync(file, "utf8"));
|
|
8199
|
+
const body = typeof event.pull_request?.body === "string" ? event.pull_request.body : "";
|
|
8200
|
+
const commits = event.pull_request?.commits;
|
|
8201
|
+
return typeof commits === "number" ? {
|
|
8202
|
+
body,
|
|
8203
|
+
commits
|
|
8204
|
+
} : { body };
|
|
8205
|
+
} catch {
|
|
8206
|
+
return { body: "" };
|
|
7749
8207
|
}
|
|
7750
|
-
return null;
|
|
7751
8208
|
}
|
|
8209
|
+
/** This function escapes the special characters of a regular expression. */
|
|
8210
|
+
const escape = (text) => text.replace(/[\\^$.|?*+()[\]{}]/g, "\\$&");
|
|
8211
|
+
const releaseFiles = {
|
|
8212
|
+
id: "release-files",
|
|
8213
|
+
title: "A pull request changes `.github/workflows/release.yml` or `scripts/release/` only with a `Release-Edit: <reason>` line.",
|
|
8214
|
+
reason: "The release flow publishes to npm with trusted publishing. A change of its files by a session that does not own the release can stop or break each release.",
|
|
8215
|
+
fix: "Revert the change of the release files. When the owner asked for the change, add the line `Release-Edit: <reason>` to the last commit message or to the body of the pull request. A re-run of a job reads the body of the event that started the run, so after a change of the body, push a commit.",
|
|
8216
|
+
sources: [
|
|
8217
|
+
{
|
|
8218
|
+
repo: "coeval",
|
|
8219
|
+
rule: "no-release-edit",
|
|
8220
|
+
doc: "CLAUDE.md:40"
|
|
8221
|
+
},
|
|
8222
|
+
{
|
|
8223
|
+
repo: "coeval",
|
|
8224
|
+
rule: "no-release-edits",
|
|
8225
|
+
doc: "CLAUDE.md:40"
|
|
8226
|
+
},
|
|
8227
|
+
{
|
|
8228
|
+
repo: "crawler",
|
|
8229
|
+
rule: "no-release-edit",
|
|
8230
|
+
doc: "CLAUDE.md:80"
|
|
8231
|
+
},
|
|
8232
|
+
{
|
|
8233
|
+
repo: "crawler",
|
|
8234
|
+
rule: "no-release-edits",
|
|
8235
|
+
doc: "CLAUDE.md:80"
|
|
8236
|
+
},
|
|
8237
|
+
{
|
|
8238
|
+
repo: "headroom",
|
|
8239
|
+
rule: "no-release-edits",
|
|
8240
|
+
doc: "CLAUDE.md:37"
|
|
8241
|
+
},
|
|
8242
|
+
{
|
|
8243
|
+
repo: "headroom",
|
|
8244
|
+
rule: "release-files-frozen",
|
|
8245
|
+
doc: "CLAUDE.md:37"
|
|
8246
|
+
}
|
|
8247
|
+
],
|
|
8248
|
+
options: {
|
|
8249
|
+
paths: {
|
|
8250
|
+
type: "strings",
|
|
8251
|
+
default: [".github/workflows/release.yml", "scripts/release/**"],
|
|
8252
|
+
description: "The globs of the files that the release flow owns."
|
|
8253
|
+
},
|
|
8254
|
+
trailer: {
|
|
8255
|
+
type: "string",
|
|
8256
|
+
default: "Release-Edit",
|
|
8257
|
+
description: "The key of the line that gives the reason of a change."
|
|
8258
|
+
},
|
|
8259
|
+
authors: {
|
|
8260
|
+
type: "strings",
|
|
8261
|
+
default: ["mark1russell7-release-train[bot]"],
|
|
8262
|
+
description: "The authors of the release flow. A change of the release files in commits of only these authors (the sync of the template) needs no reason."
|
|
8263
|
+
}
|
|
8264
|
+
},
|
|
8265
|
+
check(context, options) {
|
|
8266
|
+
const range = rangeOf(context);
|
|
8267
|
+
if ("skipped" in range) return range;
|
|
8268
|
+
const globs = Array.isArray(options["paths"]) ? options["paths"] : [];
|
|
8269
|
+
const changed = (context.git([
|
|
8270
|
+
"diff",
|
|
8271
|
+
"--name-only",
|
|
8272
|
+
...range.diff
|
|
8273
|
+
]) ?? "").split(/\r?\n/).filter((file) => file !== "" && matchesAny(file, globs));
|
|
8274
|
+
if (changed.length === 0) return [];
|
|
8275
|
+
const trailer = typeof options["trailer"] === "string" ? options["trailer"] : "Release-Edit";
|
|
8276
|
+
const line = new RegExp(`^${escape(trailer)}:[ \\t]*\\S`, "im");
|
|
8277
|
+
const pullRequest = pullRequestOf(context);
|
|
8278
|
+
if (line.test(pullRequest.body)) return [];
|
|
8279
|
+
if (!(pullRequest.commits === 1 && context.git([
|
|
8280
|
+
"rev-parse",
|
|
8281
|
+
"--verify",
|
|
8282
|
+
"--quiet",
|
|
8283
|
+
`${range.ends[1]}^2`
|
|
8284
|
+
]) === void 0) && context.git(["merge-base", ...range.ends]) === void 0) throw new Error(`The checkout does not have the merge base of ${range.ends.join(" and ")}, so the rule cannot read each commit of the change. Use fetch-depth 0, or the CI of the template, which deepens the checkout of a pull request to its merge base.`);
|
|
8285
|
+
const messages = context.git([
|
|
8286
|
+
"log",
|
|
8287
|
+
"--no-merges",
|
|
8288
|
+
"--format=%B",
|
|
8289
|
+
...range.log
|
|
8290
|
+
]) ?? "";
|
|
8291
|
+
if (line.test(messages)) return [];
|
|
8292
|
+
const authors = new Set(Array.isArray(options["authors"]) ? options["authors"] : []);
|
|
8293
|
+
const changers = (context.git([
|
|
8294
|
+
"log",
|
|
8295
|
+
"--no-merges",
|
|
8296
|
+
"--format=%an",
|
|
8297
|
+
...range.log,
|
|
8298
|
+
"--",
|
|
8299
|
+
...changed
|
|
8300
|
+
]) ?? "").split(/\r?\n/).filter((name) => name !== "");
|
|
8301
|
+
if (changers.length > 0 && changers.every((name) => authors.has(name))) return [];
|
|
8302
|
+
return changed.map((file) => ({
|
|
8303
|
+
file,
|
|
8304
|
+
message: `The change edits ${file}, a file of the release flow, with no "${trailer}: <reason>" line.`
|
|
8305
|
+
}));
|
|
8306
|
+
}
|
|
8307
|
+
};
|
|
8308
|
+
// src/rules/required-scripts.ts
|
|
7752
8309
|
/**
|
|
7753
|
-
*
|
|
7754
|
-
* matches without case.
|
|
8310
|
+
* The rule `required-scripts`: the root `package.json` keeps the scripts that the shared CI starts.
|
|
7755
8311
|
*/
|
|
7756
|
-
|
|
7757
|
-
|
|
7758
|
-
|
|
7759
|
-
|
|
7760
|
-
|
|
7761
|
-
|
|
7762
|
-
|
|
7763
|
-
|
|
8312
|
+
/** The package of the STE linter. */
|
|
8313
|
+
const STE_LINT = "@mark1russell7/ste-lint";
|
|
8314
|
+
/** The configuration file of the STE linter. */
|
|
8315
|
+
const STE_CONFIG = "ste.config.json";
|
|
8316
|
+
/** The examples of the scripts that the fix shows. */
|
|
8317
|
+
const EXAMPLES = {
|
|
8318
|
+
"lint:ste": "ste-lint",
|
|
8319
|
+
typecheck: "pnpm -r run typecheck"
|
|
7764
8320
|
};
|
|
7765
8321
|
/**
|
|
7766
|
-
* This function
|
|
7767
|
-
*
|
|
7768
|
-
* the item gives the status, for example "Waiting on Mark", "Later" or "Shipped". A heading without
|
|
7769
|
-
* a status is not an item.
|
|
7770
|
-
*
|
|
7771
|
-
* The list items "Area:", "Owner:" and "Waits for:" give the optional fields. The list item
|
|
7772
|
-
* "Links:" and the other list items give the links. Fenced code is not read.
|
|
8322
|
+
* This function tells if the repository uses the STE prose standard: the root `package.json` has a
|
|
8323
|
+
* dependency on `@mark1russell7/ste-lint`, or the root has a `ste.config.json`.
|
|
7773
8324
|
*/
|
|
7774
|
-
function
|
|
7775
|
-
const
|
|
7776
|
-
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
8325
|
+
function usesSteLint(context) {
|
|
8326
|
+
const manifest = context.rootPackage.manifest;
|
|
8327
|
+
if (DEPENDENCY_FIELDS.some((field) => specifiersOf(manifest, field).some(([name]) => name === STE_LINT))) return true;
|
|
8328
|
+
return hasFile(context.root, STE_CONFIG);
|
|
8329
|
+
}
|
|
8330
|
+
const requiredScripts = {
|
|
8331
|
+
id: "required-scripts",
|
|
8332
|
+
title: "The root `package.json` has the script `typecheck`, and also `lint:ste` when the repository uses `ste-lint`.",
|
|
8333
|
+
reason: "The shared CI starts each script of its list that `package.json` has, and it skips the others. Thus a removed script turns its check off, and nothing shows it.",
|
|
8334
|
+
fix: "Add the script, for example `\"lint:ste\": \"ste-lint\"` or `\"typecheck\": \"pnpm -r run typecheck\"`.",
|
|
8335
|
+
sources: [
|
|
8336
|
+
{
|
|
8337
|
+
repo: "client",
|
|
8338
|
+
rule: "ste-prose",
|
|
8339
|
+
doc: "CLAUDE.md:5"
|
|
8340
|
+
},
|
|
8341
|
+
{
|
|
8342
|
+
repo: "coeval",
|
|
8343
|
+
rule: "ste-prose",
|
|
8344
|
+
doc: "CLAUDE.md:5"
|
|
8345
|
+
},
|
|
8346
|
+
{
|
|
8347
|
+
repo: "crawler",
|
|
8348
|
+
rule: "ste-prose",
|
|
8349
|
+
doc: "CLAUDE.md:5"
|
|
8350
|
+
},
|
|
8351
|
+
{
|
|
8352
|
+
repo: "Graph",
|
|
8353
|
+
rule: "ste-prose",
|
|
8354
|
+
doc: "CLAUDE.md:5"
|
|
8355
|
+
},
|
|
8356
|
+
{
|
|
8357
|
+
repo: "headroom",
|
|
8358
|
+
rule: "ste-prose",
|
|
8359
|
+
doc: "CLAUDE.md:19"
|
|
8360
|
+
},
|
|
8361
|
+
{
|
|
8362
|
+
repo: "systems",
|
|
8363
|
+
rule: "lint-ste-in-ci",
|
|
8364
|
+
doc: "CLAUDE.md:24"
|
|
8365
|
+
},
|
|
8366
|
+
{
|
|
8367
|
+
repo: "Vex",
|
|
8368
|
+
rule: "ste-prose",
|
|
8369
|
+
doc: "CLAUDE.md:5"
|
|
8370
|
+
},
|
|
8371
|
+
{
|
|
8372
|
+
repo: "coeval",
|
|
8373
|
+
rule: "tsconfig-test",
|
|
8374
|
+
doc: "CLAUDE.md:18"
|
|
8375
|
+
},
|
|
8376
|
+
{
|
|
8377
|
+
repo: "crawler",
|
|
8378
|
+
rule: "tsconfig-test",
|
|
8379
|
+
doc: "CLAUDE.md:18"
|
|
8380
|
+
},
|
|
8381
|
+
{
|
|
8382
|
+
repo: "headroom",
|
|
8383
|
+
rule: "tsconfig-test",
|
|
8384
|
+
doc: "CLAUDE.md:32"
|
|
8385
|
+
},
|
|
8386
|
+
{
|
|
8387
|
+
repo: "Vex",
|
|
8388
|
+
rule: "tsconfig-test",
|
|
8389
|
+
doc: "CLAUDE.md:23"
|
|
7811
8390
|
}
|
|
7812
|
-
|
|
7813
|
-
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
if (!isEmpty(value)) current[key] = value;
|
|
7824
|
-
} else if (/^\s*[-*]\s+/.test(line)) {
|
|
7825
|
-
const seen = new Set(current.links.map((link) => link.url));
|
|
7826
|
-
for (const link of linksOf(line, options)) if (!seen.has(link.url)) current.links.push(link);
|
|
8391
|
+
],
|
|
8392
|
+
options: {
|
|
8393
|
+
scripts: {
|
|
8394
|
+
type: "strings",
|
|
8395
|
+
default: ["typecheck"],
|
|
8396
|
+
description: "The scripts that the root `package.json` has."
|
|
8397
|
+
},
|
|
8398
|
+
steScripts: {
|
|
8399
|
+
type: "strings",
|
|
8400
|
+
default: ["lint:ste"],
|
|
8401
|
+
description: "The scripts that the root `package.json` has when the repository uses `ste-lint` (a dependency on `@mark1russell7/ste-lint`, or a `ste.config.json` at the root)."
|
|
7827
8402
|
}
|
|
7828
|
-
}
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
7838
|
-
|
|
7839
|
-
|
|
7840
|
-
|
|
7841
|
-
|
|
7842
|
-
|
|
7843
|
-
|
|
7844
|
-
const { file = "ROADMAP.md" } = options;
|
|
7845
|
-
const items = [];
|
|
7846
|
-
for (const table of markdownTables(markdown)) {
|
|
7847
|
-
const column = (...names) => names.map((name) => table.header.indexOf(name)).find((index) => index >= 0) ?? -1;
|
|
7848
|
-
const id = column("id");
|
|
7849
|
-
const status = column("status");
|
|
7850
|
-
if (id < 0 || status < 0) continue;
|
|
7851
|
-
const title = column("item", "title");
|
|
7852
|
-
const owner = column("owner");
|
|
7853
|
-
const area = column("area");
|
|
7854
|
-
const needs = column("needs");
|
|
7855
|
-
const linkColumns = LINK_COLUMNS.map((name) => table.header.indexOf(name)).filter((index) => index >= 0);
|
|
7856
|
-
for (const row of table.rows) {
|
|
7857
|
-
if (row.cells.length !== table.header.length) throw new RoadmapParseError(`${file}:${row.line}: the row has ${row.cells.length} cells, and the header has ${table.header.length}`);
|
|
7858
|
-
const idText = plainText(row.cells[id]);
|
|
7859
|
-
if (isEmpty(idText)) continue;
|
|
7860
|
-
const statusText = row.cells[status] ?? "";
|
|
7861
|
-
const item = {
|
|
7862
|
-
id: idText,
|
|
7863
|
-
title: title >= 0 ? row.cells[title] ?? "" : "",
|
|
7864
|
-
status: statusText,
|
|
7865
|
-
statusClass: statusClassOf(plainText(statusText)),
|
|
7866
|
-
section: table.section,
|
|
7867
|
-
line: row.line,
|
|
7868
|
-
links: linkColumns.flatMap((index) => linksOf(row.cells[index], {
|
|
7869
|
-
...options,
|
|
7870
|
-
file
|
|
7871
|
-
}))
|
|
8403
|
+
},
|
|
8404
|
+
check(context, options) {
|
|
8405
|
+
const always = Array.isArray(options["scripts"]) ? options["scripts"] : ["typecheck"];
|
|
8406
|
+
const ste = Array.isArray(options["steScripts"]) ? options["steScripts"] : ["lint:ste"];
|
|
8407
|
+
const wanted = [.../* @__PURE__ */ new Set([...always, ...usesSteLint(context) ? ste : []])];
|
|
8408
|
+
const value = context.rootPackage.manifest["scripts"];
|
|
8409
|
+
const scripts = typeof value === "object" && value !== null ? value : {};
|
|
8410
|
+
const line = lineOf(context.rootPackage.text, "\"scripts\"");
|
|
8411
|
+
return wanted.filter((name) => typeof scripts[name] !== "string" || scripts[name] === "").map((name) => {
|
|
8412
|
+
const example = EXAMPLES[name];
|
|
8413
|
+
const why = ste.includes(name) && !always.includes(name) ? " The repository uses ste-lint." : "";
|
|
8414
|
+
return {
|
|
8415
|
+
file: context.rootPackage.file,
|
|
8416
|
+
...line === void 0 ? {} : { line },
|
|
8417
|
+
message: `The root package.json has no script "${name}".${why}`,
|
|
8418
|
+
fix: example === void 0 ? `Add the script "${name}".` : `Add the script, for example "${name}": "${example}".`
|
|
7872
8419
|
};
|
|
7873
|
-
|
|
7874
|
-
const ownerText = optional(owner);
|
|
7875
|
-
const areaText = optional(area);
|
|
7876
|
-
const needsText = optional(needs);
|
|
7877
|
-
if (ownerText !== void 0) item.owner = ownerText;
|
|
7878
|
-
if (areaText !== void 0) item.area = areaText;
|
|
7879
|
-
if (needsText !== void 0) item.needs = needsText;
|
|
7880
|
-
items.push(item);
|
|
7881
|
-
}
|
|
8420
|
+
});
|
|
7882
8421
|
}
|
|
7883
|
-
|
|
7884
|
-
...options,
|
|
7885
|
-
file
|
|
7886
|
-
});
|
|
7887
|
-
return headings.length === 0 ? items : [...items, ...headings].sort((a, b) => a.line - b.line);
|
|
7888
|
-
}
|
|
7889
|
-
/**
|
|
7890
|
-
* This function gives the items of a roadmap file, as the Status page reads them. It fails when the file has no item.
|
|
7891
|
-
*
|
|
7892
|
-
* @throws RoadmapParseError when the cells of a row do not match the header
|
|
7893
|
-
* @throws RoadmapParseError when the roadmap has no item: no table with an ID and a Status column, and no item heading
|
|
7894
|
-
*/
|
|
7895
|
-
function parseRoadmap(markdown, options = {}) {
|
|
7896
|
-
const { file = "ROADMAP.md" } = options;
|
|
7897
|
-
const items = roadmapItems(markdown, options);
|
|
7898
|
-
if (items.length === 0) throw new RoadmapParseError(`${file}: no table with an ID column and a Status column, and no heading "### \`id\`: Title"`);
|
|
7899
|
-
return items;
|
|
7900
|
-
}
|
|
7901
|
-
String.raw`
|
|
7902
|
-
const boxes = Array.from(document.querySelectorAll("[data-sp-timeline]"));
|
|
7903
|
-
const panels = new Map(Array.from(document.querySelectorAll("[data-sp-release]"), (panel) => [panel.dataset.version, panel]));
|
|
7904
|
-
const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
7905
|
-
let selected = (document.querySelector("[data-sp-release]:not([hidden])") || {}).dataset?.version;
|
|
7906
|
-
const markIn = (box, version) => Array.from(box.querySelectorAll("[data-sp-mark]")).find((mark) => mark.dataset.version === version);
|
|
7907
|
-
function reveal(box, version, smooth) {
|
|
7908
|
-
const mark = markIn(box, version);
|
|
7909
|
-
if (!mark || box.scrollWidth <= box.clientWidth) return;
|
|
7910
|
-
const x = Number(mark.dataset.x);
|
|
7911
|
-
const margin = Number(mark.dataset.half) + 16;
|
|
7912
|
-
if (x - margin >= box.scrollLeft && x + margin <= box.scrollLeft + box.clientWidth) return;
|
|
7913
|
-
box.scrollTo({ left: x - box.clientWidth / 2, behavior: smooth && !reduced ? "smooth" : "auto" });
|
|
7914
|
-
}
|
|
7915
|
-
function select(version, box) {
|
|
7916
|
-
const panel = panels.get(version);
|
|
7917
|
-
if (!panel) return;
|
|
7918
|
-
selected = version;
|
|
7919
|
-
for (const each of boxes) {
|
|
7920
|
-
for (const mark of each.querySelectorAll("[data-sp-mark]")) {
|
|
7921
|
-
const on = mark.dataset.version === version;
|
|
7922
|
-
mark.classList.toggle("sp-selected", on);
|
|
7923
|
-
mark.setAttribute("aria-pressed", String(on));
|
|
7924
|
-
mark.setAttribute("tabindex", on ? "0" : "-1");
|
|
7925
|
-
}
|
|
7926
|
-
}
|
|
7927
|
-
for (const [key, each] of panels) each.hidden = key !== version;
|
|
7928
|
-
if (box) {
|
|
7929
|
-
const mark = markIn(box, version);
|
|
7930
|
-
if (mark) mark.focus({ preventScroll: true });
|
|
7931
|
-
reveal(box, version, true);
|
|
7932
|
-
}
|
|
7933
|
-
try {
|
|
7934
|
-
history.replaceState(null, "", "#" + encodeURIComponent(panel.id));
|
|
7935
|
-
} catch {}
|
|
7936
|
-
}
|
|
7937
|
-
for (const box of boxes) {
|
|
7938
|
-
box.addEventListener("click", (event) => {
|
|
7939
|
-
const mark = event.target.closest("[data-sp-mark]");
|
|
7940
|
-
if (mark) select(mark.dataset.version, box);
|
|
7941
|
-
});
|
|
7942
|
-
box.addEventListener("keydown", (event) => {
|
|
7943
|
-
const mark = event.target.closest("[data-sp-mark]");
|
|
7944
|
-
if (!mark || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
7945
|
-
const marks = Array.from(box.querySelectorAll("[data-sp-mark]"));
|
|
7946
|
-
const position = marks.indexOf(mark);
|
|
7947
|
-
const targets = { ArrowLeft: position - 1, ArrowRight: position + 1, Home: 0, End: marks.length - 1, Enter: position, " ": position };
|
|
7948
|
-
if (!(event.key in targets)) return;
|
|
7949
|
-
event.preventDefault();
|
|
7950
|
-
const next = marks[Math.max(0, Math.min(marks.length - 1, targets[event.key]))];
|
|
7951
|
-
if (next) select(next.dataset.version, box);
|
|
7952
|
-
});
|
|
7953
|
-
}
|
|
7954
|
-
document.addEventListener("click", (event) => {
|
|
7955
|
-
const button = event.target.closest("[data-sp-toggle]");
|
|
7956
|
-
const list = button && document.getElementById(button.getAttribute("aria-controls"));
|
|
7957
|
-
if (!list) return;
|
|
7958
|
-
const open = button.getAttribute("aria-expanded") !== "true";
|
|
7959
|
-
for (const extra of list.querySelectorAll(":scope > .sp-extra")) extra.hidden = !open;
|
|
7960
|
-
button.setAttribute("aria-expanded", String(open));
|
|
7961
|
-
const label = button.querySelector("[data-sp-label]");
|
|
7962
|
-
if (label) label.textContent = open ? button.dataset.less : button.dataset.more;
|
|
7963
|
-
});
|
|
7964
|
-
// A malformed hash, for example "#100%", must not stop the module
|
|
7965
|
-
let hashed = "";
|
|
7966
|
-
try {
|
|
7967
|
-
hashed = decodeURIComponent(location.hash.slice(1));
|
|
7968
|
-
} catch {}
|
|
7969
|
-
for (const [version, panel] of panels) if (panel.id === hashed) select(version, null);
|
|
7970
|
-
const revealAll = () => { for (const box of boxes) reveal(box, selected, false); };
|
|
7971
|
-
revealAll();
|
|
7972
|
-
window.addEventListener("resize", revealAll);
|
|
7973
|
-
`;
|
|
7974
|
-
String.raw`
|
|
7975
|
-
function relativeTime(then, now) {
|
|
7976
|
-
const seconds = Math.round((now - then) / 1000);
|
|
7977
|
-
if (!Number.isFinite(seconds)) return "at an unknown time";
|
|
7978
|
-
if (seconds < 60) return "just now";
|
|
7979
|
-
const steps = [[60, "minute"], [3600, "hour"], [86400, "day"], [2592000, "month"], [31536000, "year"]];
|
|
7980
|
-
let unit = steps[0];
|
|
7981
|
-
for (const step of steps) if (seconds >= step[0]) unit = step;
|
|
7982
|
-
const count = Math.floor(seconds / unit[0]);
|
|
7983
|
-
return count + " " + unit[1] + (count === 1 ? "" : "s") + " ago";
|
|
7984
|
-
}
|
|
7985
|
-
function listOf(text) {
|
|
7986
|
-
return (text || "").split(",").filter((part) => part !== "");
|
|
7987
|
-
}
|
|
7988
|
-
` + String.raw`
|
|
7989
|
-
const now = Date.now();
|
|
7990
|
-
for (const time of document.querySelectorAll("time[data-sp-rel]")) {
|
|
7991
|
-
time.textContent = relativeTime(Date.parse(time.dateTime), now) + " (" + time.title + ")";
|
|
7992
|
-
}
|
|
7993
|
-
const board = document.querySelector("[data-sp-board]");
|
|
7994
|
-
if (board) {
|
|
7995
|
-
const classChips = Array.from(board.querySelectorAll("[data-sp-class]"));
|
|
7996
|
-
const sectionChips = Array.from(board.querySelectorAll("[data-sp-section]"));
|
|
7997
|
-
const groups = Array.from(board.querySelectorAll("[data-sp-group]"));
|
|
7998
|
-
const shown = board.querySelector("[data-sp-shown]");
|
|
7999
|
-
const empty = board.querySelector("[data-sp-empty]");
|
|
8000
|
-
const clear = board.querySelector("[data-sp-clear]");
|
|
8001
|
-
const done = board.querySelector("[data-sp-done]");
|
|
8002
|
-
const query = new URLSearchParams(location.search);
|
|
8003
|
-
const state = {
|
|
8004
|
-
classes: listOf(query.get("status")).filter((value) => classChips.some((chip) => chip.dataset.spClass === value)),
|
|
8005
|
-
sections: listOf(query.get("section")),
|
|
8006
|
-
};
|
|
8007
|
-
if (done && query.get("done") === "1") done.open = true;
|
|
8008
|
-
const apply = (write) => {
|
|
8009
|
-
for (const chip of classChips) chip.setAttribute("aria-pressed", String(state.classes.includes(chip.dataset.spClass)));
|
|
8010
|
-
for (const chip of sectionChips) chip.setAttribute("aria-pressed", String(state.sections.includes(chip.dataset.spSection)));
|
|
8011
|
-
let count = 0;
|
|
8012
|
-
for (const group of groups) {
|
|
8013
|
-
const isDone = group.dataset.class === "done";
|
|
8014
|
-
const classOn = isDone || state.classes.length === 0 || state.classes.includes(group.dataset.class);
|
|
8015
|
-
let visible = 0;
|
|
8016
|
-
for (const row of group.querySelectorAll("tr[data-section]")) {
|
|
8017
|
-
const on = classOn && (state.sections.length === 0 || state.sections.includes(row.dataset.section));
|
|
8018
|
-
row.hidden = !on;
|
|
8019
|
-
if (on) visible++;
|
|
8020
|
-
}
|
|
8021
|
-
if (isDone) {
|
|
8022
|
-
const none = group.querySelector("[data-sp-done-empty]");
|
|
8023
|
-
if (none) none.hidden = visible > 0;
|
|
8024
|
-
} else {
|
|
8025
|
-
group.hidden = visible === 0;
|
|
8026
|
-
const badge = group.querySelector("[data-sp-group-count]");
|
|
8027
|
-
if (badge) badge.textContent = String(visible);
|
|
8028
|
-
count += visible;
|
|
8029
|
-
}
|
|
8030
|
-
}
|
|
8031
|
-
if (shown) shown.textContent = count + " of " + shown.dataset.label;
|
|
8032
|
-
if (empty) empty.hidden = count > 0;
|
|
8033
|
-
if (clear) clear.hidden = state.classes.length === 0 && state.sections.length === 0;
|
|
8034
|
-
if (done) {
|
|
8035
|
-
const label = done.querySelector("[data-sp-done-label]");
|
|
8036
|
-
if (label) label.textContent = done.open ? "Hide the done items" : "Show the done items";
|
|
8037
|
-
}
|
|
8038
|
-
if (!write) return;
|
|
8039
|
-
const next = new URLSearchParams(location.search);
|
|
8040
|
-
const put = (key, value) => (value ? next.set(key, value) : next.delete(key));
|
|
8041
|
-
put("status", state.classes.join(","));
|
|
8042
|
-
put("section", state.sections.join(","));
|
|
8043
|
-
put("done", done && done.open ? "1" : "");
|
|
8044
|
-
const search = next.toString();
|
|
8045
|
-
try {
|
|
8046
|
-
history.replaceState(null, "", location.pathname + (search ? "?" + search : "") + location.hash);
|
|
8047
|
-
} catch {}
|
|
8048
|
-
};
|
|
8049
|
-
const toggle = (list, value) => (list.includes(value) ? list.filter((each) => each !== value) : list.concat(value));
|
|
8050
|
-
board.addEventListener("click", (event) => {
|
|
8051
|
-
const chip = event.target.closest("button");
|
|
8052
|
-
if (!chip) return;
|
|
8053
|
-
if (chip.dataset.spClass) state.classes = toggle(state.classes, chip.dataset.spClass);
|
|
8054
|
-
else if (chip.dataset.spSection) state.sections = toggle(state.sections, chip.dataset.spSection);
|
|
8055
|
-
else if (chip.hasAttribute("data-sp-clear")) {
|
|
8056
|
-
state.classes = [];
|
|
8057
|
-
state.sections = [];
|
|
8058
|
-
} else return;
|
|
8059
|
-
apply(true);
|
|
8060
|
-
});
|
|
8061
|
-
if (done) done.addEventListener("toggle", () => apply(true));
|
|
8062
|
-
apply(false);
|
|
8063
|
-
}
|
|
8064
|
-
`;
|
|
8422
|
+
};
|
|
8065
8423
|
// src/rules/roadmap-parses.ts
|
|
8066
8424
|
/**
|
|
8067
8425
|
* The rule `roadmap-parses`: each roadmap that a workflow gives to the Status page parses, on the pull request.
|
|
@@ -10028,6 +10386,7 @@ const RULES = [
|
|
|
10028
10386
|
noLocalPaths,
|
|
10029
10387
|
releaseFiles,
|
|
10030
10388
|
unreleasedChange,
|
|
10389
|
+
changelogVersion,
|
|
10031
10390
|
typedScripts,
|
|
10032
10391
|
typedFiles,
|
|
10033
10392
|
mainCheck,
|
|
@@ -10434,6 +10793,6 @@ function runMap(args, io) {
|
|
|
10434
10793
|
else io.stdout(mapText(found));
|
|
10435
10794
|
return 0;
|
|
10436
10795
|
}
|
|
10437
|
-
export { REAL_COMPARE as $, pathsOf as A,
|
|
10796
|
+
export { REAL_COMPARE as $, pathsOf as A, cleanPath as At, roadmapParses as B, runGit as Bt, configsOfScript as C, gateTrigger as Ct, hasTests as D, STRICT_OPTIONS as Dt, testsRequired as E, readWorkflow as Et, sharedDocsRule as F, lineOf as Ft, pinnedGitDeps as G, workspaceGlobs as Gt, releaseFiles as H, globFolders as Ht, repositoryOfRemote as I, matchesAny as It, pagesSite as J, PAGES_WORKFLOWS as K, defaultOptions as Kt, runnerBudget as L, parseJsonc as Lt, HOME_TIMEOUT_MS as M, hasFile as Mt, blockHash as N, inFolder as Nt, tsconfigTest as O, cuePreset as Ot, githubFetch as P, keyLine as Pt, noBuildOutput as Q, scheduleMinute as R, readJsonc as Rt, typedScripts as S, convertGate as St, typedFiles as T, summaryName as Tt, isGitSpecifier as U, globToRegExp as Ut, requiredScripts as V, specifiersOf as Vt, isPinned as W, packageFolders as Wt, HOME_PATTERNS as X, DEFAULT_ALLOWED as Y, noLocalPaths as Z, unreleasedChange as _, mapText as _t, listRules as a, licenseFileOf as at, TRAIN_SCOPES as b, HOME_EXPORTS as bt, runCli as c, declaredName as ct, RULES as d, repoOf as dt, hasImportMetaMain as et, workspaceProtocol as f, signaturesOf as ft, npmLookup as g, mapMarkdown as gt, UNSHIPPED_FILES as h, findHomes as ht, formatResult as i, licenseFile as it, sourceMain as j, codePackages as jt, isSourcePath as k, DEPENDENCY_FIELDS as kt, runFix as l, homePackage as lt, SHIPPED_FIELDS as m, MAP_RULE as mt, annotations as n, LICENSE_TEXTS as nt, readConfig as o, mitText as ot, NPM_REGISTRY as p, HOMES as pt, pagesCalls as q, parseConfig as qt, createContext as r, authorOf as rt, runChecks as s, repositoryIsPublic as st, USAGE as t, mainCheck as tt, summaryMarkdown as u, messageOf as ut, unreleasedChangeRule as v, mergeHomes as vt, scriptsOf as w, prPathFilters as wt, trustPolicy as x, ACTIONS_COMMIT as xt, IGNORE_AFTER as y, readOverlay as yt, roadmapOfLine as z, replaceLine as zt };
|
|
10438
10797
|
|
|
10439
|
-
//# sourceMappingURL=run-
|
|
10798
|
+
//# sourceMappingURL=run-sEUuSlqi.js.map
|