@terpjs/eslint-boundaries 0.37.0 → 0.39.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.
@@ -0,0 +1,21 @@
1
+ {
2
+ "id": "frontend/escape-hatch",
3
+ "surface": "frontend",
4
+ "title": "Every opt-out marker is justified and governed by the budget ratchet",
5
+ "intent": "The one opt-out is a justified inline marker naming the rule; an unjustified marker is itself an error, and marker counts must exactly match the app's checked-in escape-hatch budget so opt-outs stay visible and can only shrink.",
6
+ "layer": "static-bespoke",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "terp/escape-hatch",
12
+ "reported_as": "terp/escape-hatch"
13
+ }
14
+ ],
15
+ "reference": "// terp-allow-<rule>: <reason> markers reconciled against the app's checked-in escape-hatch-budget.json (ADR 0059). The rule carries no opt_out: governance cannot be waived by the mechanism it governs.",
16
+ "runtime": {
17
+ "applicability": "not-applicable",
18
+ "rationale": "Markers and budgets are source/repository artifacts; the built bundle retains neither. The controls the markers opt out of keep their own runtime halves regardless."
19
+ },
20
+ "corpus": true
21
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "id": "frontend/generated-client-only",
3
+ "surface": "frontend",
4
+ "title": "All network egress goes through the generated, typed client",
5
+ "intent": "Raw fetch / XMLHttpRequest / WebSocket / EventSource (and navigator.sendBeacon) bypass the app's single audited, typed egress path. One client means one place for auth, errors, and contract types. The refused globals and member calls are declared in restricted-surface.json (restrictedGlobals, restrictedMemberCalls).",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "BOUNDARY_SPEC.restrictedGlobals",
12
+ "reported_as": "no-restricted-globals"
13
+ }
14
+ ],
15
+ "reference": "useTerpClient() + unwrap from @terpjs/react-core for request/response; useRealtimeChannel() from @terpjs/react-core for typed SSE/WebSocket subscriptions (one-use ticket minted through the generated client).",
16
+ "opt_out": "// terp-allow-generated-client-only: <reason>",
17
+ "runtime": {
18
+ "applicability": "not-applicable",
19
+ "rationale": "In the running bundle the sanctioned generated client is itself built on fetch, so egress-primitive use cannot be attributed to an app module from inside the app. One typed egress path is an authoring contract; network policy beyond it (CSP connect-src) is deployment configuration the framework does not own per module."
20
+ },
21
+ "restricted_surface": [
22
+ "restrictedGlobals",
23
+ "restrictedMemberCalls"
24
+ ],
25
+ "corpus": true
26
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "id": "frontend/layout-contract",
3
+ "surface": "frontend",
4
+ "title": "An opted-in app's archetype body slots accept only the contract's components",
5
+ "intent": "With a checked-in layout declaration, each page archetype's body slot is constrained to the contract's sanctioned components, so screens stay structurally consistent and the failure message tells an agent exactly how to build the screen. Paired with the fail-closed runtime check on the rendered slot. The declaration is the single source for the opt-in, for the palette the app opens on, and for the shell's own shape down to the navigation groups a module's items name by id and the mark the app is recognised by (layout-declaration.schema.json): a build-time checker and the running app read the same document, so neither can enforce a contract the other does not, and a key declared both in the document and in the app's own code is refused rather than resolved by an invisible precedence.",
6
+ "layer": "static-bespoke",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "terp/layout-contract",
12
+ "reported_as": "terp/layout-contract"
13
+ },
14
+ {
15
+ "kind": "runtime",
16
+ "tool": "@terpjs/react-core",
17
+ "ref": "verifySlotChildren"
18
+ }
19
+ ],
20
+ "opt_out": "// terp-allow-layout-contract: <reason>",
21
+ "reference": "frontend/layout-contract.json, the document layout-declaration.schema.json describes (ADR 0079); the app imports it and the reference stack's bootstrap resolves it, refusing an unknown key, a value outside its enum, and any key declared twice. The per-stack values: contracts are the keys of LAYOUT_CONTRACTS in @terpjs/react-core, and defaultTheme names one of the palettes @terpjs/contract compiles or the reserved system. Neither list is written out here: the contract ids and the palette names both live in @terpjs/react-core's published layout.manifest.json, with the values filled in for the release an app is pinned to, and every copy of them in that stack is gated against it. A fourth copy in this field would be the one nothing checks, and it would sit in the very field this schema points a reader at for the truth. shell.navGroups is groupNav's group table in @terpjs/react-core, whose NavItem.group references it; shell.brand names paths Vite serves from the app's own frontend/public, rendered into AppShell's logo and logoDark slots. verifySlotChildren in @terpjs/react-core is the runtime DOM check.",
22
+ "runtime": {
23
+ "applicability": "required"
24
+ },
25
+ "corpus": true
26
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "id": "frontend/locale-catalogs-complete",
3
+ "surface": "frontend",
4
+ "title": "Every declared target locale translates every authored message",
5
+ "intent": "Every stable user-interface message identifier must have a non-empty translation in every declared target locale. A missing or malformed catalog, empty entries, and undocumented source-language copies fail the gate instead of silently rendering source-language text after a user switches locale. A descriptor is written where it is used, with its identifier and source message as literals: a function that builds one from its own parameters is refused, because every call through it carries its copy in the call's arguments, where the inventory never looks, so a missing translation would pass. A record built from data (from a member of the record, a destructured object, or a key into data) is not a descriptor factory and is not refused.",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "terp/locale-catalogs-complete"
12
+ },
13
+ {
14
+ "kind": "runtime",
15
+ "tool": "@terpjs/react-core",
16
+ "ref": "LocaleProvider"
17
+ }
18
+ ],
19
+ "reference": "Declare sourceLocale and locale message maps in frontend/i18n.json; the boundary rule and defineAppLocales validate that declaration, while LocaleProvider refuses missing target entries at render time. Write { id: \"...\", message: \"...\" } or Trans where the text is used; a positional helper such as (id, message) => ({ id, message }) is reported.",
20
+ "opt_out": "// terp-allow-locale-catalogs-complete: <reason>",
21
+ "runtime": {
22
+ "applicability": "required",
23
+ "rationale": "The locale provider owns descriptor resolution and can distinguish source fallback from a missing target entry, including dynamically assembled identifiers that a static check cannot see."
24
+ },
25
+ "corpus": true
26
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "id": "frontend/no-cross-module-imports",
3
+ "surface": "frontend",
4
+ "title": "An app module never imports a sibling module",
5
+ "intent": "Modules couple only through the platform packages and their own files. A sibling import — static, dynamic import(), relative or via the app alias — creates hidden coupling that breaks module isolation and independent evolution.",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "terp/no-cross-module-imports",
12
+ "reported_as": "terp/no-cross-module-imports"
13
+ }
14
+ ],
15
+ "opt_out": "// terp-allow-no-cross-module-imports: <reason>",
16
+ "runtime": {
17
+ "applicability": "not-applicable",
18
+ "rationale": "Module independence is an import-graph property of the source tree; the bundler merges every module into one dependency graph, after which a cross-module edge is indistinguishable from composition."
19
+ },
20
+ "corpus": true
21
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "id": "frontend/no-deep-imports",
3
+ "surface": "frontend",
4
+ "title": "App modules import platform packages from the root only",
5
+ "intent": "A deep import into a platform package's internals couples the app to files that are free to move; the package root is the published, stable surface. The refused path segments are declared in restricted-surface.json (deepImportPathSegments).",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "BOUNDARY_SPEC.internalImportPatterns",
12
+ "reported_as": "no-restricted-imports"
13
+ }
14
+ ],
15
+ "reference": "@terpjs/*/src/* and @terpjs/*/dist/* imports are refused; import from the @terpjs/* package root.",
16
+ "opt_out": "// terp-allow-no-deep-imports: <reason>",
17
+ "runtime": {
18
+ "applicability": "not-applicable",
19
+ "rationale": "Package-boundary form: the bundler resolves and inlines whatever was imported, and the built artifact retains no distinction between a root import and a deep one."
20
+ },
21
+ "restricted_surface": [
22
+ "deepImportPathSegments"
23
+ ],
24
+ "corpus": true
25
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "id": "frontend/no-dom-html-injection",
3
+ "surface": "frontend",
4
+ "title": "DOM HTML-injection sinks are refused in app modules",
5
+ "intent": "dangerouslySetInnerHTML, innerHTML/outerHTML assignment, insertAdjacentHTML and document.write inject markup that bypasses the framework's output escaping — the canonical XSS sink. Rich text renders through the stack's sanctioned rich-text component instead.",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "terp/no-dom-html-injection",
12
+ "reported_as": "terp/no-dom-html-injection"
13
+ }
14
+ ],
15
+ "reference": "The Markdown component from @terpjs/react-core for rich text.",
16
+ "opt_out": "// terp-allow-no-dom-html-injection: <reason>",
17
+ "runtime": {
18
+ "applicability": "not-applicable",
19
+ "rationale": "The sinks are platform primitives on every element; React's default output escaping is the ambient constructive protection and the sanctioned Markdown component sanitises rich text. A runtime hook over every element's HTML mutation is not a seam react-core owns or could make sound -- vendored code legitimately uses the same primitives."
20
+ },
21
+ "corpus": true
22
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "id": "frontend/no-eval",
3
+ "surface": "frontend",
4
+ "title": "eval() and new Function() are refused in app modules",
5
+ "intent": "Runtime code evaluation defeats every static guarantee the boundary provides and is a classic injection primitive. There is no sanctioned dynamic-code path in an app module.",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "terp/no-eval",
12
+ "reported_as": "terp/no-eval"
13
+ }
14
+ ],
15
+ "opt_out": "// terp-allow-no-eval: <reason>",
16
+ "runtime": {
17
+ "applicability": "not-applicable",
18
+ "rationale": "The prohibition is on authoring dynamic-code primitives in app modules \u2014 a source-form fact. In the running bundle the primitive itself is a platform global the framework cannot remove, and legitimately vendored code may reference it, so a runtime hook cannot attribute authorship to an app module. Deployment-level CSP can harden the served app, but it is deployment configuration, not a control this framework owns per rule."
19
+ },
20
+ "corpus": true
21
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "id": "frontend/no-framework-markers",
3
+ "surface": "frontend",
4
+ "title": "App-authored source never writes the stack's component markers",
5
+ "intent": "A conformant stack's components mark the element each of them renders with an identity attribute, and two of the stack's own controls trust that marker: its stylesheet selects on it, and the runtime half of layout-contract identifies a slot's children by it. Anywhere in app-authored frontend source, those markers are never written: not as an attribute in markup, not as the key of a properties object spread onto an element, and not by setting the attribute on an element through the DOM. A hand-written marker borrows a component's styling without composing the component, which gets around no-inline-styling by another door, and it passes the runtime slot check as the component it names while being something else. The markers are the stack's inventory, and only the stack writes them. An app that replaces one of the stack's own screens owns that screen: it composes the stack's components where it wants their look, and its tests locate the screen by the roles and accessible names it renders, never by forging the markers the stack's own screen carries. Any other data attribute an app writes for itself, such as a test identifier, is out of scope.",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "terp/no-framework-markers"
12
+ }
13
+ ],
14
+ "reference": "The reference stack's markers are `data-terp` and every `data-terp-*` attribute, which the components of @terpjs/react-core stamp on the elements they render; its stylesheet is keyed on them (`[data-terp=\"card\"]`) and verifySlotChildren reads them. The check refuses the name as a JSX attribute on any element or component, as the key of an object literal (an inline spread, a hoisted props object, a createElement props bag), and as a literal name passed to `setAttribute`, `setAttributeNS` or `toggleAttribute`, matching it case-insensitively because the DOM lowercases an attribute name written on an HTML element; it also refuses an assignment to a `dataset` key in the same namespace (`dataset.terp`, `dataset.terpPreviewPick`). Reading a marker is not reported. The compliant shape is the component itself (`Card`, `Stack`, ...); an app that passes its own screen to `renderTerpApp({ login })` writes its sign-in steps against that screen's roles and accessible names.",
15
+ "opt_out": "// terp-allow-no-framework-markers: <reason>",
16
+ "runtime": {
17
+ "applicability": "not-applicable",
18
+ "rationale": "A marker in the rendered page is the same attribute whichever code wrote it: the stack's own components stamp it on every element they render, so its presence at runtime is legitimate and cannot be attributed to app authorship. That is the very property that lets a forged marker pass the controls that read it. Only the authored source still shows who wrote it."
19
+ },
20
+ "corpus": true
21
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "id": "frontend/no-inline-styling",
3
+ "surface": "frontend",
4
+ "title": "style and className attributes are refused in app modules",
5
+ "intent": "A style or className attribute is a side channel into hand-authored CSS that drifts per screen; styling flows from the app's design tokens and sanctioned layout primitives only. The refused attributes are declared in restricted-surface.json (restrictedAttributes).",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "BOUNDARY_SPEC.restrictedAttributes",
12
+ "reported_as": "no-restricted-syntax"
13
+ }
14
+ ],
15
+ "reference": "Layout via Stack, DetailList and the page archetypes from @terpjs/react-core; theming via the app's token source.",
16
+ "opt_out": "// terp-allow-no-inline-styling: <reason>",
17
+ "runtime": {
18
+ "applicability": "not-applicable",
19
+ "rationale": "style/className are authoring-surface attributes: the token pipeline itself emits inline styles and class names into the built DOM, so their presence at runtime is legitimate and unattributable to app authorship."
20
+ },
21
+ "restricted_surface": [
22
+ "restrictedAttributes"
23
+ ],
24
+ "corpus": true
25
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "id": "frontend/no-raw-clipboard",
3
+ "surface": "frontend",
4
+ "title": "Putting text on the clipboard goes through the stack's seam, not navigator.clipboard",
5
+ "intent": "navigator.clipboard is not the API its type describes. The DOM lib types it as always present, and it is absent outside a secure context — so on a plain-http origin that is not localhost, navigator.clipboard.writeText(...) is a property access on undefined. That throws a synchronous TypeError before any promise exists, which means a .catch on the call never runs and neither does a try wrapped around an await that was never reached. Nothing in the type system reports it, so the whole class is invisible to review and to a type check: the observable outcome is a control that does nothing and says nothing, found by a person clicking it in a deployment served over http. Every app that reaches for the API directly rediscovers this, which is what makes it a rule rather than a lesson. The rule is about the DEFECT, not about copying: the seam a conformant stack ships is expected to feature-detect the API, fall back where it is absent, and report a refusal rather than resolve as though it had worked.",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "BOUNDARY_SPEC.restrictRawClipboard",
12
+ "reported_as": "no-restricted-syntax"
13
+ }
14
+ ],
15
+ "reference": "Any access to `navigator.clipboard` in app code is refused — the member expression, not merely a call, because `const c = navigator.clipboard` is the same throw one line earlier; the `window.`/`globalThis.` prefixed and computed (`navigator[\"clipboard\"]`) spellings and the destructuring form (`const { clipboard } = navigator`) are refused with it, since each binds the same undefined under a different name. The reference stack ships `copyText` (the mechanism, callable anywhere) and `useCopyToClipboard` (adding the transient \"copied\" acknowledgement a control needs) from `@terpjs/react-core`; `copyText` resolves to `false` when the text did not reach the clipboard, so a caller that ignores a refusal has chosen to rather than never having been told.",
16
+ "opt_out": "// terp-allow-no-raw-clipboard: <reason>",
17
+ "runtime": {
18
+ "applicability": "not-applicable",
19
+ "rationale": "The invariant is which API the source reached for, and that is only visible where the call is written. A runtime control would have to observe the TypeError it exists to prevent — by which point the copy has already silently failed for that viewer — and could not distinguish an app calling the API directly from the seam's own feature detection, which reads the very same property. The authored source is the only place the choice is still legible."
20
+ },
21
+ "corpus": true
22
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "id": "frontend/no-raw-random-uuid",
3
+ "surface": "frontend",
4
+ "title": "Minting a UUID goes through the stack's seam, not crypto.randomUUID",
5
+ "intent": "crypto.randomUUID is not the API its type describes. The DOM lib declares it unconditionally on the Crypto interface, and it exists only in a secure context -- so on a plain-http origin that is not localhost, calling it is a call on undefined and throws a synchronous TypeError. Nothing in the type system reports it, and neither does a test run: localhost IS a secure context, so the whole class is invisible to the type checker, to review and to CI at once, and surfaces only in a deployment. What makes it a rule rather than a lesson is that a conformant stack routes applications into it: an idempotency contract keyed on a CLIENT-generated request key means an app adding retry-safety reaches for exactly this method, and a stack whose default deployment topology publishes plain http puts that app in an insecure context by default. The rule is about the DEFECT, not about identifiers: the seam a conformant stack ships is expected to feature-detect, and to fall back to a source of cryptographic randomness that is NOT secure-context-gated rather than to a weaker one -- a value standing in for an idempotency key or a record id is one a collision corrupts, so silently reducing its entropy to keep a call site quiet is a worse failure than the throw.",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "BOUNDARY_SPEC.restrictRawRandomUuid",
12
+ "reported_as": "no-restricted-syntax"
13
+ }
14
+ ],
15
+ "reference": "Any access to `crypto.randomUUID` in app code is refused -- the member expression, not merely a call, because `const gen = crypto.randomUUID` is the same broken binding one line earlier; the `window.`/`globalThis.`/`self.` prefixed and computed (`crypto[\"randomUUID\"]`) spellings and the destructuring form (`const { randomUUID } = crypto`) are refused with it. `crypto.getRandomValues` is deliberately untouched: it is not secure-context-gated, it is not this defect, and the seam is built on it. The reference stack ships `randomUuid` from `@terpjs/react-core`, which uses the native generator where it exists and assembles the same v4 from `getRandomValues` where it does not, so the entropy is identical either way; with no `crypto` at all it throws `RandomUuidUnavailableError` rather than falling back to `Math.random`.",
16
+ "opt_out": "// terp-allow-no-raw-random-uuid: <reason>",
17
+ "runtime": {
18
+ "applicability": "not-applicable",
19
+ "rationale": "The invariant is which API the source reached for, and that is only visible where the call is written. A runtime control would have to observe the TypeError it exists to prevent -- by which point the value was never minted for that viewer -- and could not distinguish an app calling the API directly from the seam's own feature detection, which reads the very same property. The authored source is the only place the choice is still legible."
20
+ },
21
+ "corpus": true
22
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "id": "frontend/no-style-imports",
3
+ "surface": "frontend",
4
+ "title": "Module-authored stylesheets are refused",
5
+ "intent": "Importing a stylesheet from an app module reintroduces per-screen CSS; theming flows from the app's token source only. The refused stylesheet extensions are declared in restricted-surface.json (styleImportExtensions).",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "BOUNDARY_SPEC.styleImportPatterns",
12
+ "reported_as": "no-restricted-imports"
13
+ }
14
+ ],
15
+ "opt_out": "// terp-allow-no-style-imports: <reason>",
16
+ "runtime": {
17
+ "applicability": "not-applicable",
18
+ "rationale": "A stylesheet import is a build-graph edge; the bundler compiles it into the emitted CSS, after which module authorship does not exist."
19
+ },
20
+ "restricted_surface": [
21
+ "styleImportExtensions"
22
+ ],
23
+ "corpus": true
24
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "id": "frontend/no-unsafe-href",
3
+ "surface": "frontend",
4
+ "title": "javascript: URLs are refused in app modules",
5
+ "intent": "A javascript: href executes script on click \u2014 an XSS vector that survives the framework's attribute escaping. Links carry http(s), mailto, tel or in-app router paths only.",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "terp/no-unsafe-href",
12
+ "reported_as": "terp/no-unsafe-href"
13
+ }
14
+ ],
15
+ "opt_out": "// terp-allow-no-unsafe-href: <reason>",
16
+ "runtime": {
17
+ "applicability": "not-applicable",
18
+ "rationale": "The refusal is of authoring javascript: URLs in source. Data-driven links are the sanctioned components' own concern (the Markdown component strips unsafe protocols at render -- its control, not this rule's), and raw anchors are refused wholesale in app modules anyway."
19
+ },
20
+ "corpus": true
21
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "id": "frontend/no-unsafe-target-blank",
3
+ "surface": "frontend",
4
+ "title": "A static target=\"_blank\" link declares rel=\"noopener\"",
5
+ "intent": "Without rel=noopener the opened page holds a window.opener reference to the app \u2014 the reverse-tabnabbing primitive. The rule enforces the safe default on every statically-authored external link.",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "terp/no-unsafe-target-blank",
12
+ "reported_as": "terp/no-unsafe-target-blank"
13
+ }
14
+ ],
15
+ "opt_out": "// terp-allow-no-unsafe-target-blank: <reason>",
16
+ "runtime": {
17
+ "applicability": "not-applicable",
18
+ "rationale": "An authored static target=_blank without rel is a source form; the residual risk it addresses is legacy-engine reverse-tabnabbing, fixable only where the anchor is written. Modern engines default to noopener behaviour, and raw anchors are refused wholesale in app modules regardless."
19
+ },
20
+ "corpus": true
21
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "id": "frontend/no-untranslated-ui",
3
+ "surface": "frontend",
4
+ "title": "Static user-facing text participates in localization",
5
+ "intent": "Static user-facing text anywhere in app-authored frontend source must use the translation seam. Bare visible copy, accessibility labels, component text properties, labels stored in data, and standard toast feedback are otherwise absent from every translation catalog and silently remain in the source language. The subject is text that is rendered. An operand of a comparison is not: the expression evaluates to a boolean, so the literal in `status === \"paused\"` is a state token being tested and reaches no screen in any locale. The same holds for the left operand of `&&`, which is the test rather than what renders. Operators that can render either side - `||`, `??` and string concatenation - are in scope on both. A property that is not text is not in scope whatever its value spells: `columns=\"auto\"` on a layout component is a keyword, and the same name is text only where the component takes it as text.",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "terp/no-untranslated-ui"
12
+ }
13
+ ],
14
+ "reference": "Use UiText descriptors and Trans from @terpjs/react-core throughout app-authored frontend source. A status guard needs no hoisting: `{status === \"paused\" && <Trans .../>}` is compliant as written, and so is a comparison against a literal anywhere else.",
15
+ "opt_out": "// terp-allow-no-untranslated-ui: <reason>",
16
+ "runtime": {
17
+ "applicability": "not-applicable",
18
+ "rationale": "The rendered value cannot prove whether it originated from a descriptor or a bare literal, while dynamic business data legitimately remains untranslated."
19
+ },
20
+ "corpus": true
21
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "id": "frontend/router-links",
3
+ "surface": "frontend",
4
+ "title": "In-app links go through the router, never a raw anchor",
5
+ "intent": "A raw <a href=\"/...\"> forces a full reload and skips the role-aware route guard; in-app navigation uses the stack's router-integrated link. External https:// anchors stay allowed.",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "BOUNDARY_SPEC.restrictInAppAnchors",
12
+ "reported_as": "no-restricted-syntax"
13
+ }
14
+ ],
15
+ "reference": "Link from @terpjs/react-core (router-integrated, role-aware).",
16
+ "opt_out": "// terp-allow-router-links: <reason>",
17
+ "runtime": {
18
+ "applicability": "not-applicable",
19
+ "rationale": "In the rendered DOM the router's own Link IS an anchor -- raw-anchor authorship is only visible in source, so no DOM check can distinguish a sanctioned link from a hand-written one."
20
+ },
21
+ "corpus": true
22
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "id": "frontend/timestamp-inputs-carry-their-offset",
3
+ "surface": "frontend",
4
+ "title": "A date and time a form sends carries its UTC offset",
5
+ "intent": "A browser's local date-and-time control hands the page a wall time with no UTC offset. That names no instant: ten in the morning is a different moment in every zone. Sent as it is, the API refuses it for a timestamp, and a server that read it as UTC instead would store a person in any other zone off by their offset. So a form never sends the control's own value: it shows the instant in a zone and sends what is picked as the instant it names, with that zone's offset.",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "terp/timestamp-inputs-carry-their-offset",
12
+ "reported_as": "terp/timestamp-inputs-carry-their-offset"
13
+ },
14
+ {
15
+ "kind": "runtime",
16
+ "tool": "terp.core",
17
+ "ref": "refuse_timestamp_text_without_offset"
18
+ }
19
+ ],
20
+ "reference": "Any JSX `type` attribute whose value can be `datetime-local` is refused, on `Input`, a raw `input` or a wrapper that passes it on, in any letter case (the browser reads the type case-insensitively). The value is followed wherever it is spelled inline: a string, a template, a branch of a conditional or of `??`, `||` and `&&`, a concatenation of those, the last of a comma sequence, and the expression under `as const`, `satisfies` or `!`. A value read from a name, a call or a member, a props object spread onto the element, `createElement` and a type set through the DOM are not followed; its residuals say so. The reference stack ships `DateTimeInput` from `@terpjs/react-core`: it shows an RFC 3339 instant as wall time in a zone, the browser's own or one it is given, and sends what is picked as an RFC 3339 instant with that zone's offset; a wall time the clocks skip moves past the gap, and one they repeat is the earlier. A calendar day (`type=\"date\"`) and a time of day (`type=\"time\"`) name no instant and are not this rule's concern. The runtime half is the server's: a BaseSchema refuses timestamp text without an offset with a 422 (ADR 0206). A field that truly holds a wall time with a named zone, read as text by the API, keeps the control with the marker and its reason.",
21
+ "opt_out": "// terp-allow-timestamp-inputs-carry-their-offset: <reason>",
22
+ "runtime": {
23
+ "applicability": "required",
24
+ "rationale": "The server holds the invariant: a request body refuses timestamp text without a UTC offset with a 422 at its field, so a wall time sent from this control is refused where it enters instead of stored off by the sender's offset. The build-time half moves that refusal from the first request in production to the line the control is written on, and names the control that sends an instant instead."
25
+ },
26
+ "corpus": true
27
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "id": "frontend/token-styled-elements",
3
+ "surface": "frontend",
4
+ "title": "Raw interactive/structural HTML elements are refused in app modules",
5
+ "intent": "A raw <button>/<input>/<select>/<textarea>/<table>/<dialog>/<form>/<meter> bypasses the app's sanctioned, token-styled primitive surface (accessible and theme-consistent by construction). The refused elements are declared in restricted-surface.json (restrictedElements); each has a sanctioned replacement in the stack's component surface, and the violation message names it.",
6
+ "layer": "static-portable",
7
+ "enforcement": [
8
+ {
9
+ "kind": "build-time",
10
+ "tool": "@terpjs/eslint-boundaries",
11
+ "ref": "BOUNDARY_SPEC.restrictedElements",
12
+ "reported_as": "no-restricted-syntax"
13
+ }
14
+ ],
15
+ "reference": "Button, Input, Select, Textarea, DataView, ConfirmDialog, Stack as=\"form\" and Meter from @terpjs/react-core (BOUNDARY_SPEC.restrictedElements maps each element to its replacement).",
16
+ "opt_out": "// terp-allow-token-styled-elements: <reason>",
17
+ "runtime": {
18
+ "applicability": "not-applicable",
19
+ "rationale": "The sanctioned components themselves render the raw elements into the built DOM -- every button on screen is legitimate output of Button. Compilation erases which JSX authored a node, and third-party components legitimately render the same primitives, so a DOM scan cannot soundly attribute a raw element to app authorship (unlike the layout contract's slot check, which verifies the identity of sanctioned components at one owned seam)."
20
+ },
21
+ "restricted_surface": [
22
+ "restrictedElements"
23
+ ],
24
+ "corpus": true
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terpjs/eslint-boundaries",
3
- "version": "0.37.0",
3
+ "version": "0.39.0",
4
4
  "type": "module",
5
5
  "description": "Terp frontend boundary rules (as data) + the ESLint adapter, over all app source under src/: no cross-module imports, no package internals, design-token-only styling (no style/className/stylesheets; the bootstrap alone loads the token pipeline), token-styled components for raw HTML tags, router-only in-app links, generated-client-only, and browser XSS/navigation sink bans. Strict-only (no modes); governed opt-outs via terp-allow markers + the escape-hatch budget ratchet (terp-boundaries-budget).",
6
6
  "main": "./src/index.js",
@@ -8,6 +8,11 @@
8
8
  "terp-boundaries-budget": "./src/budget.js",
9
9
  "terp-boundaries-lint": "./src/findings.js"
10
10
  },
11
+ "files": [
12
+ "src",
13
+ "catalog",
14
+ "restricted-surface.json"
15
+ ],
11
16
  "exports": {
12
17
  ".": "./src/index.js",
13
18
  "./spec": "./src/spec.js",
@@ -0,0 +1,10 @@
1
+ {
2
+ "title": "Terp Standard - the refused raw frontend surface",
3
+ "description": "The normative declaration of the raw browser primitives an app module must not author directly. The prohibition is the portable part of the rules that cite this file (token-styled-elements, no-inline-styling, generated-client-only, no-style-imports, no-deep-imports); which sanctioned component or helper answers each primitive is per-stack configuration, recorded non-normatively in the catalog entry's 'reference' field. A checker realises this file for its language; the reference adapter's BOUNDARY_SPEC is parity-tested against it.",
4
+ "restrictedElements": ["button", "dialog", "form", "input", "meter", "select", "table", "textarea"],
5
+ "restrictedAttributes": ["className", "style"],
6
+ "restrictedGlobals": ["EventSource", "WebSocket", "XMLHttpRequest", "fetch"],
7
+ "restrictedMemberCalls": ["navigator.sendBeacon"],
8
+ "styleImportExtensions": [".css", ".less", ".sass", ".scss", ".styl"],
9
+ "deepImportPathSegments": ["dist", "src"]
10
+ }
@@ -1,11 +1,9 @@
1
1
  /**
2
- * The frontend corpus harness: lint a Terp Standard corpus case into spec-shaped
3
- * findings, exactly as an app's own boundary lint would see it.
2
+ * The frontend corpus harness: lint a corpus case into findings, exactly as an app's own
3
+ * boundary lint would see it.
4
4
  *
5
- * Shared by the certification test (corpus.test.js) and the scorecard emitter
6
- * (scorecard.js), so the two can never apply different corpus semantics. The spec
7
- * is resolved as a declared dependency (@terpjs/spec, ADR 0082) by the CALLER —
8
- * this module takes paths, never resolves the spec itself.
5
+ * Used by the corpus test (corpus.test.js). It takes paths and never locates the corpus
6
+ * itself: the corpus lives beside this package's sources (ADR 0203), and the caller names it.
9
7
  */
10
8
 
11
9
  import fs from "node:fs";
@@ -1,53 +1,48 @@
1
1
  /**
2
- * The ESLint adapter is held to the Terp Standard's violation corpus (ADR 0080).
2
+ * The ESLint adapter is held to its violation corpus (ADR 0080, ADR 0203).
3
3
  *
4
- * `spec/corpus/frontend/<rule>/` holds violating and compliant sample module files — the
5
- * executable meaning of each frontend catalog entry. This test lints every case with the real
6
- * boundary config and applies the corpus contract in terms of the **stack-neutral catalog id**
7
- * (findings are attributed through the adapter's published {@link catalogRuleId} mapping, never
8
- * the raw ESLint rule id — several catalog rules share a core rule id):
4
+ * `corpus/frontend/<rule>/` (beside this package's sources) holds violating and compliant sample
5
+ * module files: the executable meaning of each frontend catalog entry in `catalog/frontend/`. This
6
+ * test lints every case with the real boundary config and applies the corpus contract in terms of
7
+ * the **catalog id** (findings are attributed through the adapter's published {@link catalogRuleId}
8
+ * mapping, never the raw ESLint rule id — several catalog rules share a core rule id):
9
9
  *
10
10
  * - every `violation-*` case produces at least one finding attributed to the entry's catalog id;
11
11
  * - every `compliant-*` case is completely clean (no messages at all).
12
12
  *
13
- * The same corpus certifies any future stack's adapter (e.g. a Svelte realisation of
14
- * BOUNDARY_SPEC). The backend half lives in `tests/architecture/test_spec_corpus.py`.
13
+ * The rules, their entries and their cases live together (ADR 0203), so a rule, its entry and its
14
+ * cases land in one change. The backend half lives in `tests/architecture/test_rule_corpus.py`.
15
15
  */
16
16
 
17
17
  import fs from "node:fs";
18
18
  import { createRequire } from "node:module";
19
19
  import path from "node:path";
20
+ import { fileURLToPath } from "node:url";
20
21
 
21
22
  import { describe, expect, it } from "vitest";
22
23
 
23
24
  import { lintCaseFindings } from "./corpus-harness.js";
24
25
 
25
- // The spec is a declared dependency (@terpjs/spec, ADR 0082), never a repo-relative path.
26
- const SPEC_ROOT = path.dirname(
26
+ const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
27
+ const CATALOG = path.join(PACKAGE_ROOT, "catalog", "frontend");
28
+ const CORPUS = path.join(PACKAGE_ROOT, "corpus", "frontend");
29
+ // The finding format is a contract more than one program reads, so it stays in the shared
30
+ // contracts package (ADR 0203), resolved as a declared dependency, never a repo path.
31
+ const CONTRACTS_ROOT = path.dirname(
27
32
  createRequire(import.meta.url).resolve("@terpjs/spec/package.json"),
28
33
  );
29
- const CATALOG = path.join(SPEC_ROOT, "catalog", "frontend");
30
- const CORPUS = path.join(SPEC_ROOT, "corpus", "frontend");
31
34
 
32
35
  const catalogEntries = fs
33
36
  .readdirSync(CATALOG)
34
37
  .filter((name) => name.endsWith(".json"))
35
38
  .map((name) => JSON.parse(fs.readFileSync(path.join(CATALOG, name), "utf8")));
36
- const catalogIds = new Set(catalogEntries.map((entry) => entry.id));
37
- const entries = catalogEntries
38
- .filter((entry) => entry.corpus);
39
-
40
- async function findingsForConsumedSpec(caseDir) {
41
- return (await lintCaseFindings(caseDir)).filter(
42
- (finding) => finding.rule === null || catalogIds.has(finding.rule),
43
- );
44
- }
39
+ const entries = catalogEntries.filter((entry) => entry.corpus);
45
40
 
46
41
  async function lintCase(caseDir) {
47
- return (await findingsForConsumedSpec(caseDir)).map((finding) => finding.rule);
42
+ return (await lintCaseFindings(caseDir)).map((finding) => finding.rule);
48
43
  }
49
44
 
50
- describe("frontend corpus (spec/corpus/frontend)", () => {
45
+ describe("frontend corpus (corpus/frontend)", () => {
51
46
  for (const entry of entries) {
52
47
  const rule = entry.id.split("/")[1];
53
48
  const ruleDir = path.join(CORPUS, rule);
@@ -65,11 +60,11 @@ describe("frontend corpus (spec/corpus/frontend)", () => {
65
60
  }
66
61
  });
67
62
 
68
- describe("findings round-trip (spec/findings.schema.json)", () => {
69
- // The reference adapter's output, rendered as spec findings, must validate against the
70
- // published finding format (ADR 0081) — the contract a Level 2 checker is certified on.
63
+ describe("findings round-trip (findings.schema.json)", () => {
64
+ // The adapter's output, rendered as findings, must validate against the finding format, the
65
+ // contract every reader of a check report is held to.
71
66
  const schema = JSON.parse(
72
- fs.readFileSync(path.join(SPEC_ROOT, "findings.schema.json"), "utf8"),
67
+ fs.readFileSync(path.join(CONTRACTS_ROOT, "findings.schema.json"), "utf8"),
73
68
  );
74
69
  const item = schema.items;
75
70
  const rulePattern = new RegExp(item.properties.rule.pattern);
@@ -80,7 +75,7 @@ describe("findings round-trip (spec/findings.schema.json)", () => {
80
75
  const ruleDir = path.join(CORPUS, entry.id.split("/")[1]);
81
76
  for (const caseName of fs.readdirSync(ruleDir).sort()) {
82
77
  if (!caseName.startsWith("violation-")) continue;
83
- findings.push(...(await findingsForConsumedSpec(path.join(ruleDir, caseName))));
78
+ findings.push(...(await lintCaseFindings(path.join(ruleDir, caseName))));
84
79
  }
85
80
  }
86
81
  expect(findings.length).toBeGreaterThan(0);
package/src/findings.js CHANGED
@@ -25,7 +25,7 @@
25
25
  * rules listed under `not_applicable` — today `frontend/layout-contract` when the app
26
26
  * has no checked-in layout-contract.json, so a consumer never renders an unenforced
27
27
  * rule as passing). `findings` are the reported messages attributed to their
28
- * stack-neutral catalog ids through the adapter's published {@link catalogRuleId}
28
+ * catalog ids through the adapter's published {@link catalogRuleId}
29
29
  * mapping, plus any budget drift attributed to `frontend/escape-hatch`. A message
30
30
  * outside the boundary (another configured rule, a parse error) lands in
31
31
  * `unattributed` — surfaced, never dropped. The human-readable report goes to stderr,
@@ -13,8 +13,12 @@ import { SPEC_VERSION } from "./spec.js";
13
13
 
14
14
  // The machine-readable boundary lint (the frontend analog of `terp check --format json`):
15
15
  // the findings envelope publishes the evaluated-rule inventory + findings attributed to
16
- // stack-neutral catalog ids, humans keep stderr, and the exit code stays the verdict.
16
+ // catalog ids, humans keep stderr, and the exit code stays the verdict.
17
17
 
18
+ // The frontend catalog ships with this package (ADR 0203). The finding and check-report
19
+ // formats are contracts more than one program reads, so they stay in the shared contracts
20
+ // package, resolved as a declared dependency, never a repo path.
21
+ const CATALOG = fileURLToPath(new URL("../catalog/frontend", import.meta.url));
18
22
  const SPEC_ROOT = path.dirname(
19
23
  createRequire(import.meta.url).resolve("@terpjs/spec/package.json"),
20
24
  );
@@ -50,22 +54,18 @@ async function lintModule(text) {
50
54
  }
51
55
 
52
56
  describe("catalogRuleIds (the evaluated-rule inventory)", () => {
53
- it("covers the pinned catalog and matches a substituted candidate exactly", () => {
54
- // Framework main must land a reference implementation before the corresponding
55
- // Standard candidate can certify. The last published (equal-version) pin may
56
- // therefore be a subset during that staging window. Candidate CI substitutes a
57
- // newer spec, where exactness is restored before release.
57
+ it("is exactly the frontend catalog shipped with this package", () => {
58
+ // The inventory is what every findings envelope and check report publishes as evaluated,
59
+ // so it names exactly the catalogued rules: a rule without an entry, or an entry this
60
+ // adapter never runs, would let a consumer render a verdict nobody can explain. The
61
+ // catalog lives beside this package (ADR 0203), so nothing waits for another release.
58
62
  const catalogued = fs
59
- .readdirSync(path.join(SPEC_ROOT, "catalog", "frontend"))
63
+ .readdirSync(CATALOG)
60
64
  .filter((name) => name.endsWith(".json"))
61
65
  .map((name) => `frontend/${name.replace(/\.json$/, "")}`)
62
66
  .sort();
63
- const consumedVersion = fs.readFileSync(path.join(SPEC_ROOT, "VERSION"), "utf8").trim();
64
- if (consumedVersion === SPEC_VERSION) {
65
- expect(catalogRuleIds()).toEqual(expect.arrayContaining(catalogued));
66
- } else {
67
- expect(catalogRuleIds()).toEqual(catalogued);
68
- }
67
+ expect(catalogued.length).toBeGreaterThan(0);
68
+ expect(catalogRuleIds()).toEqual(catalogued);
69
69
  });
70
70
  });
71
71
 
package/src/index.js CHANGED
@@ -184,6 +184,77 @@ function isDocumentObject(node) {
184
184
  );
185
185
  }
186
186
 
187
+ /** How many strings an expression is followed to: concatenation multiplies its branches, and an
188
+ * attribute that spells more is no `type` written by hand. */
189
+ const POSSIBLE_STRINGS_CAP = 64;
190
+
191
+ function joinEach(lefts, rights) {
192
+ const joined = [];
193
+ for (const left of lefts) {
194
+ for (const right of rights) {
195
+ if (joined.length >= POSSIBLE_STRINGS_CAP) return joined;
196
+ joined.push(left + right);
197
+ }
198
+ }
199
+ return joined;
200
+ }
201
+
202
+ /**
203
+ * Every string *node* can evaluate to where the source spells it: a string, a template, each
204
+ * branch of a conditional and of `??`, `||` and `&&`, a concatenation of those, the last of a
205
+ * comma sequence, and the expression under `as`, `satisfies` and `!`. A name, a call or a
206
+ * member read is followed by no rule here, and contributes nothing.
207
+ */
208
+ function possibleStrings(node) {
209
+ const value = unwrapExpression(node);
210
+ switch (value?.type) {
211
+ case "Literal":
212
+ return typeof value.value === "string" ? [value.value] : [];
213
+ case "TemplateLiteral":
214
+ return value.expressions.reduce(
215
+ (sofar, expression, index) => {
216
+ const tail = value.quasis[index + 1].value.cooked ?? value.quasis[index + 1].value.raw;
217
+ return joinEach(sofar, possibleStrings(expression).map((part) => part + tail));
218
+ },
219
+ [value.quasis[0].value.cooked ?? value.quasis[0].value.raw],
220
+ );
221
+ case "ConditionalExpression":
222
+ return [...possibleStrings(value.consequent), ...possibleStrings(value.alternate)];
223
+ case "LogicalExpression":
224
+ return [...possibleStrings(value.left), ...possibleStrings(value.right)];
225
+ case "SequenceExpression":
226
+ return possibleStrings(value.expressions.at(-1));
227
+ case "BinaryExpression":
228
+ return value.operator === "+" ? joinEach(possibleStrings(value.left), possibleStrings(value.right)) : [];
229
+ default:
230
+ return [];
231
+ }
232
+ }
233
+
234
+ /**
235
+ * A `type` attribute that can be `datetime-local` (ADR 0206), however the value is spelled
236
+ * inline: a string, a template, a branch of a conditional or of `??`, a concatenation, or under
237
+ * `as const` or `satisfies`. The browser reads the type case-insensitively, so this does too.
238
+ */
239
+ const timestampInputsCarryTheirOffset = {
240
+ meta: {
241
+ type: "problem",
242
+ docs: { description: "Disallow a datetime-local input, whose value names no instant." },
243
+ schema: [],
244
+ },
245
+ create(context) {
246
+ return {
247
+ JSXAttribute(node) {
248
+ if (jsxName(node.name) !== "type" || !node.value) return;
249
+ const value = node.value.type === "JSXExpressionContainer" ? node.value.expression : node.value;
250
+ if (possibleStrings(value).some((text) => /^datetime-local$/i.test(text))) {
251
+ context.report({ node, message: localDateTimeMessage });
252
+ }
253
+ },
254
+ };
255
+ },
256
+ };
257
+
187
258
  const noUnsafeTargetBlank = {
188
259
  meta: {
189
260
  type: "problem",
@@ -1165,6 +1236,7 @@ const terpPlugin = {
1165
1236
  "no-untranslated-ui": noUntranslatedUi,
1166
1237
  "no-unsafe-href": noUnsafeHref,
1167
1238
  "no-unsafe-target-blank": noUnsafeTargetBlank,
1239
+ "timestamp-inputs-carry-their-offset": timestampInputsCarryTheirOffset,
1168
1240
  },
1169
1241
  };
1170
1242
 
@@ -1180,6 +1252,11 @@ const randomUuidMessage =
1180
1252
  + "TypeError that type-checks cleanly and never fires on localhost, so no test sees it. "
1181
1253
  + "Use randomUuid from @terpjs/react-core, which falls back to crypto.getRandomValues "
1182
1254
  + "(not secure-context-gated) for the same entropy.";
1255
+ const localDateTimeMessage =
1256
+ 'A type="datetime-local" input sends a wall time with no UTC offset, which names no instant, ' +
1257
+ "and the API refuses one for a timestamp with a 422 (ADR 0206). Use DateTimeInput from " +
1258
+ "@terpjs/react-core, which shows the time in the person's zone and sends the instant it " +
1259
+ "names with that zone's offset.";
1183
1260
  const deepImportMessage =
1184
1261
  "Import from the package root (@terpjs/react-core, @terpjs/contract), not its internals.";
1185
1262
  const styleImportMessage =
@@ -1212,8 +1289,8 @@ function escapeRegExp(s) {
1212
1289
 
1213
1290
  /**
1214
1291
  * The `no-restricted-syntax` realisation of the BOUNDARY_SPEC families, each entry tagged
1215
- * with the Terp Standard catalog rule it realises (`spec/catalog/frontend/<rule>.json`) so
1216
- * a reported message stays attributable to its stack-neutral rule id (see
1292
+ * with the catalog rule it realises (`catalog/frontend/<rule>.json`) so
1293
+ * a reported message stays attributable to its catalog rule id (see
1217
1294
  * {@link catalogRuleId}). {@link restrictedSyntax} strips the tag for the ESLint config.
1218
1295
  */
1219
1296
  function restrictedSyntaxWithCatalogIds() {
@@ -1385,7 +1462,7 @@ const CATALOG_ID_BY_SYNTAX_MESSAGE = new Map(
1385
1462
  );
1386
1463
 
1387
1464
  /**
1388
- * The Terp Standard catalog rule id (`frontend/<rule>`, per `spec/catalog/frontend/`) a
1465
+ * The catalog rule id (`frontend/<rule>`, per `catalog/frontend/`) a
1389
1466
  * reported ESLint message realises, or null for a message outside the boundary. This is the
1390
1467
  * adapter's published `reported_as -> catalog id` mapping: several catalog rules share a core
1391
1468
  * ESLint rule id (`no-restricted-syntax` / `no-restricted-imports` / `no-restricted-globals`),
@@ -1425,7 +1502,7 @@ export function catalogRuleId(message) {
1425
1502
  * inventory a boundary lint run publishes in its findings envelope (see ./findings.js):
1426
1503
  * a consumer joining findings to the catalog reads the inventory from the run itself, so
1427
1504
  * a per-rule "pass" can never be claimed for a rule this adapter never ran (fail closed
1428
- * under version skew). Parity with `spec/catalog/frontend/` is locked by findings.test.js.
1505
+ * under version skew). Parity with `catalog/frontend/` is locked by findings.test.js.
1429
1506
  */
1430
1507
  export function catalogRuleIds() {
1431
1508
  return [
@@ -1443,7 +1520,7 @@ export function catalogRuleIds() {
1443
1520
  /** The marker name a message answers to: its catalog rule name, or null when unwaivable.
1444
1521
  *
1445
1522
  * Suppression attributes markers exactly the way findings are attributed — through
1446
- * {@link catalogRuleId} — so a marker names the stack-neutral catalog rule
1523
+ * {@link catalogRuleId} — so a marker names the catalog rule
1447
1524
  * (`terp-allow-token-styled-elements`). One marker therefore covers every detection
1448
1525
  * path of its rule and cannot waive a sibling rule that shares a core lint id.
1449
1526
  * A message outside the boundary is not waivable by the terp escape hatch at all, and
@@ -1528,7 +1605,7 @@ export function parseAllowMarkers(text) {
1528
1605
  * Apply the governed escape hatch to a lint result (the frontend analog of the backend's
1529
1606
  * justified `# arch-allow-<rule>: <reason>` suppressions): a marker with a reason, on the
1530
1607
  * violating line or the line immediately above, suppresses that rule there. The marker names
1531
- * the CATALOG rule (see {@link suppressibleRuleName}), so `spec/catalog/frontend/<rule>.json`'s
1608
+ * the CATALOG rule (see {@link suppressibleRuleName}), so `catalog/frontend/<rule>.json`'s
1532
1609
  * `opt_out` spelling is the one that works — for every detection path of the rule at once.
1533
1610
  * An unjustified marker (no reason) is itself reported — never silently honoured — and so
1534
1611
  * is a marker naming no governed rule (a typo, a stale name, or a pre-0.6.0 core-id
@@ -1665,6 +1742,9 @@ export function terpBoundaries() {
1665
1742
  "terp/no-eval": "error",
1666
1743
  "terp/no-unsafe-href": "error",
1667
1744
  "terp/no-unsafe-target-blank": "error",
1745
+ ...(BOUNDARY_SPEC.restrictLocalDateTimeInput
1746
+ ? { "terp/timestamp-inputs-carry-their-offset": "error" }
1747
+ : {}),
1668
1748
  "no-restricted-syntax": ["error", ...restrictedSyntax()],
1669
1749
  "no-restricted-globals": [
1670
1750
  "error",
package/src/index.test.js CHANGED
@@ -304,6 +304,39 @@ describe("terpBoundaries", () => {
304
304
  ).toEqual([]);
305
305
  });
306
306
 
307
+ it("refuses a datetime-local type however it is spelled inline", async () => {
308
+ // The catalog says "an expression": a selector read only a string or a plain template as
309
+ // the attribute's direct value, so each of these passed.
310
+ for (const spelling of [
311
+ '"datetime-local"',
312
+ '{"DATETIME-LOCAL"}',
313
+ "{`datetime-local`}",
314
+ '{withTime ? "datetime-local" : "date"}',
315
+ '{"datetime-local" as const}',
316
+ '{"datetime-local" satisfies string}',
317
+ '{kind ?? "datetime-local"}',
318
+ '{withTime && "datetime-local"}',
319
+ '{"datetime-" + "local"}',
320
+ '{`datetime-${"local"}`}',
321
+ '{`${withTime ? "datetime-" : "x"}local`}',
322
+ '{(0, "datetime-local")}',
323
+ ]) {
324
+ const found = await lint(`export const W = ({ withTime, kind }) => <Input type=${spelling} />;`);
325
+ expect(found, spelling).toContain("terp/timestamp-inputs-carry-their-offset");
326
+ }
327
+ for (const spelling of ['"date"', '{withTime ? "date" : "time"}', "{kind}", '{"datetime" + "-local-ish"}']) {
328
+ const found = await lint(`export const W = ({ withTime, kind }) => <Input type=${spelling} />;`);
329
+ expect(found, spelling).not.toContain("terp/timestamp-inputs-carry-their-offset");
330
+ }
331
+ });
332
+
333
+ it("follows a concatenation's branches only so far", async () => {
334
+ const branch = '(a ? "x" : "y")';
335
+ const many = Array.from({ length: 8 }, () => branch).join(" + ");
336
+ const found = await lint(`export const W = ({ a }) => <Input type={${many} + "datetime-local"} />;`);
337
+ expect(found).not.toContain("terp/timestamp-inputs-carry-their-offset");
338
+ });
339
+
307
340
  it("flags static javascript href/src values without rejecting dynamic URLs", async () => {
308
341
  expect(await lint('export const W = () => <a href=" javascript:alert(1)">bad</a>;')).toContain(
309
342
  "terp/no-unsafe-href",
package/src/spec.js CHANGED
@@ -12,13 +12,13 @@
12
12
  * boundary config.
13
13
  */
14
14
  /**
15
- * The Terp Standard version this adapter is certified against — the `spec_version` a
16
- * check report (`app-check-report.schema.json`) carries. A constant rather than a runtime
17
- * `@terpjs/spec` read: the spec data package is a dev/certification dependency of the platform
18
- * repo, not of a generated app, and the version is a property of the toolchain build. Held
19
- * equal to the pinned spec release by the framework gate (test_check_json.py — deliberately
20
- * NOT by this package's own suite, which certification runs against candidate spec releases
21
- * whose version is allowed to be newer).
15
+ * The contracts release whose check-report format this adapter writes — the `spec_version` a
16
+ * check report (`app-check-report.schema.json`) carries. The rule ids in a report resolve
17
+ * against the catalog shipped with this package (ADR 0203); this names the format the report
18
+ * itself follows. A constant rather than a runtime `@terpjs/spec` read: the contracts package is
19
+ * a dev dependency of the platform repo, not of a generated app, and the version is a property
20
+ * of the toolchain build. Held equal to the pinned release by the framework gate
21
+ * (test_check_json.py).
22
22
  */
23
23
  export const SPEC_VERSION = "0.43.0";
24
24
 
@@ -151,11 +151,18 @@ export const BOUNDARY_SPEC = {
151
151
  */
152
152
  restrictRawClipboard: true,
153
153
  restrictRawRandomUuid: true,
154
+ /**
155
+ * Refuse a `datetime-local` input in app code (ADR 0206). Its value is a wall time with no UTC
156
+ * offset, which names no instant, and the API refuses one for a timestamp. A flag rather than
157
+ * a list for the reason the two above are: one input type, one defect. The stack's
158
+ * `DateTimeInput` sends what is picked as an instant with its zone's offset.
159
+ */
160
+ restrictLocalDateTimeInput: true,
154
161
  /**
155
162
  * The governed escape hatch (the frontend analog of the backend's `# arch-allow-*`): a
156
163
  * justified `// terp-allow-<rule>: <reason>` comment on (or immediately above) a violating
157
164
  * line suppresses that rule there. `<rule>` is the Terp Standard CATALOG rule name (the
158
- * `opt_out` spelling in `spec/catalog/frontend/<rule>.json`), never a tool-internal ESLint
165
+ * `opt_out` spelling in `catalog/frontend/<rule>.json`), never a tool-internal ESLint
159
166
  * id — one marker covers every detection path of its rule and can never waive a sibling
160
167
  * rule sharing a core lint id. An unjustified marker is itself reported. Marker counts
161
168
  * must exactly match the app's checked-in `escape-hatch-budget.json` (the ratchet).
@@ -1,10 +1,11 @@
1
1
  /**
2
- * The reference adapter is held to the spec's declared refused surface (`spec/restricted-surface.json`).
2
+ * The adapter is held to the declared refused surface (`restricted-surface.json`, beside this
3
+ * package's sources).
3
4
  *
4
- * The refused raw frontend surface is spec **data**, not adapter code: the stack-neutral,
5
- * normative part of the portable prohibition rules is the list of raw primitives an app module
6
- * must not author; which sanctioned component answers each primitive is per-stack configuration
7
- * (the catalog entries' non-normative `reference` field). This test locks the two together:
5
+ * The refused raw frontend surface is **data**, not adapter code: the normative part of the
6
+ * prohibition rules is the list of raw browser primitives an app module must not author; which
7
+ * sanctioned component answers each primitive is the catalog entries' non-normative `reference`
8
+ * field. This test locks the two together:
8
9
  *
9
10
  * - structurally: `BOUNDARY_SPEC` realises exactly the declared surface (no drift in either
10
11
  * direction — an element/attribute/global added to one side must be added to the other);
@@ -14,20 +15,19 @@
14
15
  */
15
16
 
16
17
  import fs from "node:fs";
17
- import { createRequire } from "node:module";
18
18
  import path from "node:path";
19
+ import { fileURLToPath } from "node:url";
19
20
 
20
21
  import { ESLint } from "eslint";
21
22
  import { describe, expect, it } from "vitest";
22
23
 
23
24
  import terpBoundaries, { BOUNDARY_SPEC, catalogRuleId } from "./index.js";
24
25
 
25
- // The spec is a declared dependency (@terpjs/spec, ADR 0082), never a repo-relative path.
26
- const SPEC_ROOT = path.dirname(
27
- createRequire(import.meta.url).resolve("@terpjs/spec/package.json"),
28
- );
29
26
  const SURFACE = JSON.parse(
30
- fs.readFileSync(path.join(SPEC_ROOT, "restricted-surface.json"), "utf8"),
27
+ fs.readFileSync(
28
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "restricted-surface.json"),
29
+ "utf8",
30
+ ),
31
31
  );
32
32
 
33
33
  async function lintModuleSource(source) {
@@ -172,12 +172,11 @@ describe("behavioural parity: each declared primitive is refused with the right
172
172
 
173
173
  // ---------------------------------------------------------------------------
174
174
  // opt-out parity: the catalog's declared marker spelling is the one that works.
175
- // A violating line per rule; the spec's own `opt_out` (a justified marker naming
176
- // the CATALOG rule) must suppress exactly that rule — and the escape-hatch
175
+ // A violating line per rule; the catalog entry's own `opt_out` (a justified marker
176
+ // naming the CATALOG rule) must suppress exactly that rule — and the escape-hatch
177
177
  // governance rule declares no opt_out at all (waiving governance is refused).
178
- // The pinned spec (>= 0.6.0) states this contract.
179
178
  // ---------------------------------------------------------------------------
180
- const CATALOG_DIR = path.join(SPEC_ROOT, "catalog", "frontend");
179
+ const CATALOG_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "catalog", "frontend");
181
180
  const CATALOG_ENTRIES = fs
182
181
  .readdirSync(CATALOG_DIR)
183
182
  .filter((name) => name.endsWith(".json"))
@@ -205,6 +204,8 @@ const VIOLATION_SNIPPETS = {
205
204
  'export const W = ({label}) => <a href="https://example.com" target="_blank">{label}</a>;',
206
205
  "frontend/no-untranslated-ui":
207
206
  'export const W = () => <Text>Untranslated copy</Text>;',
207
+ "frontend/timestamp-inputs-carry-their-offset":
208
+ 'export const W = () => <Input type="datetime-local" />;',
208
209
  };
209
210
 
210
211
  describe(
package/src/scorecard.js DELETED
@@ -1,166 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Emit the Terp Standard conformance scorecard for `@terpjs/eslint-boundaries`
4
- * (the frontend checker).
5
- *
6
- * The scorecard (`scorecard.schema.json` in the spec) turns "certified against
7
- * spec X.Y.Z" into a verifiable artifact: one entry per frontend catalog rule
8
- * with its pass/fail verdict over the violation corpus, plus the detector
9
- * residuals the adapter relies on (held to a subset of the spec's recorded
10
- * `corpus/RESIDUALS.json`). A consumer re-runs the corpus and reproduces it.
11
- *
12
- * A certification-context tool, not an app tool: it needs `@terpjs/spec` (a dev
13
- * dependency of the platform repo) and runs the SAME harness the corpus test
14
- * uses (./corpus-harness.js), so the scorecard can never disagree with the
15
- * suite. Self-validates and refuses to write an invalid or failing scorecard
16
- * (exit 1).
17
- *
18
- * node packages/frontend/eslint-boundaries/src/scorecard.js --out scorecard.json
19
- */
20
-
21
- import fs from "node:fs";
22
- import { createRequire } from "node:module";
23
- import path from "node:path";
24
- import process from "node:process";
25
- import { pathToFileURL } from "node:url";
26
-
27
- import { lintCaseFindings } from "./corpus-harness.js";
28
-
29
- const require = createRequire(import.meta.url);
30
-
31
- const RULE_ID_RE = /^(backend\/[a-z0-9_]+|frontend\/[a-z0-9-]+)$/;
32
- const SEMVER_RE = /^\d+\.\d+\.\d+$/;
33
-
34
- /** The @terpjs/spec root — resolved lazily so importing this module never requires it. */
35
- function specRoot() {
36
- return path.dirname(require.resolve("@terpjs/spec/package.json"));
37
- }
38
-
39
- /** Build the @terpjs/eslint-boundaries scorecard over the frontend corpus. */
40
- export async function buildScorecard() {
41
- const root = specRoot();
42
- const catalogDir = path.join(root, "catalog", "frontend");
43
- const corpusDir = path.join(root, "corpus", "frontend");
44
- const residuals = JSON.parse(
45
- fs.readFileSync(path.join(root, "corpus", "RESIDUALS.json"), "utf8"),
46
- ).residuals;
47
- const packageVersion = JSON.parse(
48
- fs.readFileSync(new URL("../package.json", import.meta.url), "utf8"),
49
- ).version;
50
-
51
- const rules = [];
52
- const entries = fs
53
- .readdirSync(catalogDir)
54
- .filter((name) => name.endsWith(".json"))
55
- .map((name) => JSON.parse(fs.readFileSync(path.join(catalogDir, name), "utf8")))
56
- .filter((entry) => entry.corpus);
57
- const consumedRuleIds = new Set(
58
- fs
59
- .readdirSync(catalogDir)
60
- .filter((name) => name.endsWith(".json"))
61
- .map((name) => JSON.parse(fs.readFileSync(path.join(catalogDir, name), "utf8")).id),
62
- );
63
- for (const entry of entries) {
64
- const ruleDir = path.join(corpusDir, entry.id.split("/")[1]);
65
- let pass = true;
66
- for (const caseName of fs.readdirSync(ruleDir).sort()) {
67
- const caseDir = path.join(ruleDir, caseName);
68
- if (!fs.statSync(caseDir).isDirectory()) continue;
69
- // A framework implementation lands before its Standard candidate can certify.
70
- // While running against the last published pin, ignore those forward rule ids;
71
- // a substituted candidate includes them in consumedRuleIds and exercises them.
72
- // Unattributed findings remain failures rather than disappearing in the filter.
73
- const fired = (await lintCaseFindings(caseDir))
74
- .filter((finding) => finding.rule === null || consumedRuleIds.has(finding.rule))
75
- .map((finding) => finding.rule);
76
- if (caseName.startsWith("violation-") && !fired.includes(entry.id)) pass = false;
77
- if (caseName.startsWith("compliant-") && fired.length > 0) pass = false;
78
- }
79
- const claim = { rule: entry.id, pass };
80
- if (residuals[entry.id]?.length) claim.residuals_claimed = [...residuals[entry.id]];
81
- rules.push(claim);
82
- }
83
- return {
84
- spec_version: fs.readFileSync(path.join(root, "VERSION"), "utf8").trim(),
85
- checker: { tool: "@terpjs/eslint-boundaries", version: packageVersion },
86
- rules,
87
- };
88
- }
89
-
90
- /** Hold the scorecard to its published contract; returns the problems. */
91
- export function validateScorecard(scorecard) {
92
- const problems = [];
93
- if (!SEMVER_RE.test(String(scorecard.spec_version ?? ""))) {
94
- problems.push("spec_version is not a semver string");
95
- }
96
- if (!scorecard.checker?.tool || !scorecard.checker?.version) {
97
- problems.push("checker must carry tool and version");
98
- }
99
- const root = specRoot();
100
- const residuals = JSON.parse(
101
- fs.readFileSync(path.join(root, "corpus", "RESIDUALS.json"), "utf8"),
102
- ).residuals;
103
- const catalogued = fs
104
- .readdirSync(path.join(root, "catalog", "frontend"))
105
- .filter((name) => name.endsWith(".json"))
106
- .map((name) =>
107
- JSON.parse(fs.readFileSync(path.join(root, "catalog", "frontend", name), "utf8")),
108
- )
109
- .filter((entry) => entry.corpus)
110
- .map((entry) => entry.id);
111
- const rules = scorecard.rules ?? [];
112
- if (rules.length === 0) problems.push("a scorecard without rule claims certifies nothing");
113
- const claimed = new Set();
114
- for (const claim of rules) {
115
- claimed.add(claim.rule);
116
- if (!RULE_ID_RE.test(String(claim.rule ?? ""))) {
117
- problems.push(`bad rule id: ${claim.rule}`);
118
- }
119
- if (typeof claim.pass !== "boolean") {
120
- problems.push(`${claim.rule}: pass must be a boolean`);
121
- } else if (!claim.pass) {
122
- problems.push(`${claim.rule}: the reference adapter must pass its own corpus`);
123
- }
124
- for (const residual of claim.residuals_claimed ?? []) {
125
- if (!(residuals[claim.rule] ?? []).includes(residual)) {
126
- problems.push(`${claim.rule}: claims an unrecorded residual: ${residual}`);
127
- }
128
- }
129
- }
130
- const missing = catalogued.filter((id) => !claimed.has(id));
131
- if (missing.length > 0) {
132
- problems.push(`corpus-covered rules missing a claim: ${missing.join(", ")}`);
133
- }
134
- return problems;
135
- }
136
-
137
- async function main() {
138
- const args = process.argv.slice(2);
139
- const outIndex = args.indexOf("--out");
140
- const out = outIndex !== -1 ? args[outIndex + 1] : "";
141
- const scorecard = await buildScorecard();
142
- const problems = validateScorecard(scorecard);
143
- if (problems.length > 0) {
144
- for (const problem of problems) process.stderr.write(`scorecard: ${problem}\n`);
145
- process.exitCode = 1;
146
- return;
147
- }
148
- const rendered = `${JSON.stringify(scorecard, null, 2)}\n`;
149
- if (out) {
150
- fs.writeFileSync(out, rendered);
151
- process.stderr.write(
152
- `wrote ${out} (${scorecard.rules.length} rule claims, spec ${scorecard.spec_version})\n`,
153
- );
154
- } else {
155
- process.stdout.write(rendered);
156
- }
157
- }
158
-
159
- // Run main() only when invoked as a CLI, not on import (the findings.js pattern).
160
- const entry = process.argv[1] ? pathToFileURL(fs.realpathSync(process.argv[1])).href : "";
161
- if (entry === import.meta.url) {
162
- main().catch((error) => {
163
- console.error(String(error));
164
- process.exitCode = 2;
165
- });
166
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * The scorecard emitter is held to the published certification contract
3
- * (spec/scorecard.schema.json): the adapter's scorecard validates, claims the
4
- * whole corpus-covered frontend catalog, passes it, and only relies on the
5
- * residuals the spec records. The emitter reuses the corpus test's own harness
6
- * (./corpus-harness.js), so a scorecard can never disagree with the suite.
7
- */
8
-
9
- import fs from "node:fs";
10
- import { createRequire } from "node:module";
11
- import path from "node:path";
12
-
13
- import { describe, expect, it } from "vitest";
14
-
15
- import { buildScorecard, validateScorecard } from "./scorecard.js";
16
-
17
- const SPEC_ROOT = path.dirname(
18
- createRequire(import.meta.url).resolve("@terpjs/spec/package.json"),
19
- );
20
-
21
- describe("the @terpjs/eslint-boundaries scorecard", () => {
22
- it("claims the whole corpus-covered catalog, green, schema-shaped", async () => {
23
- const scorecard = await buildScorecard();
24
- expect(validateScorecard(scorecard)).toEqual([]);
25
-
26
- // Schema shape, field by field (the spec suite's minimal-validator discipline).
27
- const schema = JSON.parse(
28
- fs.readFileSync(path.join(SPEC_ROOT, "scorecard.schema.json"), "utf8"),
29
- );
30
- for (const field of schema.required) expect(scorecard).toHaveProperty(field);
31
- for (const field of Object.keys(scorecard)) {
32
- expect(Object.keys(schema.properties)).toContain(field);
33
- }
34
- expect(scorecard.spec_version).toBe(
35
- fs.readFileSync(path.join(SPEC_ROOT, "VERSION"), "utf8").trim(),
36
- );
37
- expect(scorecard.checker.tool).toBe("@terpjs/eslint-boundaries");
38
- const itemProperties = Object.keys(schema.properties.rules.items.properties);
39
- for (const claim of scorecard.rules) {
40
- expect(claim.pass).toBe(true);
41
- for (const field of Object.keys(claim)) expect(itemProperties).toContain(field);
42
- }
43
- }, 120_000);
44
-
45
- it("rejects a scorecard claiming an unrecorded residual or a failing rule", async () => {
46
- const scorecard = await buildScorecard();
47
- const failing = {
48
- ...scorecard,
49
- rules: [{ ...scorecard.rules[0], pass: false }, ...scorecard.rules.slice(1)],
50
- };
51
- expect(validateScorecard(failing).join("\n")).toMatch(/must pass its own corpus/);
52
- const overclaiming = {
53
- ...scorecard,
54
- rules: [
55
- { ...scorecard.rules[0], residuals_claimed: ["a residual the spec never recorded"] },
56
- ...scorecard.rules.slice(1),
57
- ],
58
- };
59
- expect(validateScorecard(overclaiming).join("\n")).toMatch(/unrecorded residual/);
60
- }, 120_000);
61
- });