@terpjs/eslint-boundaries 0.38.0 → 0.40.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.
@@ -8,8 +8,8 @@
8
8
  {
9
9
  "kind": "build-time",
10
10
  "tool": "@terpjs/eslint-boundaries",
11
- "ref": "BOUNDARY_SPEC.restrictLocalDateTimeInput",
12
- "reported_as": "no-restricted-syntax"
11
+ "ref": "terp/timestamp-inputs-carry-their-offset",
12
+ "reported_as": "terp/timestamp-inputs-carry-their-offset"
13
13
  },
14
14
  {
15
15
  "kind": "runtime",
@@ -17,7 +17,7 @@
17
17
  "ref": "refuse_timestamp_text_without_offset"
18
18
  }
19
19
  ],
20
- "reference": "Any JSX `type` attribute whose value is `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), as a string, an expression or a plain template. 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.",
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
21
  "opt_out": "// terp-allow-timestamp-inputs-carry-their-offset: <reason>",
22
22
  "runtime": {
23
23
  "applicability": "required",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terpjs/eslint-boundaries",
3
- "version": "0.38.0",
3
+ "version": "0.40.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",
@@ -30,7 +30,7 @@
30
30
  "typescript-eslint": "^8.72.1"
31
31
  },
32
32
  "devDependencies": {
33
- "@terpjs/spec": "0.43.0",
33
+ "@terpjs/spec": "0.45.0",
34
34
  "eslint": "^10.14.0",
35
35
  "vitest": "^5.0.5"
36
36
  },
package/src/findings.js CHANGED
@@ -62,11 +62,13 @@ const PACKAGE_VERSION = JSON.parse(
62
62
  /**
63
63
  * Render a findings envelope as the Terp Standard **check report**
64
64
  * (`app-check-report.schema.json`, printed by `--format check-report`): the same
65
- * inventory and findings, self-described with the spec version the rule ids resolve
66
- * against, the checker identity, and the run verdict — so a consumer joins per-rule
67
- * verdicts to the catalog without knowing this toolchain. `unattributed.reported_as`
68
- * is omitted (never null) per the schema; `ok` covers the standard's own findings
69
- * (the process exit code stays the combined verdict, unattributed errors included).
65
+ * inventory and findings, self-described with the release of the report format, the
66
+ * checker identity (whose version names the catalog release the rule ids resolve
67
+ * against: the catalog ships with this package, ADR 0203), and the run verdict — so a
68
+ * consumer joins per-rule verdicts to the catalog without knowing this toolchain.
69
+ * `unattributed.reported_as` is omitted (never null) per the schema; `ok` covers the
70
+ * standard's own findings (the process exit code stays the combined verdict,
71
+ * unattributed errors included).
70
72
  */
71
73
  export function asCheckReport(envelope) {
72
74
  return {
@@ -314,10 +314,9 @@ describe("the check report (--format check-report, app-check-report.schema.json)
314
314
  const { envelope } = renderEnvelope(results, path.resolve("."), { layoutContract: true });
315
315
  const report = asCheckReport(envelope);
316
316
  expect(report.terp_check_report).toBe(1);
317
- // The certified spec version rides every report. Shape only here — the
317
+ // The report format's release rides every report. Shape only here: the
318
318
  // equality lock against the pinned @terpjs/spec lives in the framework gate
319
- // (test_check_json.py), because certification runs THIS suite against
320
- // candidate spec releases whose version is allowed to be newer.
319
+ // (test_check_json.py), beside the lock on terp.arch.SPEC_VERSION.
321
320
  expect(report.spec_version).toMatch(/^\d+\.\d+\.\d+$/);
322
321
  expect(report.checker.tool).toBe("@terpjs/eslint-boundaries");
323
322
  expect(report.checker.version).toMatch(/^\d+\.\d+\.\d+$/);
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
 
@@ -1309,22 +1381,6 @@ function restrictedSyntaxWithCatalogIds() {
1309
1381
  },
1310
1382
  ]
1311
1383
  : [];
1312
- const localDateTime = BOUNDARY_SPEC.restrictLocalDateTimeInput
1313
- ? [
1314
- {
1315
- // The attribute on any element: `Input`, a raw `input` (refused on its own as well)
1316
- // or a wrapper that passes it through. Any letter case, since the browser reads the
1317
- // type case-insensitively, and as a string, an expression or a plain template.
1318
- catalogId: "frontend/timestamp-inputs-carry-their-offset",
1319
- selector:
1320
- "JSXAttribute[name.name='type'][value.value=/^datetime-local$/i], " +
1321
- "JSXAttribute[name.name='type'] > JSXExpressionContainer > Literal[value=/^datetime-local$/i], " +
1322
- "JSXAttribute[name.name='type'] > JSXExpressionContainer > " +
1323
- "TemplateLiteral[expressions.length=0][quasis.0.value.raw=/^datetime-local$/i]",
1324
- message: localDateTimeMessage,
1325
- },
1326
- ]
1327
- : [];
1328
1384
  // A stylesheet reached without an import declaration, which no-restricted-imports never
1329
1385
  // sees: `import("lib/style.css")`, `import(`./themes/${name}.css`)`, and a Vite
1330
1386
  // `import.meta.glob` whose pattern names a stylesheet (a string, or a string in the array
@@ -1358,7 +1414,6 @@ function restrictedSyntaxWithCatalogIds() {
1358
1414
  ...inAppAnchors,
1359
1415
  ...rawClipboard,
1360
1416
  ...rawRandomUuid,
1361
- ...localDateTime,
1362
1417
  ...dynamicStyleImports,
1363
1418
  {
1364
1419
  catalogId: "frontend/no-dom-html-injection",
@@ -1687,6 +1742,9 @@ export function terpBoundaries() {
1687
1742
  "terp/no-eval": "error",
1688
1743
  "terp/no-unsafe-href": "error",
1689
1744
  "terp/no-unsafe-target-blank": "error",
1745
+ ...(BOUNDARY_SPEC.restrictLocalDateTimeInput
1746
+ ? { "terp/timestamp-inputs-carry-their-offset": "error" }
1747
+ : {}),
1690
1748
  "no-restricted-syntax": ["error", ...restrictedSyntax()],
1691
1749
  "no-restricted-globals": [
1692
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
@@ -20,7 +20,7 @@
20
20
  * of the toolchain build. Held equal to the pinned release by the framework gate
21
21
  * (test_check_json.py).
22
22
  */
23
- export const SPEC_VERSION = "0.43.0";
23
+ export const SPEC_VERSION = "0.45.0";
24
24
 
25
25
  /** Every script extension the bundler loads as app source (see `appFiles`). */
26
26
  const SOURCE_EXTENSIONS = ["ts", "tsx", "mts", "cts", "js", "jsx", "mjs", "cjs"];