From 50f6b61176cfddbf2856a1ca47cc4004f59dcf3f Mon Sep 17 00:00:00 2001 From: VirtualMachinist Date: Fri, 20 Nov 2026 07:27:51 -0500 Subject: [PATCH 1/4] Let a law's rule entry name the classes it applies to, and list W-22's Astro a11y rules (R106) A rule entry in laws/W-NN.yaml takes an optional classes list, a subset of the law's classes: without it the rule applies to every class the law maps. The schema, the loader type and the validator (which fails a class outside the law's) carry it, laws explain shows it, and section 8.3 describes it. W-22 lists the 31 astro/jsx-a11y rules that eslint-plugin-astro's strict a11y config enables, each for astro-site only; a test keeps the list equal to the plugin's. The ESLint reader and the probe honour the field in the step that follows; until then `laws probe` still treats the new rules as owed to every class W-22 maps. Co-Authored-By: Claude Sonnet 5.5 --- WEB_TOPS.md | 3 +- laws/W-22.yaml | 31 ++++++++++++++++ schema/law.schema.json | 9 ++++- src/laws/catalog/rule-classes.test.ts | 51 +++++++++++++++++++++++++++ src/laws/catalog/schema.test.ts | 20 +++++++++++ src/laws/catalog/schema.ts | 15 ++++++-- src/laws/catalog/types.ts | 2 ++ src/laws/catalog/view.test.ts | 6 ++++ src/laws/catalog/view.ts | 8 +++-- 9 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 src/laws/catalog/rule-classes.test.ts diff --git a/WEB_TOPS.md b/WEB_TOPS.md index 0bd97c2..b18d191 100644 --- a/WEB_TOPS.md +++ b/WEB_TOPS.md @@ -829,7 +829,8 @@ fails the catalog, and so every `laws` command. Fields: - `classes`, the launch classes that map the law (§5.2), and `conditional_classes`, those among them that map it only when the project depends on Astro; - `reader`: `kinds`, from `tl`, `an`, `at` and `tbd` (§8.1), and `text`, the Reader cell of §8.2; -- `rules`: each tool rule, flag or check the law maps, as a `tool` and a `name`; +- `rules`: each tool rule, flag or check the law maps, as a `tool` and a `name`, and an optional + `classes`, the classes among the law's that the rule applies to (absent: every class the law maps); - `judged`: `v0.1` for a law ticked in §8.2, `m3` for a law M3 gives a reader, `no` for the rest; - `rationale`, `fix` and an optional `note`. diff --git a/laws/W-22.yaml b/laws/W-22.yaml index 818eba7..2ed38be 100644 --- a/laws/W-22.yaml +++ b/laws/W-22.yaml @@ -13,6 +13,37 @@ rules: - { tool: eslint, name: "jsx-a11y-x/no-static-element-interactions" } - { tool: eslint, name: "jsx-a11y-x/click-events-have-key-events" } - { tool: eslint, name: "jsx-a11y-x/anchor-is-valid" } + - { tool: eslint, name: "astro/jsx-a11y/alt-text", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/anchor-has-content", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/anchor-is-valid", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/aria-activedescendant-has-tabindex", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/aria-props", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/aria-proptypes", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/aria-role", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/aria-unsupported-elements", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/autocomplete-valid", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/click-events-have-key-events", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/heading-has-content", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/html-has-lang", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/iframe-has-title", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/img-redundant-alt", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/interactive-supports-focus", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/label-has-associated-control", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/media-has-caption", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/mouse-events-have-key-events", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/no-access-key", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/no-autofocus", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/no-distracting-elements", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/no-interactive-element-to-noninteractive-role", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/no-noninteractive-element-interactions", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/no-noninteractive-element-to-interactive-role", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/no-noninteractive-tabindex", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/no-redundant-roles", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/no-static-element-interactions", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/role-has-required-aria-props", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/role-supports-aria-props", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/scope", classes: [astro-site] } + - { tool: eslint, name: "astro/jsx-a11y/tabindex-no-positive", classes: [astro-site] } - { tool: html-validate, name: "a11y" } - { tool: axe, name: "axe" } judged: v0.1 diff --git a/schema/law.schema.json b/schema/law.schema.json index 1a1bcdc..5d99f66 100644 --- a/schema/law.schema.json +++ b/schema/law.schema.json @@ -71,7 +71,14 @@ "additionalProperties": false, "properties": { "tool": { "type": "string", "minLength": 1 }, - "name": { "type": "string", "minLength": 1 } + "name": { "type": "string", "minLength": 1 }, + "classes": { + "description": "The classes in the law's `classes` this rule applies to. Absent: every class the law maps.", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { "$ref": "#/$defs/class" } + } } } }, diff --git a/src/laws/catalog/rule-classes.test.ts b/src/laws/catalog/rule-classes.test.ts new file mode 100644 index 0000000..0441a9b --- /dev/null +++ b/src/laws/catalog/rule-classes.test.ts @@ -0,0 +1,51 @@ +import astro from "eslint-plugin-astro"; +import { join, resolve } from "node:path"; +import { describe, expect, it } from "vitest"; +import { loadCatalog } from "./load.ts"; + +const ROOT = resolve(import.meta.dirname, "../../.."); +const PREFIX = "astro/jsx-a11y/"; + +function w22Rules() { + const loaded = loadCatalog(join(ROOT, "laws")); + if (!loaded.ok) throw new Error(loaded.problems.map((found) => found.message).join("; ")); + const found = loaded.laws.find((law) => law.id === "W-22"); + if (found === undefined) throw new Error("no W-22"); + return found.rules; +} + +const levelOf = (setting: unknown): unknown => (Array.isArray(setting) ? setting[0] : setting); + +/** The astro a11y rules its strict config turns on: the plugin says which they are. */ +const ENABLED = astro.configs["flat/jsx-a11y-strict"] + .flatMap((entry) => Object.entries(entry.rules ?? {})) + .filter( + ([name, setting]) => name.startsWith(PREFIX) && ![0, "off"].includes(String(levelOf(setting))), + ) + .map(([name]) => name) + .sort(); + +describe("R106: W-22 maps the astro a11y rules to astro-site only", () => { + it("lists exactly the 31 rules the plugin's strict a11y config enables, each for astro-site", () => { + const mapped = w22Rules().filter((rule) => rule.name.startsWith(PREFIX)); + expect(mapped.map((rule) => rule.name).sort()).toEqual(ENABLED); + expect(ENABLED).toHaveLength(31); + for (const rule of mapped) { + expect(rule, rule.name).toMatchObject({ tool: "eslint", classes: ["astro-site"] }); + } + }); + + it("leaves the jsx-a11y-x rules, and the built-page checks, for every class the law maps", () => { + const others = w22Rules().filter((rule) => !rule.name.startsWith(PREFIX)); + expect(others.map((rule) => rule.name)).toEqual([ + "jsx-a11y-x/alt-text", + "jsx-a11y-x/label-has-associated-control", + "jsx-a11y-x/no-static-element-interactions", + "jsx-a11y-x/click-events-have-key-events", + "jsx-a11y-x/anchor-is-valid", + "a11y", + "axe", + ]); + for (const rule of others) expect(rule.classes, rule.name).toBeUndefined(); + }); +}); diff --git a/src/laws/catalog/schema.test.ts b/src/laws/catalog/schema.test.ts index 5eb3520..6584f89 100644 --- a/src/laws/catalog/schema.test.ts +++ b/src/laws/catalog/schema.test.ts @@ -86,6 +86,26 @@ describe("validateLaw (G1a: an invalid file fails)", () => { expect(problemsOf(lawWith({ conditional_classes: [] }))).toHaveLength(1); }); + it("accepts a rule's classes among the law's, and fails one that is not, an empty list and a repeat", () => { + const withRule = (classes: unknown): unknown => + lawWith({ + classes: ["web-app", "astro-site"], + conditional_classes: undefined, + rules: [ + { tool: "eslint", name: "a/b" }, + { tool: "eslint", name: "c/d", classes }, + ], + }); + expect(problemsOf(withRule(["astro-site"]))).toEqual([]); + expect(problemsOf(withRule(["ui-components"]))).toEqual([ + "/rules/1/classes ui-components is not in classes", + ]); + expect(problemsOf(withRule([]))).toHaveLength(1); + expect(problemsOf(withRule(["astro-site", "astro-site"]))).toHaveLength(1); + expect(problemsOf(withRule(["cli"]))).toHaveLength(1); + expect(problemsOf(withRule("astro-site"))).toHaveLength(1); + }); + it("fails a severity, a judged value and an id the schema does not allow", () => { expect(problemsOf(lawWith({ severity: "X" }))).toHaveLength(1); expect(problemsOf(lawWith({ judged: "yes" }))).toHaveLength(1); diff --git a/src/laws/catalog/schema.ts b/src/laws/catalog/schema.ts index f9d683f..0bede3e 100644 --- a/src/laws/catalog/schema.ts +++ b/src/laws/catalog/schema.ts @@ -11,9 +11,20 @@ const strays = (law: Law): Problem[] => .filter((name) => !law.classes.includes(name)) .map((name) => ({ pointer: "/conditional_classes", message: `${name} is not in classes` })); -/** Validates one parsed law file against `schema/law.schema.json`, and the one rule a schema cannot state. */ +/** A rule's classes must be among the law's: a schema cannot say that either. */ +const ruleStrays = (law: Law): Problem[] => + law.rules.flatMap((rule, index) => + (rule.classes ?? []) + .filter((name) => !law.classes.includes(name)) + .map((name) => ({ + pointer: `/rules/${String(index)}/classes`, + message: `${name} is not in classes`, + })), + ); + +/** Validates one parsed law file against `schema/law.schema.json`, and the rules a schema cannot state. */ export function validateLaw(value: unknown): Validated { if (!validate(value)) return { ok: false, problems: toProblems(validate.errors) }; - const problems = strays(value); + const problems = [...strays(value), ...ruleStrays(value)]; return problems.length === 0 ? { ok: true, value } : { ok: false, problems }; } diff --git a/src/laws/catalog/types.ts b/src/laws/catalog/types.ts index 8cd395a..6d33770 100644 --- a/src/laws/catalog/types.ts +++ b/src/laws/catalog/types.ts @@ -19,6 +19,8 @@ export type Judged = "v0.1" | "m3" | "no"; export interface LawRule { readonly tool: string; readonly name: string; + /** The classes the rule applies to, among the law's: absent, every class the law maps. */ + readonly classes?: readonly LawClass[]; } /** One law, as `laws/W-NN.yaml` holds it (WEB_TOPS.md section 8.3, `schema/law.schema.json`). */ diff --git a/src/laws/catalog/view.test.ts b/src/laws/catalog/view.test.ts index f3660b8..4d080e9 100644 --- a/src/laws/catalog/view.test.ts +++ b/src/laws/catalog/view.test.ts @@ -57,6 +57,12 @@ describe("listText", () => { }); describe("explainText", () => { + it("says which classes a rule applies to when it does not apply to all of the law's", () => { + const text = explainText(law("W-22")); + expect(text).toContain("\n eslint astro/jsx-a11y/alt-text (astro-site only)\n"); + expect(text).toContain("\n eslint jsx-a11y-x/alt-text\n"); + }); + it("prints every field of a law, one line each", () => { const text = explainText(law("W-01")); const lines = text.split("\n"); diff --git a/src/laws/catalog/view.ts b/src/laws/catalog/view.ts index 68dd1c8..40f4b0c 100644 --- a/src/laws/catalog/view.ts +++ b/src/laws/catalog/view.ts @@ -1,6 +1,6 @@ import { isConditional } from "./query.ts"; import type { Filter } from "./query.ts"; -import type { Judged, Law } from "./types.ts"; +import type { Judged, Law, LawRule } from "./types.ts"; const SEVERITY: Readonly> = { R: "a break is refuse", @@ -41,11 +41,15 @@ const classText = (law: Law): string => .map((name) => (isConditional(law, name) ? `${name} (${ASTRO_ONLY})` : name)) .join(", "); +/** A rule that applies to some of the law's classes only says which. */ +const ruleClasses = (rule: LawRule): string => + rule.classes === undefined ? "" : ` (${rule.classes.join(", ")} only)`; + /** The rules a law maps: one line each under `rules:`, or `none` after it. */ const rulesText = (law: Law): string => law.rules.length === 0 ? " none" - : law.rules.map((rule) => `\n ${rule.tool} ${rule.name}`).join(""); + : law.rules.map((rule) => `\n ${rule.tool} ${rule.name}${ruleClasses(rule)}`).join(""); /** `laws explain`: every field of section 8.3, one line each, with the reader and rules spelled out. */ export function explainText(law: Law): string { From ae2ad888efd48a1df6bdac46fef63e7e79ff8b52 Mon Sep 17 00:00:00 2001 From: VirtualMachinist Date: Fri, 20 Nov 2026 08:54:10 -0500 Subject: [PATCH 2/4] Let the probe prove a rule only for the classes its entry names (R106) The probe took every rule of a law as owed to every class the law maps, so W-22's Astro rules were demanded under web-app and ui-components too. A probe law now carries the classes of each rule whose entry names some, and the laws of a class keep only the proofs that apply to it. The W-22 rule list test keeps its own five rules apart from Astro's, which rule-classes.test.ts checks. Co-Authored-By: Claude Sonnet 5.5 --- laws/W-22.yaml | 24 ++++++++++++++++++++---- src/laws/catalog/catalog.test.ts | 5 +++-- src/laws/probe/catalog.test.ts | 25 +++++++++++++++++++++++++ src/laws/probe/catalog.ts | 16 ++++++++++++++-- src/laws/probe/source.test.ts | 19 +++++++++++++++++++ src/laws/probe/source.ts | 14 +++++++++++++- src/laws/probe/types.ts | 2 ++ 7 files changed, 96 insertions(+), 9 deletions(-) diff --git a/laws/W-22.yaml b/laws/W-22.yaml index 2ed38be..59b1468 100644 --- a/laws/W-22.yaml +++ b/laws/W-22.yaml @@ -16,7 +16,11 @@ rules: - { tool: eslint, name: "astro/jsx-a11y/alt-text", classes: [astro-site] } - { tool: eslint, name: "astro/jsx-a11y/anchor-has-content", classes: [astro-site] } - { tool: eslint, name: "astro/jsx-a11y/anchor-is-valid", classes: [astro-site] } - - { tool: eslint, name: "astro/jsx-a11y/aria-activedescendant-has-tabindex", classes: [astro-site] } + - { + tool: eslint, + name: "astro/jsx-a11y/aria-activedescendant-has-tabindex", + classes: [astro-site], + } - { tool: eslint, name: "astro/jsx-a11y/aria-props", classes: [astro-site] } - { tool: eslint, name: "astro/jsx-a11y/aria-proptypes", classes: [astro-site] } - { tool: eslint, name: "astro/jsx-a11y/aria-role", classes: [astro-site] } @@ -34,9 +38,21 @@ rules: - { tool: eslint, name: "astro/jsx-a11y/no-access-key", classes: [astro-site] } - { tool: eslint, name: "astro/jsx-a11y/no-autofocus", classes: [astro-site] } - { tool: eslint, name: "astro/jsx-a11y/no-distracting-elements", classes: [astro-site] } - - { tool: eslint, name: "astro/jsx-a11y/no-interactive-element-to-noninteractive-role", classes: [astro-site] } - - { tool: eslint, name: "astro/jsx-a11y/no-noninteractive-element-interactions", classes: [astro-site] } - - { tool: eslint, name: "astro/jsx-a11y/no-noninteractive-element-to-interactive-role", classes: [astro-site] } + - { + tool: eslint, + name: "astro/jsx-a11y/no-interactive-element-to-noninteractive-role", + classes: [astro-site], + } + - { + tool: eslint, + name: "astro/jsx-a11y/no-noninteractive-element-interactions", + classes: [astro-site], + } + - { + tool: eslint, + name: "astro/jsx-a11y/no-noninteractive-element-to-interactive-role", + classes: [astro-site], + } - { tool: eslint, name: "astro/jsx-a11y/no-noninteractive-tabindex", classes: [astro-site] } - { tool: eslint, name: "astro/jsx-a11y/no-redundant-roles", classes: [astro-site] } - { tool: eslint, name: "astro/jsx-a11y/no-static-element-interactions", classes: [astro-site] } diff --git a/src/laws/catalog/catalog.test.ts b/src/laws/catalog/catalog.test.ts index b359f5c..15973eb 100644 --- a/src/laws/catalog/catalog.test.ts +++ b/src/laws/catalog/catalog.test.ts @@ -226,8 +226,9 @@ describe("the rules a law names, for the law probe", () => { expect(rulesOf("W-26", "stylelint")).toHaveLength(8); }); - it("names for W-22 the click and anchor rules beside alt, label and static-element rules", () => { - expect(rulesOf("W-22", "eslint")).toEqual([ + it("names for W-22 the click and anchor rules beside alt, label and static-element rules, and Astro's own beside them", () => { + const own = rulesOf("W-22", "eslint").filter((name) => !name.startsWith("astro/jsx-a11y/")); + expect(own).toEqual([ "jsx-a11y-x/alt-text", "jsx-a11y-x/label-has-associated-control", "jsx-a11y-x/no-static-element-interactions", diff --git a/src/laws/probe/catalog.test.ts b/src/laws/probe/catalog.test.ts index 19ea4f4..3226283 100644 --- a/src/laws/probe/catalog.test.ts +++ b/src/laws/probe/catalog.test.ts @@ -49,6 +49,31 @@ describe("G3a the laws the probe proves are the catalog's ticked lint and compil }); }); +describe("R106 a law's proofs under a class are the rules that apply to it", () => { + const law = { + id: "W-91", + classes: ["ui-components", "astro-site"], + proofs: ["jsx-a11y-x/alt-text", "astro/jsx-a11y/alt-text"], + scoped: { "astro/jsx-a11y/alt-text": ["astro-site"] }, + }; + const proofsOf = (className: string): string[] => + lawsOfClass([law], className).flatMap((found) => found.proofs); + + it("keeps a rule that names classes only for those, and every other rule for every class", () => { + expect(proofsOf("astro-site")).toEqual(["jsx-a11y-x/alt-text", "astro/jsx-a11y/alt-text"]); + expect(proofsOf("ui-components")).toEqual(["jsx-a11y-x/alt-text"]); + }); + + it("still maps no law for a class the law does not list", () => { + expect(proofsOf("web-app")).toEqual([]); + }); + + it("takes a law with no scopes as it is", () => { + const plain = { id: "W-92", proofs: ["a", "b"] }; + expect(lawsOfClass([plain], "ui-components")).toEqual([plain]); + }); +}); + const bad: Catalog = { ok: false, problems: [ diff --git a/src/laws/probe/catalog.ts b/src/laws/probe/catalog.ts index a927fd3..9e8ea53 100644 --- a/src/laws/probe/catalog.ts +++ b/src/laws/probe/catalog.ts @@ -18,6 +18,18 @@ export function readCatalog(dir: string = CATALOG_DIR, load: typeof loadCatalog /** The laws the probe proves: the ticked laws a lint rule or a compiler flag judges, read from the catalog. */ export const catalogLaws: LawSource = sourceOf(readCatalog); -/** The laws a class maps (`classes` in each law's file); a law with no class list is mapped by every class. */ +const mapsClass = (law: ProbeLaw, className: string): boolean => + law.classes === undefined || law.classes.includes(className); + +/** The proofs of a law that apply to a class: a rule whose entry names classes (R106) is proven only for those. */ +const proofsFor = (law: ProbeLaw, className: string): ProbeLaw => ({ + ...law, + proofs: law.proofs.filter((proof) => law.scoped?.[proof]?.includes(className) ?? true), +}); + +/** + * The laws a class maps (`classes` in each law's file; a law with no class list is mapped by every class), each with + * the proofs that apply to the class. + */ export const lawsOfClass = (list: readonly ProbeLaw[], className: string): ProbeLaw[] => - list.filter((law) => law.classes === undefined || law.classes.includes(className)); + list.filter((law) => mapsClass(law, className)).map((law) => proofsFor(law, className)); diff --git a/src/laws/probe/source.test.ts b/src/laws/probe/source.test.ts index 7e55770..a0248ad 100644 --- a/src/laws/probe/source.test.ts +++ b/src/laws/probe/source.test.ts @@ -46,6 +46,7 @@ describe("G3a the laws the probe proves are read from the catalog's records", () id: "W-01", classes: ["ts-library", "web-app"], proofs: ["@typescript-eslint/no-explicit-any", "noImplicitAny"], + scoped: {}, }); expect(isProbed(W01)).toBe(true); }); @@ -84,6 +85,24 @@ describe("G3a the laws the probe proves are read from the catalog's records", () }); }); +describe("R106 a rule whose entry names classes is scoped to them", () => { + const record: LawRecord = { + id: "W-91", + classes: ["ui-components", "astro-site"], + judged: "v0.1", + rules: [ + { tool: "eslint", name: "jsx-a11y-x/alt-text" }, + { tool: "eslint", name: "astro/jsx-a11y/alt-text", classes: ["astro-site"] }, + { tool: "axe", name: "axe", classes: ["astro-site"] }, + ], + }; + + it("lists the classes of each probed rule that has them, and leaves the other rules out", () => { + expect(toProbeLaw(record).scoped).toEqual({ "astro/jsx-a11y/alt-text": ["astro-site"] }); + expect(toProbeLaw(W01).scoped).toEqual({}); + }); +}); + describe("G3a the tools whose rules a twin can fire", () => { const law = (tool: string): LawRecord => ({ id: "W-90", diff --git a/src/laws/probe/source.ts b/src/laws/probe/source.ts index 1333efd..f2ab289 100644 --- a/src/laws/probe/source.ts +++ b/src/laws/probe/source.ts @@ -5,7 +5,11 @@ export interface LawRecord { readonly id: string; readonly classes: readonly string[]; readonly judged: string; - readonly rules: readonly { readonly tool: string; readonly name: string }[]; + readonly rules: readonly { + readonly tool: string; + readonly name: string; + readonly classes?: readonly string[]; + }[]; } /** The tools whose rules a twin can fire: a lint config, the compiler's flags, and Stylelint. */ @@ -30,11 +34,19 @@ export function isProbed(law: LawRecord): boolean { return law.judged === "v0.1" && rules.length > 0 && !rules.some((rule) => isCustom(rule.name)); } +/** The classes a rule applies to, by its name: only a rule whose entry has `classes` (R106) is listed. */ +function scopesOf(rules: LawRecord["rules"]): Record { + return Object.fromEntries( + rules.flatMap((rule) => (rule.classes === undefined ? [] : [[rule.name, rule.classes]])), + ); +} + /** A law as the probe takes it: what its tool rules and flags name are what its twins must prove. */ export const toProbeLaw = (law: LawRecord): ProbeLaw => ({ id: law.id, classes: law.classes, proofs: law.rules.filter(probed).map((rule) => rule.name), + scoped: scopesOf(law.rules.filter(probed)), }); /** The probe's laws out of the catalog's records, in id order. */ diff --git a/src/laws/probe/types.ts b/src/laws/probe/types.ts index ec5d38d..9a123b4 100644 --- a/src/laws/probe/types.ts +++ b/src/laws/probe/types.ts @@ -13,6 +13,8 @@ export interface ProbeLaw { readonly proofs: readonly string[]; /** The classes that map the law (WEB_TOPS.md section 5.2); absent for a law every class maps. */ readonly classes?: readonly string[]; + /** The classes a rule applies to, by proof, where its entry names them (R106); any other proof is proven for every class. */ + readonly scoped?: Readonly>; } /** Where the laws come from. `laws/W-NN.yaml` is the source once it lands; until then, the interim table. */ From fb79f8fd2d372c4f2667263b218ccd46bd3166cf Mon Sep 17 00:00:00 2001 From: VirtualMachinist Date: Fri, 20 Nov 2026 09:00:17 -0500 Subject: [PATCH 3/4] Test the list of classes a rule names in laws explain (R106) A rule that names several classes prints them comma separated; no test had a rule with more than one, so the separator could be emptied unseen. Co-Authored-By: Claude Sonnet 5.5 --- src/laws/catalog/view.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/laws/catalog/view.test.ts b/src/laws/catalog/view.test.ts index 4d080e9..64ec93c 100644 --- a/src/laws/catalog/view.test.ts +++ b/src/laws/catalog/view.test.ts @@ -63,6 +63,15 @@ describe("explainText", () => { expect(text).toContain("\n eslint jsx-a11y-x/alt-text\n"); }); + it("lists each class of a rule that names several, comma separated", () => { + const base = law("W-22"); + const text = explainText({ + ...base, + rules: [{ tool: "eslint", name: "some-rule", classes: ["astro-site", "web-app"] }], + }); + expect(text).toContain("\n eslint some-rule (astro-site, web-app only)\n"); + }); + it("prints every field of a law, one line each", () => { const text = explainText(law("W-01")); const lines = text.split("\n"); From 6e922cd53399a41f170992f81b7078bee6233b34 Mon Sep 17 00:00:00 2001 From: VirtualMachinist Date: Fri, 20 Nov 2026 09:58:57 -0500 Subject: [PATCH 4/4] Give W-22 the Astro twins that prove its astro/jsx-a11y rules (R106) W-22 now maps 31 astro/jsx-a11y rules for astro-site, so under that class the probe owes a bad twin that fires each. One .astro bad twin carries a line per rule with its marker, and a clean twin holds the valid forms. Co-Authored-By: Claude Sonnet 5.5 --- fixtures/laws/W-22/bad/astro-semantics.astro | 65 +++++++++++++++++++ .../laws/W-22/clean/astro-semantics.astro | 16 +++++ 2 files changed, 81 insertions(+) create mode 100644 fixtures/laws/W-22/bad/astro-semantics.astro create mode 100644 fixtures/laws/W-22/clean/astro-semantics.astro diff --git a/fixtures/laws/W-22/bad/astro-semantics.astro b/fixtures/laws/W-22/bad/astro-semantics.astro new file mode 100644 index 0000000..29d3daa --- /dev/null +++ b/fixtures/laws/W-22/bad/astro-semantics.astro @@ -0,0 +1,65 @@ +--- +const handler = () => undefined; +--- + + + + + +go + +
+ +
+ +
+ +
+ + + + + +
go
+ +

+ + + + + +image of a dog + +
go
+ + + + + +
+ +
+ + + +go + + + +

go

+ +

go

+ +
+ + + +go + +
+ +
go
+ +
+ +
diff --git a/fixtures/laws/W-22/clean/astro-semantics.astro b/fixtures/laws/W-22/clean/astro-semantics.astro new file mode 100644 index 0000000..56093c8 --- /dev/null +++ b/fixtures/laws/W-22/clean/astro-semantics.astro @@ -0,0 +1,16 @@ +--- +const handler = () => undefined; +--- +A mountain at dusk +go + + +

Title

+ + +
go
+
+ + +
A
+