Public: anyone can read this; the crew can change it.

Automate a review finding as a lint or test: **Direction.** This is a feature while the pipeline list is first; the issue ask #14370

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/14293-automate-a-review-finding-as-a-lint-or-t → main 1 commit fork

  • Merged. mason/14293-automate-a-review-finding-as-a-lint-or-t was merged into main as 9a43ecf.

Review

Sign in to review this change.
3 files changed +24 −3
src/kernel/direction.ts +14 −2
@@ -11,6 +11,9 @@
1111 * lines of vendored code that no page or screen path caught. A file added
1212 * under a `vendor/` directory counts once per directory.
1313 *
14 * The waiver names the issue it serves, as `#123` (#14293): five reviews (#11151, #12111, #13859,
15 * #14116, #14171) asked for it.
16 *
1417 * Four more reviews (#11289, #11696, #12177, #12307) accepted that waiver and
1518 * still said "keep it small and single-purpose" (#12363). So the waiver buys
1619 * a small pull only: at most `MAX_FEATURES` added feature files and
@@ -32,6 +35,10 @@ const PIPELINE = /^(scripts\/|src\/flow\/|src\/nightly\/|src\/checks\/|forge\.js
3235 export const MAX_FEATURES = 2;
3336 export const MAX_FILES = 20;
3437 const WAIVER = /^Direction:[ \t]*\S[^\n]{9,}/im;
38 /**
39 * The issue the waiver serves, as `#123` (#14293): five reviews said "say which issue it serves".
40 */
41 const ISSUE = /#\d+/;
3542
3643 /**
3744 * A redesign edits a page rather than adding one (#10380): an existing
@@ -60,7 +67,12 @@ export function directionProblems(
6067 ];
6168 if (features.length === 0) return [];
6269 if (changes.some((c) => PIPELINE.test(c.path))) return [];
63 if (!messages.some((m) => WAIVER.test(m))) return [problem(features)];
70 const waivers = messages.flatMap((m) => m.match(new RegExp(WAIVER.source, "gim")) ?? []);
71 if (waivers.length === 0) return [problem(features)];
72 if (!waivers.some((w) => ISSUE.test(w)))
73 return [
74 `rule "name the issue": the Direction line says why this feature goes ahead of the pipeline but not which issue it serves; add its number, as "Direction: <why> (#123)"`,
75 ];
6476 const big: string[] = [];
6577 if (features.length > MAX_FEATURES)
6678 big.push(`it adds ${features.length} feature files (at most ${MAX_FEATURES})`);
@@ -74,6 +86,6 @@ export function directionProblems(
7486 function problem(features: readonly string[]): string {
7587 const shown = features.slice(0, 3).join(", ") + (features.length > 3 ? ` and ${features.length - 3} more` : "");
7688 return (
77 `rule "pipeline first": this pull adds a feature (${shown}) and no pipeline change (scripts/, src/flow/, src/nightly/, src/checks/, forge.json); change the pipeline, or put a "Direction: <why this goes ahead of the pipeline items>" line (10+ characters) in a commit message`
89 `rule "pipeline first": this pull adds a feature (${shown}) and no pipeline change (scripts/, src/flow/, src/nightly/, src/checks/, forge.json); change the pipeline, or put a "Direction: <why this goes ahead of the pipeline items> (#issue)" line (10+ characters, naming the issue it serves) in a commit message`
7890 );
7991 }
test/direction-refusal.test.ts +1 −1
@@ -56,7 +56,7 @@ test("a range that adds a page alone is refused; a Direction line in its message
5656 // the gate's own entry point runs the rule, so removing its call goes red
5757 expect(gateMain(dir, base)).toContain('rule "pipeline first"');
5858
59 run(dir, "commit", "-q", "--allow-empty", "-m", "Waive\n\nDirection: a small door onto the spawn path, owner asked");
59 run(dir, "commit", "-q", "--allow-empty", "-m", "Waive\n\nDirection: a small door onto the spawn path, owner asked on #7642");
6060 expect(await withBase(base, () => directionRefusal(dir))).toEqual([]);
6161 expect(gateMain(dir, base)).not.toContain('rule "pipeline first"');
6262 });
test/direction.test.ts +9
@@ -78,3 +78,12 @@ test("a new action, core module or route is a feature too, naming the rule (#142
7878 expect(directionProblems([ch("A", "src/core/x.ts"), ch("M", "scripts/gate.ts")], [])).toEqual([]);
7979 expect(directionProblems([ch("A", "src/core/x.ts"), ch("A", "src/checks/y.ts")], [])).toEqual([]);
8080 });
81
82 test("a Direction line that names no issue is refused by name (#14293)", () => {
83 const out = directionProblems([page], ["Direction: a small door onto the spawn path, owner asked"]);
84 expect(out).toHaveLength(1);
85 expect(out[0]).toContain('rule "name the issue"');
86 expect(directionProblems([page], ["Direction: a small door onto the spawn path (#7642)"])).toEqual([]);
87 // an issue number elsewhere in the message is not the waiver's
88 expect(directionProblems([page], ["Closes #7642\n\nDirection: a small door onto the spawn path"])).toHaveLength(1);
89 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs