@mark1russell7/conventions 0.8.2 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,6 +25,7 @@ Each break shows the file, the line, the rule and the fix. In GitHub Actions, th
25
25
  - `runner-budget`: the minute of a schedule, a `max-parallel` of a matrix, and a concurrency group at the top of a workflow. A new run of a pull request stops the old run. A run of another event waits for the old run.
26
26
  - `tests-required`: the option `passWithNoTests` in a config or a script, in a package with test files. A package with no tests needs a person, who removes its test script.
27
27
  - `typed-files`: a config file at the root of a package (`vitest.config.ts`). The fix adds `*.config.ts` and `rootDir: "."` to the `tsconfig.test.json` of the package, when that file has no comments.
28
+ - `trust-policy`: the settings `trustPolicy`, `trustPolicyIgnoreAfter` and `trustPolicyExclude` of `pnpm-workspace.yaml`. The fix makes the file when the repository has none.
28
29
 
29
30
  The text output marks each break that has a fix. In the JSON output, such a break has `fixable: true`. The release train starts `conventions fix` in its update pull requests. Thus a break that a script can fix does not block a repository.
30
31
 
@@ -36,6 +37,7 @@ The rules come from the invariants audit of 2026-10-26 (strategy item s38). The
36
37
  |---|---|---|
37
38
  | `pinned-git-deps` | A dependency from git (`github:`, `git+https:`, `owner/repo`) names a full commit SHA. The rule also examines `overrides`, `resolutions` and `pnpm.overrides`. | coeval `pinned-deps`, `unpublished-dep-pinned`. headroom `non-npm-deps-pinned`, `pinned-github-specifier`. Graph `github-dep-full-sha`, `github-dep-pinned`. client `general-npm-version`. |
38
39
  | `workspace-protocol` | A dependency on a package of the workspace uses `workspace:`. The rule does not examine peer dependencies. | client `workspace-protocol`, `workspace-deps`. coeval `pinned-deps`. headroom `non-npm-deps-pinned`. crawler `mcp-workspace-dep`. |
40
+ | `trust-policy` | A repository with a `pnpm-lock.yaml` sets `trustPolicy: no-downgrade` in `pnpm-workspace.yaml`: pnpm refuses a version with less trust evidence than an earlier version, for example one with no provenance after versions from a trusted publisher. `trustPolicyIgnoreAfter` is 10080 or more, so the check examines the versions of the last 7 days. A stolen-token version is new, and older versions can have less evidence for other reasons. `trustPolicyExclude` has the scopes of the release train, which checks the provenance of their versions itself. | fleet `trust-policy` (STRATEGY.md, 2026-11-01). |
39
41
  | `source-main` | The `main` of each workspace package is `src/index.ts` (a package with only a `bin` has no `main`, and a private package with no entry is an app). A public package that has a source entry has the same field in `publishConfig`, and that field points at the build. | coeval `package-main-source`, `source-package-main`. crawler `pkg-source-main`, `source-package-main`, `publish-config-build`. Graph `new-package-main-index`, `source-package-main`. headroom `source-package-main`. |
40
42
  | `tsconfig-test` | Each package with a `tsconfig.json` has a `tsconfig.test.json`, and its `typecheck` script names it. | coeval, crawler, Vex `package-tsconfig-test` or `pkg-tsconfig-test`, and `tsconfig-test`. headroom `tsconfig-test`, `tsconfig-test-per-package`. |
41
43
  | `cue-preset` | The `tsconfig.json` of each package extends a preset of `@mark1russell7/cue`. No config of a package turns off a strict option that its preset turns on. | client `cue-config`, `no-manual-tsconfig`. Graph `cue-preset-strict`, `strict-preset`, `new-package-via-cli`. coeval, crawler, headroom, Vex `package-scaffold`. |
@@ -98,6 +100,8 @@ An unknown rule, an unknown option, or an exception or a changed option without
98
100
  | `typed-scripts.shellLines` | `1` | The most lines of code of a shell script (a launcher). Empty lines and comments do not count. |
99
101
  | `typed-files.configs` | `[]` | More tsconfig files, relative to the root, that CI examines with another command (for example a script that the typecheck starts). |
100
102
  | `roadmap-parses.roadmaps` | `[]` | More roadmap files, relative to the root, for a roadmap that no workflow names. |
