@terpjs/eslint-boundaries 0.42.0 → 0.43.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terpjs/eslint-boundaries",
3
- "version": "0.42.0",
3
+ "version": "0.43.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",
@@ -27,11 +27,11 @@
27
27
  "eslint": ">=9"
28
28
  },
29
29
  "dependencies": {
30
- "typescript-eslint": "^8.72.1"
30
+ "typescript-eslint": "^8.72.2"
31
31
  },
32
32
  "devDependencies": {
33
- "@terpjs/spec": "0.46.0",
34
- "eslint": "^10.14.0",
33
+ "@terpjs/spec": "0.48.0",
34
+ "eslint": "^10.15.0",
35
35
  "vitest": "^5.1.0"
36
36
  },
37
37
  "license": "Apache-2.0",
package/src/budget.js CHANGED
@@ -45,7 +45,7 @@ function parsedReviewDate(value) {
45
45
  }
46
46
 
47
47
  /** Every app-authored `src/**` source file under *root*, recursively. */
48
- function sourceFiles(root) {
48
+ export function sourceFiles(root) {
49
49
  const sourceRoot = path.join(root, "src");
50
50
  if (!fs.existsSync(sourceRoot)) {
51
51
  return [];
package/src/findings.js CHANGED
@@ -2,8 +2,8 @@
2
2
  /**
3
3
  * The machine-readable boundary lint — the frontend analog of `terp check --format json`.
4
4
  *
5
- * `terp-boundaries-lint` runs the app's own ESLint config (the flat config in the cwd,
6
- * exactly what `eslint .` would load) **and** the escape-hatch budget ratchet (the same
5
+ * `terp-boundaries-lint` runs the shipped boundary config on app source, the app's own
6
+ * ESLint config on its configured files, and the escape-hatch budget ratchet (the same
7
7
  * check `terp-boundaries-budget` runs) in one command, and publishes one **findings
8
8
  * envelope** on stdout:
9
9
  *
@@ -50,8 +50,8 @@ import { pathToFileURL } from "node:url";
50
50
 
51
51
  import { ESLint } from "eslint";
52
52
 
53
- import { checkBudget } from "./budget.js";
54
- import { activeLayoutContract, catalogRuleId, catalogRuleIds } from "./index.js";
53
+ import { checkBudget, sourceFiles } from "./budget.js";
54
+ import { activeLayoutContract, catalogRuleId, catalogRuleIds, terpBoundaries } from "./index.js";
55
55
  import { SPEC_VERSION } from "./spec.js";
56
56
 
57
57
  /** This package's own version — the `checker.version` a check report carries. */
@@ -108,10 +108,15 @@ export function renderEnvelope(results, cwd = process.cwd(), options = {}) {
108
108
  const findings = [];
109
109
  const unattributed = [];
110
110
  const human = [];
111
+ const seen = new Set();
111
112
  for (const result of results) {
112
113
  const relative = path.relative(cwd, result.filePath).split(path.sep).join("/");
113
114
  const file = relative === "" ? result.filePath.split(path.sep).join("/") : relative;
114
115
  for (const message of result.messages) {
116
+ // The app config normally includes Terp. Publish a shared diagnostic once.
117
+ const key = JSON.stringify([file, message.line, message.column, message.ruleId, message.message]);
118
+ if (seen.has(key)) continue;
119
+ seen.add(key);
115
120
  const rule = catalogRuleId(message);
116
121
  const line = Number.isInteger(message.line) && message.line > 0 ? message.line : 1;
117
122
  if (rule === null) {
@@ -174,6 +179,16 @@ async function main() {
174
179
  args.splice(formatIndex, 2);
175
180
  }
176
181
  const budgetPath = args[0] ?? path.join(cwd, "escape-hatch-budget.json");
182
+ // Evaluate the published inventory with the package's config before loading app config.
183
+ // The budget and the lint walk the same app-authored files, including files an app ignores.
184
+ const sources = sourceFiles(cwd);
185
+ const boundaries = new ESLint({
186
+ overrideConfigFile: true,
187
+ overrideConfig: terpBoundaries(),
188
+ globInputPaths: false,
189
+ });
190
+ const mandatory = sources.length ? await boundaries.lintFiles(sources) : [];
191
+
177
192
  // The app's own config and ignore set. Two rules also read checked-in declarations
178
193
  // outside the linted source file, so include those bytes in the cache namespace.
179
194
  // Otherwise fixing i18n.json can replay a stale failure, and breaking it after a
@@ -198,7 +213,7 @@ async function main() {
198
213
  ".eslintcache",
199
214
  ),
200
215
  });
201
- const results = await eslint.lintFiles(["."]);
216
+ const results = [...mandatory, ...await eslint.lintFiles(["."])];
202
217
  // The ratchet runs regardless of the lint verdict — both halves always report.
203
218
  const budgetProblems = checkBudget(cwd, budgetPath);
204
219
  const relativeBudget = path.relative(cwd, budgetPath).split(path.sep).join("/");
@@ -197,6 +197,25 @@ describe("terp-boundaries-lint (the bin)", () => {
197
197
  expect(run.stderr).toMatch(/problem/);
198
198
  });
199
199
 
200
+ it("holds ignored app source to the shipped rules and keeps additional app diagnostics", () => {
201
+ const root = appRoot({
202
+ "package.json": '{ "type": "module" }',
203
+ "eslint.config.js": 'export default [{ ignores: ["src/private/**"] }, { rules: { "no-debugger": "error" } }];',
204
+ "escape-hatch-budget.json": "{}",
205
+ "src/private/View.tsx": "export const View = () => <button>ok</button>;",
206
+ "extra.js": "debugger;",
207
+ });
208
+ const run = runBin(root);
209
+ expect(run.status).toBe(1);
210
+ const report = JSON.parse(run.stdout);
211
+ expect(report.findings).toContainEqual(expect.objectContaining({
212
+ path: "src/private/View.tsx", rule: "frontend/token-styled-elements",
213
+ }));
214
+ expect(report.unattributed).toContainEqual(expect.objectContaining({
215
+ path: "extra.js", reported_as: "no-debugger",
216
+ }));
217
+ });
218
+
200
219
  it("stays green (exit 0) with an empty findings list on a clean app", () => {
201
220
  const root = appRoot({
202
221
  "package.json": '{ "type": "module" }',
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.46.0";
23
+ export const SPEC_VERSION = "0.48.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"];