diff --git a/fixtures/laws/W-49/bad/astro-missing-client-only-directive-value.astro b/fixtures/laws/W-49/bad/astro-missing-client-only-directive-value.astro
new file mode 100644
index 0000000..cfc2b65
--- /dev/null
+++ b/fixtures/laws/W-49/bad/astro-missing-client-only-directive-value.astro
@@ -0,0 +1,5 @@
+---
+import Widget from "./Widget.tsx";
+---
+
+
diff --git a/fixtures/laws/W-49/bad/astro-no-conflict-set-directives.astro b/fixtures/laws/W-49/bad/astro-no-conflict-set-directives.astro
new file mode 100644
index 0000000..0b13f9e
--- /dev/null
+++ b/fixtures/laws/W-49/bad/astro-no-conflict-set-directives.astro
@@ -0,0 +1,6 @@
+---
+const html = "a";
+const text = "a";
+---
+
+
diff --git a/fixtures/laws/W-49/bad/astro-no-deprecated-astro-canonicalurl.astro b/fixtures/laws/W-49/bad/astro-no-deprecated-astro-canonicalurl.astro
new file mode 100644
index 0000000..ae325cc
--- /dev/null
+++ b/fixtures/laws/W-49/bad/astro-no-deprecated-astro-canonicalurl.astro
@@ -0,0 +1,4 @@
+---
+---
+
+
diff --git a/fixtures/laws/W-49/bad/astro-no-deprecated-astro-fetchcontent.astro b/fixtures/laws/W-49/bad/astro-no-deprecated-astro-fetchcontent.astro
new file mode 100644
index 0000000..8eebf89
--- /dev/null
+++ b/fixtures/laws/W-49/bad/astro-no-deprecated-astro-fetchcontent.astro
@@ -0,0 +1,5 @@
+---
+// expect: astro/no-deprecated-astro-fetchcontent
+const posts = Astro.fetchContent("./posts/*.md");
+---
+{posts.length}
diff --git a/fixtures/laws/W-49/bad/astro-no-deprecated-astro-resolve.astro b/fixtures/laws/W-49/bad/astro-no-deprecated-astro-resolve.astro
new file mode 100644
index 0000000..81306e2
--- /dev/null
+++ b/fixtures/laws/W-49/bad/astro-no-deprecated-astro-resolve.astro
@@ -0,0 +1,5 @@
+---
+// expect: astro/no-deprecated-astro-resolve
+const src = Astro.resolve("./a.png");
+---
+
diff --git a/fixtures/laws/W-49/bad/astro-no-deprecated-getentrybyslug.astro b/fixtures/laws/W-49/bad/astro-no-deprecated-getentrybyslug.astro
new file mode 100644
index 0000000..4e6b54e
--- /dev/null
+++ b/fixtures/laws/W-49/bad/astro-no-deprecated-getentrybyslug.astro
@@ -0,0 +1,6 @@
+---
+// expect: astro/no-deprecated-getentrybyslug
+import { getEntryBySlug } from "astro:content";
+const entry = await getEntryBySlug("blog", "a");
+---
+{entry}
diff --git a/fixtures/laws/W-49/bad/astro-no-exports-from-components.astro b/fixtures/laws/W-49/bad/astro-no-exports-from-components.astro
new file mode 100644
index 0000000..154ffe0
--- /dev/null
+++ b/fixtures/laws/W-49/bad/astro-no-exports-from-components.astro
@@ -0,0 +1,5 @@
+---
+// expect: astro/no-exports-from-components
+export const value = 1;
+---
+{value}
diff --git a/fixtures/laws/W-49/bad/astro-no-prerender-export-outside-pages.astro b/fixtures/laws/W-49/bad/astro-no-prerender-export-outside-pages.astro
new file mode 100644
index 0000000..6a50364
--- /dev/null
+++ b/fixtures/laws/W-49/bad/astro-no-prerender-export-outside-pages.astro
@@ -0,0 +1,5 @@
+---
+// expect: astro/no-prerender-export-outside-pages
+export const prerender = true;
+---
+x
diff --git a/fixtures/laws/W-49/bad/astro-no-unused-define-vars-in-style.astro b/fixtures/laws/W-49/bad/astro-no-unused-define-vars-in-style.astro
new file mode 100644
index 0000000..b269687
--- /dev/null
+++ b/fixtures/laws/W-49/bad/astro-no-unused-define-vars-in-style.astro
@@ -0,0 +1,7 @@
+---
+---
+x
+
+
diff --git a/fixtures/laws/W-49/clean/astro-missing-client-only-directive-value.astro b/fixtures/laws/W-49/clean/astro-missing-client-only-directive-value.astro
new file mode 100644
index 0000000..90c72c1
--- /dev/null
+++ b/fixtures/laws/W-49/clean/astro-missing-client-only-directive-value.astro
@@ -0,0 +1,4 @@
+---
+import Widget from "./Widget.tsx";
+---
+
diff --git a/fixtures/laws/W-49/clean/astro-no-conflict-set-directives.astro b/fixtures/laws/W-49/clean/astro-no-conflict-set-directives.astro
new file mode 100644
index 0000000..11a9615
--- /dev/null
+++ b/fixtures/laws/W-49/clean/astro-no-conflict-set-directives.astro
@@ -0,0 +1,5 @@
+---
+const html = "a";
+const text = "a";
+---
+
diff --git a/fixtures/laws/W-49/clean/astro-no-deprecated-astro-canonicalurl.astro b/fixtures/laws/W-49/clean/astro-no-deprecated-astro-canonicalurl.astro
new file mode 100644
index 0000000..61caf84
--- /dev/null
+++ b/fixtures/laws/W-49/clean/astro-no-deprecated-astro-canonicalurl.astro
@@ -0,0 +1,3 @@
+---
+---
+
diff --git a/fixtures/laws/W-49/clean/astro-no-deprecated-astro-fetchcontent.astro b/fixtures/laws/W-49/clean/astro-no-deprecated-astro-fetchcontent.astro
new file mode 100644
index 0000000..7c34d72
--- /dev/null
+++ b/fixtures/laws/W-49/clean/astro-no-deprecated-astro-fetchcontent.astro
@@ -0,0 +1,4 @@
+---
+const posts = Object.values(import.meta.glob("./posts/*.md"));
+---
+{posts.length}
diff --git a/fixtures/laws/W-49/clean/astro-no-deprecated-astro-resolve.astro b/fixtures/laws/W-49/clean/astro-no-deprecated-astro-resolve.astro
new file mode 100644
index 0000000..4158810
--- /dev/null
+++ b/fixtures/laws/W-49/clean/astro-no-deprecated-astro-resolve.astro
@@ -0,0 +1,4 @@
+---
+const src = new URL("./a.png", Astro.url).href;
+---
+
diff --git a/fixtures/laws/W-49/clean/astro-no-deprecated-getentrybyslug.astro b/fixtures/laws/W-49/clean/astro-no-deprecated-getentrybyslug.astro
new file mode 100644
index 0000000..0620a2a
--- /dev/null
+++ b/fixtures/laws/W-49/clean/astro-no-deprecated-getentrybyslug.astro
@@ -0,0 +1,5 @@
+---
+import { getEntry } from "astro:content";
+const entry = await getEntry("blog", "a");
+---
+{entry}
diff --git a/fixtures/laws/W-49/clean/astro-no-exports-from-components.astro b/fixtures/laws/W-49/clean/astro-no-exports-from-components.astro
new file mode 100644
index 0000000..17cc0a4
--- /dev/null
+++ b/fixtures/laws/W-49/clean/astro-no-exports-from-components.astro
@@ -0,0 +1,4 @@
+---
+const value = 1;
+---
+{value}
diff --git a/fixtures/laws/W-49/clean/astro-no-prerender-export-outside-pages.astro b/fixtures/laws/W-49/clean/astro-no-prerender-export-outside-pages.astro
new file mode 100644
index 0000000..9626cca
--- /dev/null
+++ b/fixtures/laws/W-49/clean/astro-no-prerender-export-outside-pages.astro
@@ -0,0 +1,5 @@
+---
+const prerender = true;
+void prerender;
+---
+x
diff --git a/fixtures/laws/W-49/clean/astro-no-unused-define-vars-in-style.astro b/fixtures/laws/W-49/clean/astro-no-unused-define-vars-in-style.astro
new file mode 100644
index 0000000..3795034
--- /dev/null
+++ b/fixtures/laws/W-49/clean/astro-no-unused-define-vars-in-style.astro
@@ -0,0 +1,6 @@
+---
+---
+x
+
diff --git a/src/cli/laws-probe-astro.test.ts b/src/cli/laws-probe-astro.test.ts
new file mode 100644
index 0000000..19233ff
--- /dev/null
+++ b/src/cli/laws-probe-astro.test.ts
@@ -0,0 +1,61 @@
+import { symlinkSync } from "node:fs";
+import { join } from "node:path";
+import { afterAll, describe, expect, it } from "vitest";
+import { REAL_TOOL_TIMEOUT } from "../gate/test-support-timeouts.ts";
+import { cleanTemp, put, tempDir } from "../laws/probe/testkit.ts";
+import { failing, KIT, messages, probeFrom, probeProcess } from "./test-support-probe.ts";
+import type { ProbeReport } from "../laws/probe/types.ts";
+
+afterAll(cleanTemp);
+
+/**
+ * An astro-site project that is not the kit: the kit's own ESLint preset for the astro variant, read from its
+ * source, and the kit's tools through a symlink. `off` is a rule its config turns off for `.astro` files.
+ */
+function astroSite(off?: string): string {
+ const dir = tempDir();
+ symlinkSync(join(KIT, "node_modules"), join(dir, "node_modules"));
+ const turned =
+ off === undefined ? "[]" : `[{ files: ["**/*.astro"], rules: { "${off}": "off" } }]`;
+ put(dir, {
+ "tsconfig.json": '{ "extends": "' + join(KIT, "tsconfig.json") + '" }\n',
+ "package.json": '{ "type": "module", "dependencies": { "astro": "5.0.0" } }\n',
+ "eslint.config.js": [
+ `import { eslintPreset } from "${join(KIT, "src/presets/eslint.js")}";`,
+ 'const base = await eslintPreset({ variant: "astro", tsconfigRootDir: import.meta.dirname, class: "astro-site" });',
+ `export default [...base, ...${turned}];`,
+ "",
+ ].join("\n"),
+ });
+ return dir;
+}
+
+function probe(dir: string, law: string): { code: number; report: ProbeReport } {
+ return probeFrom(probeProcess(dir, "--class", "astro-site", "--law", law, "--json"));
+}
+
+describe("G5 the Astro twins are proven under the astro preset, and each rule is the one its twin proves", () => {
+ it(
+ "W-22 and W-49 pass over their .astro and .tsx twins, none skipped",
+ () => {
+ const dir = astroSite();
+ const [w22, w49] = [probe(dir, "W-22"), probe(dir, "W-49")];
+ expect([w22.code, w49.code]).toEqual([0, 0]);
+ expect([failing(w22.report), failing(w49.report)]).toEqual([[], []]);
+ expect([w22.report.skipped, w49.report.skipped]).toEqual([[], []]);
+ },
+ REAL_TOOL_TIMEOUT,
+ );
+
+ it(
+ "a config that turns one Astro rule off fails the law red on that rule's twin, and on no other",
+ () => {
+ const result = probe(astroSite("astro/no-deprecated-astro-resolve"), "W-49");
+ expect(result.code).toBe(1);
+ expect(messages(result.report)).toEqual([
+ "W-49/bad/astro-no-deprecated-astro-resolve.astro:3 stayed quiet: astro/no-deprecated-astro-resolve did not fire on its bad twin",
+ ]);
+ },
+ REAL_TOOL_TIMEOUT,
+ );
+});
diff --git a/src/cli/laws-probe-fake.test.ts b/src/cli/laws-probe-fake.test.ts
index 2a5558a..b1631a7 100644
--- a/src/cli/laws-probe-fake.test.ts
+++ b/src/cli/laws-probe-fake.test.ts
@@ -23,7 +23,7 @@ const laws = (): readonly ProbeLaw[] => [
const passed: ProbeOutcome = {
ok: true,
- report: { laws: [{ id: "W-99", verdict: "pass", failures: [], unrelated: [] }] },
+ report: { laws: [{ id: "W-99", verdict: "pass", failures: [], unrelated: [] }], skipped: [] },
};
const failed: ProbeOutcome = {
@@ -42,6 +42,7 @@ const failed: ProbeOutcome = {
unrelated: [],
},
],
+ skipped: [],
},
};
@@ -83,6 +84,7 @@ describe("G3b the command prints a probe's report and picks its exit code", () =
expect(result.code).toBe(0);
expect(JSON.parse(result.out)).toEqual({
laws: [{ id: "W-99", verdict: "pass", failures: [], unrelated: [] }],
+ skipped: [],
});
expect(result.out.endsWith("}\n")).toBe(true);
});
@@ -222,3 +224,51 @@ describe("G3b the command's own problems", () => {
expect(made.fixtures).toBe(join(KIT, "fixtures", "laws"));
});
});
+
+describe("R105 the request says why Astro twins are skipped", () => {
+ const skipOf = async (
+ className: string,
+ files: Record = {},
+ ): Promise => {
+ const cwd = tempDir();
+ put(cwd, files);
+ const { probe, requests } = given(passed);
+ await cli(["--class", className, "--law", "W-99"], cwd, { probe, laws });
+ return first(requests).astroSkip;
+ };
+ const MANIFEST = (field: string): Record => ({
+ "package.json": JSON.stringify({ [field]: { astro: "^5.0.0" } }),
+ });
+
+ it("an astro-site lints Astro files, so nothing is skipped", async () => {
+ expect(await skipOf("astro-site")).toBeUndefined();
+ });
+
+ it("a ui-components and a ts-library project do not lint them, and the reason names the class", async () => {
+ expect(await skipOf("ui-components")).toBe(
+ "the ui-components preset does not lint .astro files",
+ );
+ expect(await skipOf("ts-library")).toBe("the ts-library preset does not lint .astro files");
+ });
+
+ it("a web-app lints them only when its package.json depends on astro, under any dependency field", async () => {
+ const why = "a web-app lints .astro files only when the project depends on astro";
+ expect(await skipOf("web-app")).toBe(why);
+ expect(await skipOf("web-app", { "package.json": "{}" })).toBe(why);
+ expect(await skipOf("web-app", { "package.json": "not json" })).toBe(why);
+ expect(await skipOf("web-app", MANIFEST("dependencies"))).toBeUndefined();
+ expect(await skipOf("web-app", MANIFEST("devDependencies"))).toBeUndefined();
+ expect(await skipOf("web-app", MANIFEST("peerDependencies"))).toBeUndefined();
+ expect(
+ await skipOf("web-app", { "package.json": JSON.stringify({ dependencies: ["astro"] }) }),
+ ).toBe(why);
+ });
+
+ it("the class is the one web-tops.yaml names when no --class is given", async () => {
+ const cwd = tempDir();
+ put(cwd, { "web-tops.yaml": "class: astro-site\n" });
+ const { probe, requests } = given(passed);
+ await cli(["--law", "W-99"], cwd, { probe, laws });
+ expect(first(requests).astroSkip).toBeUndefined();
+ });
+});
diff --git a/src/cli/laws-probe-ui.test.ts b/src/cli/laws-probe-ui.test.ts
index 62ada21..a8e11c4 100644
--- a/src/cli/laws-probe-ui.test.ts
+++ b/src/cli/laws-probe-ui.test.ts
@@ -3,11 +3,18 @@ import { REAL_TOOL_TIMEOUT } from "../gate/test-support-timeouts.ts";
import { lawsOfClass } from "../laws/probe/catalog.ts";
import { kitProbeLaws } from "../laws/probe/testkit.ts";
import { cleanTemp, put } from "../laws/probe/testkit.ts";
-import { adopter, failing, messages, probeOf, verdicts } from "./test-support-probe.ts";
+import {
+ adopter,
+ failing,
+ messages,
+ probeOf,
+ probeProcess,
+ verdicts,
+} from "./test-support-probe.ts";
afterAll(cleanTemp);
-const ALL = kitProbeLaws().map((law) => law.id);
+const WEB_APP = lawsOfClass(kitProbeLaws(), "web-app").map((law) => law.id);
const TS_ONLY = lawsOfClass(kitProbeLaws(), "ts-library").map((law) => law.id);
/** Replaces one line of a config, as an adopter that did not enable a rule would have it. */
@@ -24,10 +31,19 @@ describe("G3c `laws probe` under a class with JSX and CSS: W-22 and W-26", () =>
it("proves W-22 and W-26 beside the laws every class maps, and every law passes", () => {
expect(ui.code).toBe(0);
- expect(ui.report.laws.map((law) => law.id)).toEqual(ALL);
+ expect(ui.report.laws.map((law) => law.id)).toEqual(WEB_APP);
expect(failing(ui.report)).toEqual([]);
});
+ it("a law whose twins are all Astro is not probed for a web-app that does not depend on astro, and the exit says why", () => {
+ const run = probeProcess(adopter(undefined, true), "--class", "web-app", "--law", "W-49");
+ expect(run.code).toBe(2);
+ expect(run.err).toBe(
+ "webtops laws probe: every twin of the given laws was skipped: a web-app lints .astro files only when the project depends on astro\n",
+ );
+ expect(run.out).toBe("");
+ });
+
it(
"a ts-library probes neither, and a project's web-tops.yaml names its class",
async () => {
@@ -36,7 +52,7 @@ describe("G3c `laws probe` under a class with JSX and CSS: W-22 and W-26", () =>
expect(plain.report.laws.map((law) => law.id)).toEqual(TS_ONLY);
put(dir, { "web-tops.yaml": "class: web-app\n" });
const named = await probeOf(dir);
- expect(named.report.laws.map((law) => law.id)).toEqual(ALL);
+ expect(named.report.laws.map((law) => law.id)).toEqual(WEB_APP);
},
REAL_TOOL_TIMEOUT,
);
diff --git a/src/cli/laws-probe.ts b/src/cli/laws-probe.ts
index 4fb18b0..5e6777f 100644
--- a/src/cli/laws-probe.ts
+++ b/src/cli/laws-probe.ts
@@ -105,13 +105,47 @@ const absolute = (cwd: string, path: string): string =>
const noLaws = (law: string | undefined): string =>
law === undefined ? "no law to probe" : `no law ${law} to probe`;
-/** The one law asked for, or the laws the project's class maps: `--class`, else `web-tops.yaml`, else `ts-library`. */
+/** The project's class: `--class`, else `web-tops.yaml`, else `ts-library`. */
+const classOf = (io: Io, flags: Flags): string =>
+ flags.class ?? projectString(io.cwd, "class") ?? defaultClass();
+
+/** The one law asked for, or the laws the project's class maps. */
function lawsFor(io: Io, deps: ProbeDeps, flags: Flags): ProbeLaw[] {
const laws = deps.laws();
if (flags.law !== undefined) {
return laws.filter((law) => law.id === flags.law);
}
- return lawsOfClass(laws, flags.class ?? projectString(io.cwd, "class") ?? defaultClass());
+ return lawsOfClass(laws, classOf(io, flags));
+}
+
+/** Whether the project's `package.json` lists `astro` among its dependencies. */
+function dependsOnAstro(cwd: string): boolean {
+ try {
+ const manifest: unknown = JSON.parse(readFileSync(join(cwd, "package.json"), "utf8"));
+ return ["dependencies", "devDependencies", "peerDependencies"].some((field) => {
+ const group = step(manifest, field);
+ return isRecord(group) && "astro" in group;
+ });
+ } catch {
+ return false;
+ }
+}
+
+/**
+ * Why `.astro` twins are left out, or undefined when the class's preset lints them: an astro-site always does, a
+ * web-app only when the project depends on astro, and every other class has no Astro files to lint.
+ */
+function astroSkip(io: Io, flags: Flags): string | undefined {
+ const className = classOf(io, flags);
+ if (className === "astro-site") {
+ return undefined;
+ }
+ if (className === "web-app") {
+ return dependsOnAstro(io.cwd)
+ ? undefined
+ : "a web-app lints .astro files only when the project depends on astro";
+ }
+ return `the ${className} preset does not lint .astro files`;
}
/** The laws to probe, or what is wrong: the catalog cannot be read, or the flags choose no law. */
@@ -139,6 +173,7 @@ function requestOf(io: Io, deps: ProbeDeps, flags: Flags, laws: readonly ProbeLa
eslintConfig:
flags.config === undefined ? projectEslintConfig(io.cwd) : absolute(io.cwd, flags.config),
tsconfig: absolute(io.cwd, flags.tsconfig ?? "tsconfig.json"),
+ astroSkip: astroSkip(io, flags),
};
}
diff --git a/src/laws/probe/catalog.test.ts b/src/laws/probe/catalog.test.ts
index 19ea4f4..19d6013 100644
--- a/src/laws/probe/catalog.test.ts
+++ b/src/laws/probe/catalog.test.ts
@@ -7,7 +7,7 @@ const ids = (className: string): string[] =>
lawsOfClass(kitProbeLaws(), className).map((law) => law.id);
describe("G3a the laws the probe proves are the catalog's ticked lint and compiler laws", () => {
- it("reads the fourteen laws a lint rule or a flag judges, in order, from laws/W-NN.yaml", () => {
+ it("reads the fifteen laws a lint rule or a flag judges (judged v0.1 or m3), in order, from laws/W-NN.yaml", () => {
expect(kitProbeLaws().map((law) => law.id)).toEqual([
"W-01",
"W-02",
@@ -23,6 +23,7 @@ describe("G3a the laws the probe proves are the catalog's ticked lint and compil
"W-26",
"W-34",
"W-35",
+ "W-49",
]);
});
@@ -42,6 +43,13 @@ describe("G3a the laws the probe proves are the catalog's ticked lint and compil
expect(ids("web-app")).toContain("W-26");
});
+ it("W-49 is mapped by the astro-site class alone", () => {
+ expect(ids("astro-site")).toContain("W-49");
+ for (const className of ["ts-library", "ui-components", "web-app", "node-service"]) {
+ expect(ids(className)).not.toContain("W-49");
+ }
+ });
+
it("a class the catalog does not know maps nothing, and a law with no class list is mapped by every class", () => {
expect(ids("cli")).toEqual([]);
expect(lawsOfClass([], "ts-library")).toEqual([]);
diff --git a/src/laws/probe/fixtures.test.ts b/src/laws/probe/fixtures.test.ts
index 1eef8da..610250b 100644
--- a/src/laws/probe/fixtures.test.ts
+++ b/src/laws/probe/fixtures.test.ts
@@ -34,7 +34,9 @@ describe("G3a every law the probe proves has a bad and a clean twin, marked", ()
it("only a bad twin carries a marker, and each file is an ES module so the twins do not share globals", () => {
const withMarkers = TWINS.filter((twin) => parseMarkers(twin.file, text(twin.file)).length > 0);
expect(withMarkers.every((twin) => twin.kind === "bad")).toBe(true);
- const sources = TWINS.filter((twin) => !twin.file.endsWith(".css"));
+ const sources = TWINS.filter(
+ (twin) => !twin.file.endsWith(".css") && !twin.file.endsWith(".astro"),
+ );
const scripts = sources.filter((twin) => !/^(import|export) /mu.test(text(twin.file)));
expect(scripts.map((twin) => twin.file)).toEqual([]);
});
diff --git a/src/laws/probe/format.test.ts b/src/laws/probe/format.test.ts
index cfc18e1..7476e6d 100644
--- a/src/laws/probe/format.test.ts
+++ b/src/laws/probe/format.test.ts
@@ -15,7 +15,7 @@ const FAIL: LawProbe = {
describe("G3b the probe's text and exit code", () => {
it("prints a line for each law, its failures under it, and how many pass", () => {
- const report: ProbeReport = { laws: [PASS, FAIL] };
+ const report: ProbeReport = { laws: [PASS, FAIL], skipped: [] };
expect(probeText(report)).toBe(
[
"W-01 pass",
@@ -30,17 +30,34 @@ describe("G3b the probe's text and exit code", () => {
});
it("says nothing about unrelated findings when there are none", () => {
- expect(probeText({ laws: [PASS] })).toBe("W-01 pass\n1 of 1 laws probed pass\n");
+ expect(probeText({ laws: [PASS], skipped: [] })).toBe("W-01 pass\n1 of 1 laws probed pass\n");
});
it("counts no law as 0 of 0, and exits 0 for it: there is nothing that fails", () => {
- expect(probeText({ laws: [] })).toBe("0 of 0 laws probed pass\n");
- expect(probeExit({ laws: [] })).toBe(0);
+ expect(probeText({ laws: [], skipped: [] })).toBe("0 of 0 laws probed pass\n");
+ expect(probeExit({ laws: [], skipped: [] })).toBe(0);
});
it("exits 0 when every law passes and 1 when any fails", () => {
- expect(probeExit({ laws: [PASS, PASS] })).toBe(0);
- expect(probeExit({ laws: [PASS, FAIL] })).toBe(1);
- expect(probeExit({ laws: [FAIL] })).toBe(1);
+ expect(probeExit({ laws: [PASS, PASS], skipped: [] })).toBe(0);
+ expect(probeExit({ laws: [PASS, FAIL], skipped: [] })).toBe(1);
+ expect(probeExit({ laws: [FAIL], skipped: [] })).toBe(1);
+ });
+
+ it("names each skipped twin with its reason, after the laws and before the count", () => {
+ const reason = "the ui-components preset does not lint .astro files";
+ const skipped = [
+ { law: "W-22", kind: "bad" as const, file: "W-22/bad/a.astro", reason },
+ { law: "W-22", kind: "clean" as const, file: "W-22/clean/a.astro", reason },
+ ];
+ expect(probeText({ laws: [PASS], skipped })).toBe(
+ [
+ "W-01 pass",
+ `skipped W-22/bad/a.astro: ${reason}`,
+ `skipped W-22/clean/a.astro: ${reason}`,
+ "1 of 1 laws probed pass",
+ "",
+ ].join("\n"),
+ );
});
});
diff --git a/src/laws/probe/format.ts b/src/laws/probe/format.ts
index 5a80ad7..21cf0b5 100644
--- a/src/laws/probe/format.ts
+++ b/src/laws/probe/format.ts
@@ -15,7 +15,8 @@ function lawLines(probe: LawProbe): string[] {
export function probeText(report: ProbeReport): string {
const passed = report.laws.filter((probe) => probe.verdict === "pass").length;
const total = `${String(passed)} of ${String(report.laws.length)} laws probed pass`;
- return `${[...report.laws.flatMap(lawLines), total].join("\n")}\n`;
+ const skipped = report.skipped.map((twin) => `skipped ${twin.file}: ${twin.reason}`);
+ return `${[...report.laws.flatMap(lawLines), ...skipped, total].join("\n")}\n`;
}
export const probeExit = (report: ProbeReport): 0 | 1 =>
diff --git a/src/laws/probe/judge.test.ts b/src/laws/probe/judge.test.ts
index a3f7eea..38213c6 100644
--- a/src/laws/probe/judge.test.ts
+++ b/src/laws/probe/judge.test.ts
@@ -18,6 +18,7 @@ const GOOD: LawEvidence = {
twins: TWINS,
marks: [mark(1, "no-thing"), mark(2, "noImplicitAny")],
seen: [seen(BAD, 1, "plugin/no-thing"), seen(BAD, 2, "TS7006")],
+ skippedMarks: [],
};
function kinds(evidence: LawEvidence): string[] {
@@ -210,4 +211,30 @@ describe("G3b the judge says each failure in a sentence", () => {
"W-99/bad/b.ts has no // expect: marker",
]);
});
+
+ it("a proof that only a skipped twin names is not unproven: it was skipped, and the report says so", () => {
+ const skipped = { file: "W-99/bad/page.astro", line: 1, rules: ["astro/no-astro"] };
+ const law: ProbeLaw = { id: "W-99", proofs: ["no-thing", "astro/no-astro"] };
+ const evidence: LawEvidence = {
+ ...GOOD,
+ law,
+ marks: [mark(1, "no-thing")],
+ seen: [seen(BAD, 1, "plugin/no-thing")],
+ };
+ expect(kinds(evidence)).toEqual(["unproven"]);
+ expect(kinds({ ...evidence, skippedMarks: [skipped] })).toEqual([]);
+ });
+
+ it("a skipped twin excuses only the proof it names, never another one", () => {
+ const skipped = { file: "W-99/bad/page.astro", line: 1, rules: ["astro/other-rule"] };
+ const law: ProbeLaw = { id: "W-99", proofs: ["no-thing", "astro/no-astro"] };
+ const evidence: LawEvidence = {
+ ...GOOD,
+ law,
+ marks: [mark(1, "no-thing")],
+ seen: [seen(BAD, 1, "plugin/no-thing")],
+ skippedMarks: [skipped],
+ };
+ expect(kinds(evidence)).toEqual(["unproven"]);
+ });
});
diff --git a/src/laws/probe/judge.ts b/src/laws/probe/judge.ts
index 037bc16..4e2fab0 100644
--- a/src/laws/probe/judge.ts
+++ b/src/laws/probe/judge.ts
@@ -16,6 +16,8 @@ export interface LawEvidence {
readonly twins: readonly Twin[];
readonly marks: readonly Expectation[];
readonly seen: readonly Observed[];
+ /** The markers of this law's twins that were left out: a rule they name was skipped, not unproven. */
+ readonly skippedMarks: readonly Expectation[];
}
const at = (found: { file: string; line: number }): string => `${found.file}:${String(found.line)}`;
@@ -167,7 +169,7 @@ export function judgeLaw(evidence: LawEvidence): LawProbe {
...unexpected(law, bad, badMarks, seen),
...marksInClean(clean, marks),
...noisy(law, clean, seen),
- ...unproven(law, badMarks),
+ ...unproven(law, [...badMarks, ...evidence.skippedMarks]),
];
const unrelated = inFiles(seen, own).filter(
(found) => !explains(law, found.rule) && !marked(marks, found) && !isNotEvaluated(found.rule),
diff --git a/src/laws/probe/run.test.ts b/src/laws/probe/run.test.ts
index c5db552..a8eb46a 100644
--- a/src/laws/probe/run.test.ts
+++ b/src/laws/probe/run.test.ts
@@ -487,3 +487,163 @@ describe("G3b the runner's exact calls, and each law judged on its own twins", (
expect(!outcome.ok && outcome.problem).toBe("eslint did not run: tool-timeout. late\npartial");
});
});
+
+const MIXED_LAW: ProbeLaw = { id: "W-96", proofs: ["no-thing", "astro/no-astro"] };
+
+function mixedFixtures(): string {
+ const dir = tempDir();
+ put(dir, {
+ "W-96/bad/a.ts": "export const a = 1; // expect: no-thing\n",
+ "W-96/clean/a.ts": "export const a = 1;\n",
+ "W-96/bad/page.astro": " \n",
+ "W-96/clean/page.astro": "\n",
+ });
+ return dir;
+}
+
+const REASON = "the ui-components preset does not lint .astro files";
+
+describe("R105 the runner skips Astro twins a class cannot lint, and says so", () => {
+ const mixed = (cwd: string, exec: Exec, extra: Partial = {}): ProbeRequest =>
+ request(cwd, exec, { laws: [MIXED_LAW], fixtures: mixedFixtures(), ...extra });
+
+ it("names no Astro twin to ESLint, reports each as skipped with the reason, and passes on the other twins", async () => {
+ const cwd = project();
+ const calls: Call[] = [];
+ const real = join(realpathSync(cwd), ".web-tops/out/laws-probe");
+ const found = JSON.stringify([
+ {
+ filePath: `${real}/W-96/bad/a.ts`,
+ messages: [{ ruleId: "p/no-thing", line: 1, message: "m" }],
+ },
+ ]);
+ const outcome = await runProbe(
+ mixed(cwd, fake({ eslintOutput: found }, calls), { astroSkip: REASON }),
+ );
+ expect(nth(calls, 0).args.join(" ")).not.toContain("page.astro");
+ expect(outcome).toMatchObject({
+ ok: true,
+ report: {
+ laws: [{ id: "W-96", verdict: "pass", failures: [] }],
+ skipped: [
+ { file: "W-96/bad/page.astro", reason: REASON },
+ { file: "W-96/clean/page.astro", reason: REASON },
+ ],
+ },
+ });
+ });
+
+ it("without a reason the Astro twins are linted and proven, and nothing is skipped", async () => {
+ const cwd = project();
+ const calls: Call[] = [];
+ const outcome = await runProbe(mixed(cwd, fake({ eslintOutput: "[]" }, calls)));
+ expect(nth(calls, 0).args.join(" ")).toContain("page.astro");
+ expect(outcome).toMatchObject({ ok: true, report: { skipped: [] } });
+ });
+
+ it("a law whose every twin is Astro is left out, and a probe with no law left is a problem naming why", async () => {
+ const cwd = project();
+ const outcome = await runProbe(
+ request(cwd, fake({ eslintOutput: "[]" }, []), {
+ laws: [ASTRO_LAW],
+ fixtures: astroFixtures(),
+ astroSkip: REASON,
+ }),
+ );
+ expect(outcome).toEqual({
+ ok: false,
+ code: 2,
+ problem: `every twin of the given laws was skipped: ${REASON}`,
+ });
+ });
+
+ it("a law with only Astro twins is dropped beside a law that has others, and the other is still judged", async () => {
+ const cwd = project();
+ const fixtures = mixedFixtures();
+ put(fixtures, {
+ "W-97/bad/page.astro": " \n",
+ "W-97/clean/page.astro": "\n",
+ });
+ const outcome = await runProbe(
+ request(cwd, fake({ eslintOutput: "[]" }, []), {
+ laws: [MIXED_LAW, ASTRO_LAW],
+ fixtures,
+ astroSkip: REASON,
+ }),
+ );
+ expect(outcome.ok && outcome.report.laws.map((law) => law.id)).toEqual(["W-96"]);
+ expect(outcome.ok && outcome.report.skipped.map((twin) => twin.law)).toEqual([
+ "W-96",
+ "W-96",
+ "W-97",
+ "W-97",
+ ]);
+ });
+});
+
+describe("R105 the runner keeps each law's twins and each law's skips apart", () => {
+ const OTHER: ProbeLaw = { id: "W-95", proofs: ["no-thing", "astro/no-astro"] };
+
+ it("a proof that another law's skipped twin names is still unproven for a law that has no such twin", async () => {
+ const cwd = project();
+ const fixtures = mixedFixtures();
+ put(fixtures, {
+ "W-95/bad/a.ts": "export const a = 1; // expect: no-thing\n",
+ "W-95/clean/a.ts": "export const a = 1;\n",
+ });
+ const real = join(realpathSync(cwd), ".web-tops/out/laws-probe");
+ const found = JSON.stringify(
+ ["W-95", "W-96"].map((id) => ({
+ filePath: `${real}/${id}/bad/a.ts`,
+ messages: [{ ruleId: "p/no-thing", line: 1, message: "m" }],
+ })),
+ );
+ const outcome = await runProbe(
+ request(cwd, fake({ eslintOutput: found }, []), {
+ laws: [MIXED_LAW, OTHER],
+ fixtures,
+ astroSkip: REASON,
+ }),
+ );
+ expect(outcome.ok && outcome.report.laws.map((law) => `${law.id} ${law.verdict}`)).toEqual([
+ "W-96 pass",
+ "W-95 fail",
+ ]);
+ expect(outcome.ok && outcome.report.laws[1]?.failures.map((failure) => failure.kind)).toEqual([
+ "unproven",
+ ]);
+ });
+
+ it("a law with no twin of its own has none, even beside a law that has some", async () => {
+ const cwd = project();
+ const outcome = await runProbe(
+ request(cwd, fake({ eslintOutput: "[]" }, []), {
+ laws: [LAW, { id: "W-98", proofs: ["no-thing"] }],
+ }),
+ );
+ expect(outcome.ok && outcome.report.laws[1]?.failures.map((failure) => failure.kind)).toEqual([
+ "no-bad-twin",
+ "no-clean-twin",
+ "unproven",
+ ]);
+ });
+
+ it("a law with no twin at all stays in the report beside a law whose twins were skipped", async () => {
+ const outcome = await runProbe(
+ request(project(), fake({ eslintOutput: "[]" }, []), {
+ laws: [MIXED_LAW, { id: "W-94", proofs: ["no-thing"] }],
+ fixtures: mixedFixtures(),
+ astroSkip: REASON,
+ }),
+ );
+ expect(outcome.ok && outcome.report.laws.map((law) => `${law.id} ${law.verdict}`)).toEqual([
+ "W-96 fail",
+ "W-94 fail",
+ ]);
+ });
+
+ it("no law to probe and nothing skipped is a report with no law, not a problem", async () => {
+ const outcome = await runProbe(request(project(), fake({}, []), { laws: [] }));
+ expect(outcome).toEqual({ ok: true, report: { laws: [], skipped: [] } });
+ });
+});
diff --git a/src/laws/probe/run.ts b/src/laws/probe/run.ts
index e905931..82cb123 100644
--- a/src/laws/probe/run.ts
+++ b/src/laws/probe/run.ts
@@ -5,8 +5,16 @@ import { TOOLS, parseJson, readOutput, resolveTool } from "../../layers/hygiene/
import { judgeLaw } from "./judge.ts";
import { parseMarkers } from "./markers.ts";
import { readEslint, readStylelint, readTsc, type Reading } from "./observe.ts";
-import { isAstro, isCss, isScript, listTwins, materialize, stylelintIgnore } from "./twins.ts";
-import type { Expectation, Observed, ProbeLaw, ProbeReport, Twin } from "./types.ts";
+import {
+ isAstro,
+ isCss,
+ isScript,
+ listTwins,
+ materialize,
+ splitTwins,
+ stylelintIgnore,
+} from "./twins.ts";
+import type { Expectation, Observed, ProbeLaw, ProbeReport, SkippedTwin, Twin } from "./types.ts";
export interface ProbeRequest {
readonly cwd: string;
@@ -21,6 +29,11 @@ export interface ProbeRequest {
readonly eslintConfig: string | undefined;
/** The tsconfig whose flags are proven: the project's own. */
readonly tsconfig: string;
+ /**
+ * Why Astro twins are left out: the project's class has no Astro files to lint. Absent when its preset lints them,
+ * and then each Astro twin is proven like any other.
+ */
+ readonly astroSkip?: string | undefined;
}
/** The probe could not run: 3 when a tool is missing or timed out, 2 when a config or output is unusable. */
@@ -160,16 +173,38 @@ function marksOf(scratch: string, twins: readonly Twin[]): Expectation[] {
);
}
-function report(
- request: ProbeRequest,
- twins: readonly Twin[],
- seen: readonly Observed[],
-): ProbeReport {
- const marks = marksOf(request.scratch, twins);
+interface Kept {
+ readonly kept: readonly Twin[];
+ readonly skipped: readonly SkippedTwin[];
+}
+
+/** The markers of the files of a law: a marker names its file with the law's id first. */
+const ofLaw = (marks: readonly Expectation[], law: ProbeLaw): Expectation[] =>
+ marks.filter((mark) => mark.file.startsWith(`${law.id}/`));
+
+/**
+ * A law whose every twin was skipped has nothing to judge: it is left out of the laws, and its twins are named in
+ * `skipped` with the reason. A rule only a skipped twin names is not unproven: it was skipped.
+ */
+function report(request: ProbeRequest, twins: Kept, seen: readonly Observed[]): ProbeReport {
+ const marks = marksOf(request.scratch, twins.kept);
+ const skippedMarks = marksOf(request.scratch, twins.skipped);
+ const left = request.laws.filter(
+ (law) =>
+ twins.kept.some((twin) => twin.law === law.id) ||
+ !twins.skipped.some((twin) => twin.law === law.id),
+ );
return {
- laws: request.laws.map((law) =>
- judgeLaw({ law, twins: twins.filter((twin) => twin.law === law.id), marks, seen }),
+ laws: left.map((law) =>
+ judgeLaw({
+ law,
+ twins: twins.kept.filter((twin) => twin.law === law.id),
+ marks,
+ seen,
+ skippedMarks: ofLaw(skippedMarks, law),
+ }),
),
+ skipped: twins.skipped,
};
}
@@ -189,22 +224,26 @@ const real = (request: ProbeRequest): ProbeRequest => ({
* what the tools reported.
*/
export async function runProbe(given: ProbeRequest): Promise {
- const twins = listTwins(given.fixtures, given.laws);
+ const twins = splitTwins(listTwins(given.fixtures, given.laws), given.astroSkip);
materialize(given.fixtures, given.scratch, given.laws, given.tsconfig);
const request = real(given);
- const linted = await lint(request, twins);
+ const linted = await lint(request, twins.kept);
if (!linted.ok) {
return linted;
}
- const compiled = await compile(request, twins);
+ const compiled = await compile(request, twins.kept);
if (!compiled.ok) {
return compiled;
}
- const styled = await stylelintPass(request, twins);
+ const styled = await stylelintPass(request, twins.kept);
return styled.ok
- ? {
- ok: true,
- report: report(request, twins, [...linted.seen, ...compiled.seen, ...styled.seen]),
- }
+ ? judged(report(request, twins, [...linted.seen, ...compiled.seen, ...styled.seen]))
: styled;
}
+
+/** A probe that left every law out has proven nothing: it says so, and names the twins it skipped. */
+function judged(made: ProbeReport): ProbeOutcome {
+ return made.laws.length === 0 && made.skipped.length > 0
+ ? problem(`every twin of the given laws was skipped: ${String(made.skipped[0]?.reason)}`)
+ : { ok: true, report: made };
+}
diff --git a/src/laws/probe/source.test.ts b/src/laws/probe/source.test.ts
index 7e55770..4491dd2 100644
--- a/src/laws/probe/source.test.ts
+++ b/src/laws/probe/source.test.ts
@@ -68,7 +68,8 @@ describe("G3a the laws the probe proves are read from the catalog's records", ()
it("leaves out a law that is not ticked, whatever its rules", () => {
expect(isProbed(W47)).toBe(false);
- expect(isProbed({ ...W01, judged: "m3" })).toBe(false);
+ expect(isProbed({ ...W01, judged: "no" })).toBe(false);
+ expect(isProbed({ ...W01, judged: "m3" })).toBe(true);
});
it("lists the probed laws in id order, and reads the records each time the source is called", () => {
diff --git a/src/laws/probe/source.ts b/src/laws/probe/source.ts
index 1333efd..d5f97f6 100644
--- a/src/laws/probe/source.ts
+++ b/src/laws/probe/source.ts
@@ -21,13 +21,16 @@ const isCustom = (name: string): boolean => name.startsWith("webtops/");
const probed = (rule: LawRecord["rules"][number]): boolean => probedTools().includes(rule.tool);
+/** A law is judged when section 8.2 ticks it (`v0.1`) or milestone M3 gives it a reader (`m3`); `no` is not judged yet. */
+const isJudged = (law: LawRecord): boolean => law.judged === "v0.1" || law.judged === "m3";
+
/**
- * Whether the probe proves a law: it is ticked (`judged: v0.1`, section 8.2), a lint rule or a compiler flag judges it,
- * and none of those is a rule of the custom plugin.
+ * Whether the probe proves a law: it is judged, a lint rule or a compiler flag judges it, and none of those is a rule
+ * of the custom plugin.
*/
export function isProbed(law: LawRecord): boolean {
const rules = law.rules.filter(probed);
- return law.judged === "v0.1" && rules.length > 0 && !rules.some((rule) => isCustom(rule.name));
+ return isJudged(law) && rules.length > 0 && !rules.some((rule) => isCustom(rule.name));
}
/** A law as the probe takes it: what its tool rules and flags name are what its twins must prove. */
diff --git a/src/laws/probe/twins.test.ts b/src/laws/probe/twins.test.ts
index 476cb0d..bd550c5 100644
--- a/src/laws/probe/twins.test.ts
+++ b/src/laws/probe/twins.test.ts
@@ -2,7 +2,15 @@ import { existsSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { afterAll, describe, expect, it } from "vitest";
import { cleanTemp, put, tempDir } from "./testkit.ts";
-import { isAstro, isCss, isScript, listTwins, materialize, stylelintIgnore } from "./twins.ts";
+import {
+ isAstro,
+ isCss,
+ isScript,
+ listTwins,
+ materialize,
+ splitTwins,
+ stylelintIgnore,
+} from "./twins.ts";
import type { ProbeLaw } from "./types.ts";
afterAll(cleanTemp);
@@ -100,7 +108,7 @@ describe("G3a twins: fixtures/laws/W-NN/{bad,clean}/", () => {
expect(config).toEqual({
extends: "/project/tsconfig.json",
compilerOptions: { noEmit: true },
- include: ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"],
+ include: ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts", "**/*.astro"],
exclude: [],
});
});
@@ -124,3 +132,29 @@ describe("G3a twins: the files a twin has", () => {
]);
});
});
+
+describe("R105 twins: the Astro twins a class's preset cannot lint are skipped, with a reason", () => {
+ const TWINS = [
+ { law: "W-22", kind: "bad" as const, file: "W-22/bad/a.tsx" },
+ { law: "W-22", kind: "bad" as const, file: "W-22/bad/a.astro" },
+ { law: "W-22", kind: "clean" as const, file: "W-22/clean/a.astro" },
+ { law: "W-26", kind: "bad" as const, file: "W-26/bad/s.css" },
+ ];
+
+ it("keeps every twin when the preset lints Astro", () => {
+ expect(splitTwins(TWINS, undefined)).toEqual({ kept: TWINS, skipped: [] });
+ });
+
+ it("skips each Astro twin, and only those, with the reason beside it", () => {
+ const { kept, skipped } = splitTwins(TWINS, "no astro here");
+ expect(kept.map((twin) => twin.file)).toEqual(["W-22/bad/a.tsx", "W-26/bad/s.css"]);
+ expect(skipped).toEqual([
+ { law: "W-22", kind: "bad", file: "W-22/bad/a.astro", reason: "no astro here" },
+ { law: "W-22", kind: "clean", file: "W-22/clean/a.astro", reason: "no astro here" },
+ ]);
+ });
+
+ it("an empty reason still skips: only an absent one keeps the twins", () => {
+ expect(splitTwins(TWINS, "").skipped).toHaveLength(2);
+ });
+});
diff --git a/src/laws/probe/twins.ts b/src/laws/probe/twins.ts
index c54f245..da3e9e1 100644
--- a/src/laws/probe/twins.ts
+++ b/src/laws/probe/twins.ts
@@ -1,6 +1,6 @@
import { cpSync, existsSync, mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs";
import { join } from "node:path";
-import type { ProbeLaw, Twin, TwinKind } from "./types.ts";
+import type { ProbeLaw, SkippedTwin, Twin, TwinKind } from "./types.ts";
/** The files of a twin the tools read. Anything else in a twin directory is copied beside them and left alone. */
function twinFile(): RegExp {
@@ -46,6 +46,21 @@ export function listTwins(fixtures: string, laws: readonly ProbeLaw[]): Twin[] {
);
}
+/**
+ * The twins the project's preset can lint, and those it cannot. An Astro twin is left out, with the reason, when the
+ * class has no Astro files to lint (`astroSkip` is the reason); every other twin is kept.
+ */
+export function splitTwins(
+ twins: readonly Twin[],
+ astroSkip: string | undefined,
+): { readonly kept: Twin[]; readonly skipped: SkippedTwin[] } {
+ const skip = (twin: Twin): boolean => astroSkip !== undefined && isAstro(twin.file);
+ return {
+ kept: twins.filter((twin) => !skip(twin)),
+ skipped: twins.filter(skip).map((twin) => ({ ...twin, reason: String(astroSkip) })),
+ };
+}
+
/**
* The scratch project: a copy of each probed law's directory, the one tsconfig the compiler and the type-aware lint
* rules both find, and an empty ignore file for Stylelint. It extends the project's own, so a flag the project turns off is off for the twins too, and it
@@ -68,7 +83,7 @@ export function materialize(
const config = {
extends: tsconfig,
compilerOptions: { noEmit: true },
- include: ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"],
+ include: ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts", "**/*.astro"],
exclude: [],
};
writeFileSync(join(scratch, "tsconfig.json"), `${JSON.stringify(config, null, 2)}\n`);
diff --git a/src/laws/probe/types.ts b/src/laws/probe/types.ts
index ec5d38d..0f21b5c 100644
--- a/src/laws/probe/types.ts
+++ b/src/laws/probe/types.ts
@@ -72,6 +72,12 @@ export interface LawProbe {
readonly unrelated: readonly Observed[];
}
+/** A twin the probe left out of the run, and why: a skip is always said, never silent. */
+export interface SkippedTwin extends Twin {
+ readonly reason: string;
+}
+
export interface ProbeReport {
readonly laws: readonly LawProbe[];
+ readonly skipped: readonly SkippedTwin[];
}