103
+ | `trust-policy.exclude` | `["@mark1russell7/*", "@procedures/*"]` | The patterns that `trustPolicyExclude` must have. |
104
+ | `trust-policy.ignoreAfter` | `10080` | The smallest `trustPolicyIgnoreAfter`, in minutes. |
101
105
  | `runner-budget.maxParallel` | `3` | The largest `max-parallel` of a matrix. |
102
106
  | `runner-budget.minute` | `true` | When `false`, the rule does not examine the minute of the schedules. |
103
107
  | `runner-budget.grouped` | `["reusable-ai-review.yml", "reusable-codex-review.yml"]` | The shared workflows that give a concurrency group in each of their jobs. |
package/build/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { c as runCli } from "./run-DD72yQn7.js";
2
+ import { c as runCli } from "./run-CRjXzR_6.js";
3
3
  // src/cli.ts
4
4
  try {
5
5
  process.exitCode = runCli(process.argv.slice(2), {
package/build/index.d.ts CHANGED
@@ -23,7 +23,7 @@ interface Break {
23
23
  interface Edit {
24
24
  /** The file, relative to the root, with `/`. */
25
25
  readonly file: string;
26
- /** The whole text of the file before the change. */
26
+ /** The whole text of the file before the change. An empty text makes a file that does not exist. */
27
27
  readonly before: string;
28
28
  /** The whole text of the file after the change. */
29
29
  readonly after: string;
@@ -198,6 +198,11 @@ export declare function configsOfScript(script: string): string[];
198
198
  export declare function scriptsOf(scripts: Readonly<Record<string, unknown>>, name: string, seen?: Set<string>): string[];
199
199
  export declare const typedFiles: Rule;
200
200
  export declare const typedScripts: Rule;
201
+ /** The scopes that the release train updates. The train checks the provenance of their versions itself. */
202
+ export declare const TRAIN_SCOPES: readonly ["@mark1russell7/*", "@procedures/*"];
203
+ /** 7 days, in minutes. */
204
+ export declare const IGNORE_AFTER = 10080;
205
+ export declare const trustPolicy: Rule;
201
206
  export declare const workspaceProtocol: Rule;
202
207
  /** Each rule of the check. */
203
208
  export declare const RULES: readonly Rule[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/rule.ts","../src/config.ts","../src/rules/cue-preset.ts","../src/rules/no-build-output.ts","../src/rules/no-local-paths.ts","../src/rules/pinned-git-deps.ts","../src/rules/release-files.ts","../src/rules/required-scripts.ts","../src/rules/roadmap-parses.ts","../src/rules/runner-budget.ts","../src/rules/source-main.ts","../src/rules/tests-required.ts","../src/rules/tsconfig-test.ts","../src/rules/typed-files.ts","../src/rules/typed-scripts.ts","../src/rules/workspace-protocol.ts","../src/rules/index.ts","../src/run.ts","../src/workspace.ts"],"mappings":";UASiB;WACN;WACA;WACA;;;UA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,SAAS,0BAA0B;qBAKtC,cAAc;;wBCiCX,gBAAgB;;;;;wBA4BhB,UAAU,SAAS,SAAS,0BAA0B,cAAc,OAAM;qBAgG7E,YAAY;qBCjJZ,cAAc;qBC9Bd,mBAAmB;;qBCYnB,gBAAgB;;UCRZ;WACN;WACA;WACA;;WAEA;WACA,iBAAiB;;WAEjB;;WAEA;;;UAIM;WACN,gBAAgB;;WAEhB;;;UAIM;;WAEN;;WAEA;;WAEA;WACA,MAAM,SAAS;;WAEf,iBAAiB;;;wBAaZ,WAAW,cAAc,iBAAgB,SAAiB;;wBAO1D,cAAc,cAAc,QAAQ,mBAAmB,UAAS,KAAK,gCAAqC;;wBAwB1G,UAAU,SAAS,eAAe;;UAoCjC;;WAEN;;WAEA;;WAEA,QAAQ;;;;;;;wBAWH,OAAO,SAAS,eAAe;;wBAuC/B,aAAa,QAAQ;;wBA0BrB,gBAAgB,QAAQ;;wBAsBxB,YAAY,QAAQ;;wBAYpB,UAAU,QAAQ,+BAA+B,iBAAgB;;UAkBhE;WACN;WACA,KAAK,SAAS;WACd,SAAS;WACT,SAAS;;;qBAIP;;wBA0BG,OAAO,yBAAyB,IAAI;;;;;;wBC5QpC,aAAa,eAAe;;;;;wBAsD5B,YAAY,cAAc;;;;;;wBA8B1B,eAAe;;;;;;;wBAwCf,eAAe,cAAc"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/rule.ts","../src/config.ts","../src/rules/cue-preset.ts","../src/rules/no-build-output.ts","../src/rules/no-local-paths.ts","../src/rules/pinned-git-deps.ts","../src/rules/release-files.ts","../src/rules/required-scripts.ts","../src/rules/roadmap-parses.ts","../src/rules/runner-budget.ts","../src/rules/source-main.ts","../src/rules/tests-required.ts","../src/rules/tsconfig-test.ts","../src/rules/typed-files.ts","../src/rules/typed-scripts.ts","../src/rules/trust-policy.ts","../src/rules/workspace-protocol.ts","../src/rules/index.ts","../src/run.ts","../src/workspace.ts"],"mappings":";UASiB;WACN;WACA;WACA;;;UAI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SAAS,0BAA0B;qBAKtC,cAAc;;wBCiCX,gBAAgB;;;;;wBA4BhB,UAAU,SAAS,SAAS,0BAA0B,cAAc,OAAM;qBAgG7E,YAAY;qBCjJZ,cAAc;;qBC3Bd;;qBAGA;qBA6DA,aAAa;qBCnEb,mBAAmB;;qBCanB,gBAAgB;;UCTZ;WACN;WACA;WACA;;WAEA;WACA,iBAAiB;;WAEjB;;WAEA;;;UAIM;WACN,gBAAgB;;WAEhB;;;UAIM;;WAEN;;WAEA;;WAEA;WACA,MAAM,SAAS;;WAEf,iBAAiB;;;wBAaZ,WAAW,cAAc,iBAAgB,SAAiB;;wBAO1D,cAAc,cAAc,QAAQ,mBAAmB,UAAS,KAAK,gCAAqC;;wBAwB1G,UAAU,SAAS,eAAe;;UAoCjC;;WAEN;;WAEA;;WAEA,QAAQ;;;;;;;wBAWH,OAAO,SAAS,eAAe;;wBAyC/B,aAAa,QAAQ;;wBA0BrB,gBAAgB,QAAQ;;wBAsBxB,YAAY,QAAQ;;wBAYpB,UAAU,QAAQ,+BAA+B,iBAAgB;;UAkBhE;WACN;WACA,KAAK,SAAS;WACd,SAAS;WACT,SAAS;;;qBAIP;;wBA0BG,OAAO,yBAAyB,IAAI;;;;;;wBC9QpC,aAAa,eAAe;;;;;wBAsD5B,YAAY,cAAc;;;;;;wBA8B1B,eAAe;;;;;;;wBAwCf,eAAe,cAAc"}
package/build/index.js CHANGED
@@ -1 +1 @@
1
- export { N as DEFAULT_ALLOWED, z as DEPENDENCY_FIELDS, P as HOME_PATTERNS, d as RULES, L as STRICT_OPTIONS, t as USAGE, n as annotations, B as cleanPath, V as codePackages, m as configsOfScript, r as createContext, R as cuePreset, nt as defaultOptions, i as formatResult, Q as globFolders, $ as globToRegExp, H as hasFile, v as hasTests, U as inFolder, A as isGitSpecifier, j as isPinned, b as isSourcePath, W as keyLine, G as lineOf, a as listRules, K as matchesAny, I as noBuildOutput, F as noLocalPaths, et as packageFolders, rt as parseConfig, q as parseJsonc, x as pathsOf, M as pinnedGitDeps, o as readConfig, J as readJsonc, k as releaseFiles, Y as replaceLine, C as repositoryOfRemote, O as requiredScripts, E as roadmapOfLine, D as roadmapParses, s as runChecks, c as runCli, l as runFix, X as runGit, w as runnerBudget, T as scheduleMinute, h as scriptsOf, S as sourceMain, Z as specifiersOf, u as summaryMarkdown, _ as testsRequired, y as tsconfigTest, g as typedFiles, p as typedScripts, tt as workspaceGlobs, f as workspaceProtocol } from "./run-DD72yQn7.js";
1
+ export { I as DEFAULT_ALLOWED, H as DEPENDENCY_FIELDS, L as HOME_PATTERNS, p as IGNORE_AFTER, d as RULES, B as STRICT_OPTIONS, m as TRAIN_SCOPES, t as USAGE, n as annotations, U as cleanPath, W as codePackages, _ as configsOfScript, r as createContext, V as cuePreset, at as defaultOptions, i as formatResult, tt as globFolders, nt as globToRegExp, G as hasFile, x as hasTests, K as inFolder, N as isGitSpecifier, P as isPinned, C as isSourcePath, q as keyLine, J as lineOf, a as listRules, Y as matchesAny, z as noBuildOutput, R as noLocalPaths, rt as packageFolders, ot as parseConfig, X as parseJsonc, w as pathsOf, F as pinnedGitDeps, o as readConfig, Z as readJsonc, M as releaseFiles, Q as replaceLine, E as repositoryOfRemote, j as requiredScripts, k as roadmapOfLine, A as roadmapParses, s as runChecks, c as runCli, l as runFix, $ as runGit, D as runnerBudget, O as scheduleMinute, v as scriptsOf, T as sourceMain, et as specifiersOf, u as summaryMarkdown, b as testsRequired, h as trustPolicy, S as tsconfigTest, y as typedFiles, g as typedScripts, it as workspaceGlobs, f as workspaceProtocol } from "./run-CRjXzR_6.js";
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { spawnSync } from "node:child_process";
3
- import { appendFileSync, existsSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
3
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
4
4
  import { basename, dirname, extname, join, posix, relative, resolve, sep } from "node:path";
5
5
  // src/config.ts
6
6
  /** The fields of the configuration of a rule that are not options. */
@@ -1757,7 +1757,7 @@ const roadmapParses = {
1757
1757
  const WORKFLOW = /^\.github\/workflows\/[^/]+\.ya?ml$/;
1758
1758
  const indentOf = (line) => line.length - line.trimStart().length;
1759
1759
  /** This function removes a comment at the end of a value, and the quotes around it. */
1760
- function valueOf(raw) {
1760
+ function valueOf$1(raw) {
1761
1761
  const comment = raw.indexOf(" #");
1762
1762
  let value = (comment >= 0 ? raw.slice(0, comment) : raw).trim();
1763
1763
  const quote = value.charAt(0);
@@ -1769,7 +1769,7 @@ function keyValue(line, key) {
1769
1769
  let text = line.trimStart();
1770
1770
  if (text.startsWith("- ")) text = text.slice(2).trimStart();
1771
1771
  if (!text.startsWith(`${key}:`)) return void 0;
1772
- return valueOf(text.slice(key.length + 1));
1772
+ return valueOf$1(text.slice(key.length + 1));
1773
1773
  }
1774
1774
  /** This function gives the lines of the block under the line `index`: the next lines with a larger indent. */
1775
1775
  function blockEnd(lines, index) {
@@ -2745,6 +2745,150 @@ const typedScripts = {
2745
2745
  return breaks;
2746
2746
  }
2747
2747
  };
2748
+ // src/rules/trust-policy.ts
2749
+ /**
2750
+ * The rule `trust-policy`: a pnpm repository sets `trustPolicy: no-downgrade` in `pnpm-workspace.yaml`. It checks each
2751
+ * version for 7 days after its publish (`trustPolicyIgnoreAfter`). It excludes the scopes of the release train.
2752
+ */
2753
+ const WORKSPACE = "pnpm-workspace.yaml";
2754
+ /** The scopes that the release train updates. The train checks the provenance of their versions itself. */
2755
+ const TRAIN_SCOPES = ["@mark1russell7/*", "@procedures/*"];
2756
+ /** 7 days, in minutes. */
2757
+ const IGNORE_AFTER = 10080;
2758
+ const POLICY_COMMENT = ["# An install fails when a new version has less trust evidence than an earlier version of the same package: for", "# example, a version with no provenance after versions from a trusted publisher. Such a version can be a stolen token."];
2759
+ const IGNORE_COMMENT = ["# The check examines the versions of the last 7 days. A stolen-token version is new, and the registry removes it in", "# hours. Older versions can have less evidence for other reasons: for example undici-types 6.21.0 under @types/node."];
2760
+ const EXCLUDE_COMMENT = ["# The release train updates our own scopes, and it checks the provenance of each version. pnpm cannot use them: it", "# ranks the first versions, which were staged by hand, above the versions from release.yml (pnpm/pnpm#16689)."];
2761
+ /** A top-level key of the file: its line index, and its value without a comment or quotes. */
2762
+ function valueOf(lines, key) {
2763
+ const index = lines.findIndex((line) => line.startsWith(`${key}:`));
2764
+ if (index < 0) return void 0;
2765
+ return {
2766
+ index,
2767
+ value: (lines[index] ?? "").slice(key.length + 1).replace(/\s+#.*$/, "").trim().replace(/^["']|["']$/g, "")
2768
+ };
2769
+ }
2770
+ /** This function gives the items of the block list under the line `start`, the index of its last item, and its indent. */
2771
+ function blockList(lines, start) {
2772
+ const items = [];
2773
+ let last = start;
2774
+ let indent = " ";
2775
+ for (let index = start + 1; index < lines.length; index++) {
2776
+ const line = lines[index] ?? "";
2777
+ const text = line.trim();
2778
+ if (text === "" || text.startsWith("#")) continue;
2779
+ if (!text.startsWith("- ") || line === line.trimStart()) break;
2780
+ indent = line.slice(0, line.length - line.trimStart().length);
2781
+ items.push(text.slice(2).replace(/\s+#.*$/, "").trim().replace(/^["']|["']$/g, ""));
2782
+ last = index;
2783
+ }
2784
+ return {
2785
+ items,
2786
+ last,
2787
+ indent
2788
+ };
2789
+ }
2790
+ /** This function gives the text with the lines `added` after the line `after` (-1: at the end), with the line ends of the text. */
2791
+ function insert(text, after, added) {
2792
+ const eol = text.includes("\r\n") ? "\r\n" : "\n";
2793
+ const lines = text.split(/\r?\n/);
2794
+ if (after >= 0) {
2795
+ lines.splice(after + 1, 0, ...added);
2796
+ return lines.join(eol);
2797
+ }
2798
+ while (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
2799
+ return [
2800
+ ...lines,
2801
+ ...lines.length > 0 ? [""] : [],
2802
+ ...added,
2803
+ ""
2804
+ ].join(eol);
2805
+ }
2806
+ /** This function gives the text with the value of the top-level key on the line `index` replaced. */
2807
+ function setValue(text, index, key, value) {
2808
+ const eol = text.includes("\r\n") ? "\r\n" : "\n";
2809
+ const lines = text.split(/\r?\n/);
2810
+ lines[index] = `${key}: ${value}`;
2811
+ return lines.join(eol);
2812
+ }
2813
+ const trustPolicy = {
2814
+ id: "trust-policy",
2815
+ title: "A pnpm repository sets `trustPolicy: no-downgrade` for the versions of the last 7 days, and excludes the scopes of the release train.",
2816
+ reason: "A stolen npm token can publish a version with no provenance, and the next install takes it. With `no-downgrade`, pnpm refuses a version with less trust evidence than an earlier version. The release age of pnpm keeps out the versions of the last day; this check covers the next days. The release train updates our own scopes at once and checks their provenance itself.",
2817
+ fix: "Add `trustPolicy: no-downgrade`, `trustPolicyIgnoreAfter: 10080` and a `trustPolicyExclude` with the scopes of the option `exclude` to `pnpm-workspace.yaml`. `conventions fix` writes them.",
2818
+ sources: [{
2819
+ repo: "fleet",
2820
+ rule: "trust-policy",
2821
+ doc: "docs/STRATEGY.md (2026-11-01, release age and trust policy)"
2822
+ }],
2823
+ options: {
2824
+ exclude: {
2825
+ type: "strings",
2826
+ default: [...TRAIN_SCOPES],
2827
+ description: "The patterns that `trustPolicyExclude` must have: the scopes whose versions the release train checks."
2828
+ },
2829
+ ignoreAfter: {
2830
+ type: "number",
2831
+ default: IGNORE_AFTER,
2832
+ description: "The smallest `trustPolicyIgnoreAfter`, in minutes. A larger value checks more versions."
2833
+ }
2834
+ },
2835
+ check(context, options) {
2836
+ if (!hasFile(context.root, "pnpm-lock.yaml")) return { skipped: "the repository has no pnpm-lock.yaml" };
2837
+ const exclude = Array.isArray(options["exclude"]) ? options["exclude"] : TRAIN_SCOPES;
2838
+ const ignoreAfter = typeof options["ignoreAfter"] === "number" ? options["ignoreAfter"] : IGNORE_AFTER;
2839
+ const exists = hasFile(context.root, WORKSPACE);
2840
+ const text = exists ? readFileSync(join(context.root, WORKSPACE), "utf8") : "";
2841
+ const lines = text.split(/\r?\n/);
2842
+ const edit = (after) => after === text ? [] : [{
2843
+ file: WORKSPACE,
2844
+ before: text,
2845
+ after
2846
+ }];
2847
+ const at = (index) => index === void 0 ? {} : { line: index + 1 };
2848
+ const breaks = [];
2849
+ const policy = valueOf(lines, "trustPolicy");
2850
+ if (policy?.value !== "no-downgrade") breaks.push({
2851
+ file: WORKSPACE,
2852
+ ...at(policy?.index),
2853
+ message: policy === void 0 ? `${exists ? WORKSPACE : "The repository"} does not set trustPolicy.` : `trustPolicy is "${policy.value}", not "no-downgrade".`,
2854
+ edits: edit(policy === void 0 ? insert(text, -1, [...POLICY_COMMENT, "trustPolicy: no-downgrade"]) : setValue(text, policy.index, "trustPolicy", "no-downgrade"))
2855
+ });
2856
+ const ignore = valueOf(lines, "trustPolicyIgnoreAfter");
2857
+ const minutes = ignore === void 0 ? void 0 : Number(ignore.value);
2858
+ if (minutes === void 0 || !Number.isInteger(minutes) || minutes < ignoreAfter) {
2859
+ const after = ignore !== void 0 ? setValue(text, ignore.index, "trustPolicyIgnoreAfter", String(ignoreAfter)) : policy !== void 0 ? insert(text, policy.index, [...IGNORE_COMMENT, `trustPolicyIgnoreAfter: ${String(ignoreAfter)}`]) : text;
2860
+ breaks.push({
2861
+ file: WORKSPACE,
2862
+ ...at(ignore?.index),
2863
+ message: ignore === void 0 ? `${WORKSPACE} does not set trustPolicyIgnoreAfter, so pnpm also refuses old versions that have less evidence for other reasons.` : `trustPolicyIgnoreAfter is ${ignore.value}, not a whole number of at least ${String(ignoreAfter)} minutes.`,
2864
+ edits: edit(after)
2865
+ });
2866
+ }
2867
+ const start = lines.findIndex((line) => line.startsWith("trustPolicyExclude:"));
2868
+ const inline = start >= 0 && (valueOf(lines, "trustPolicyExclude")?.value ?? "") !== "";
2869
+ const list = start >= 0 && !inline ? blockList(lines, start) : {
2870
+ items: [],
2871
+ last: start,
2872
+ indent: " "
2873
+ };
2874
+ const missing = exclude.filter((pattern) => !list.items.includes(pattern));
2875
+ if (missing.length > 0) {
2876
+ const items = missing.map((pattern) => `${list.indent}- ${JSON.stringify(pattern)}`);
2877
+ const after = inline ? text : start >= 0 ? insert(text, list.last, items) : policy === void 0 ? text : insert(text, -1, [
2878
+ ...EXCLUDE_COMMENT,
2879
+ "trustPolicyExclude:",
2880
+ ...items
2881
+ ]);
2882
+ breaks.push({
2883
+ file: WORKSPACE,
2884
+ ...at(start >= 0 ? start : void 0),
2885
+ message: `trustPolicyExclude does not have ${missing.join(", ")}.`,
2886
+ edits: edit(after)
2887
+ });
2888
+ }
2889
+ return breaks;
2890
+ }
2891
+ };
2748
2892
  // src/rules/workspace-protocol.ts
2749
2893
  /**
2750
2894
  * The rule `workspace-protocol`: a package uses another package of the workspace through `workspace:`.
@@ -2814,6 +2958,7 @@ const workspaceProtocol = {
2814
2958
  const RULES = [
2815
2959
  pinnedGitDeps,
2816
2960
  workspaceProtocol,
2961
+ trustPolicy,
2817
2962
  sourceMain,
2818
2963
  tsconfigTest,
2819
2964
  cuePreset,
@@ -2963,7 +3108,8 @@ function runFix(options) {
2963
3108
  for (const rule of result.rules) for (const edit of rule.breaks.flatMap((item) => item.edits ?? [])) {
2964
3109
  if (written.has(edit.file)) continue;
2965
3110
  const path = join(root, edit.file);
2966
- if (!existsSync(path) || readFileSync(path, "utf8") !== edit.before) continue;
3111
+ if ((existsSync(path) ? readFileSync(path, "utf8") : "") !== edit.before) continue;
3112
+ mkdirSync(dirname(path), { recursive: true });
2967
3113
  writeFileSync(path, edit.after);
2968
3114
  written.add(edit.file);
2969
3115
  if (!changed.includes(edit.file)) changed.push(edit.file);
@@ -3178,6 +3324,6 @@ function runCli(args, io) {
3178
3324
  if (summary) appendFileSync(summary, summaryMarkdown(result));
3179
3325
  return result.failed ? 1 : 0;
3180
3326
  }
3181
- export { globToRegExp as $, isGitSpecifier as A, cleanPath as B, repositoryOfRemote as C, roadmapParses as D, roadmapOfLine as E, noLocalPaths as F, lineOf as G, hasFile as H, noBuildOutput as I, readJsonc as J, matchesAny as K, STRICT_OPTIONS as L, pinnedGitDeps as M, DEFAULT_ALLOWED as N, requiredScripts as O, HOME_PATTERNS as P, globFolders as Q, cuePreset as R, sourceMain as S, scheduleMinute as T, inFolder as U, codePackages as V, keyLine as W, runGit as X, replaceLine as Y, specifiersOf as Z, testsRequired as _, listRules as a, isSourcePath as b, runCli as c, RULES as d, packageFolders as et, workspaceProtocol as f, typedFiles as g, scriptsOf as h, formatResult as i, isPinned as j, releaseFiles as k, runFix as l, configsOfScript as m, annotations as n, defaultOptions as nt, readConfig as o, typedScripts as p, parseJsonc as q, createContext as r, parseConfig as rt, runChecks as s, USAGE as t, workspaceGlobs as tt, summaryMarkdown as u, hasTests as v, runnerBudget as w, pathsOf as x, tsconfigTest as y, DEPENDENCY_FIELDS as z };
3327
+ export { runGit as $, roadmapParses as A, STRICT_OPTIONS as B, isSourcePath as C, runnerBudget as D, repositoryOfRemote as E, pinnedGitDeps as F, hasFile as G, DEPENDENCY_FIELDS as H, DEFAULT_ALLOWED as I, lineOf as J, inFolder as K, HOME_PATTERNS as L, releaseFiles as M, isGitSpecifier as N, scheduleMinute as O, isPinned as P, replaceLine as Q, noLocalPaths as R, tsconfigTest as S, sourceMain as T, cleanPath as U, cuePreset as V, codePackages as W, parseJsonc as X, matchesAny as Y, readJsonc as Z, configsOfScript as _, listRules as a, defaultOptions as at, testsRequired as b, runCli as c, RULES as d, specifiersOf as et, workspaceProtocol as f, typedScripts as g, trustPolicy as h, formatResult as i, workspaceGlobs as it, requiredScripts as j, roadmapOfLine as k, runFix as l, TRAIN_SCOPES as m, annotations as n, globToRegExp as nt, readConfig as o, parseConfig as ot, IGNORE_AFTER as p, keyLine as q, createContext as r, packageFolders as rt, runChecks as s, USAGE as t, globFolders as tt, summaryMarkdown as u, scriptsOf as v, pathsOf as w, hasTests as x, typedFiles as y, noBuildOutput as z };
3182
3328
 
3183
- //# sourceMappingURL=run-DD72yQn7.js.map
3329
+ //# sourceMappingURL=run-CRjXzR_6.js.map