-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
421 lines (397 loc) · 15.8 KB
/
Copy patheslint.config.mjs
File metadata and controls
421 lines (397 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import importPlugin from "eslint-plugin-import-x";
import noBarrelFiles from "eslint-plugin-no-barrel-files";
import { createConfig, strict } from "eslint-plugin-boundaries/config";
import { resolve } from "node:path";
// ---------------------------------------------------------------------------
// Folder dependency graph — enforced by eslint-plugin-boundaries.
//
// Every src/ folder is declared as an element type. The boundaries/dependencies
// rule uses an allowlist (default: "disallow") so any import not listed below
// is an error. This statically guarantees the folder-level dependency graph is
// acyclic; a governance test (tests/unit/governance/no-folder-cycles.test.ts)
// additionally verifies that the declared policies cannot form a cycle.
//
// Built with the official createConfig helper, which registers the plugin and
// validates every settings/rule key. We deliberately do NOT set
// boundaries/include: classification is done entirely via element descriptors,
// and the flat-config `files` field below scopes the rules to architecture
// source files (root config files are simply not linted by this entry). Setting
// `include` would classify resolved node_modules targets as ignored files, which
// would make boundaries/no-ignored-dependencies fire on every external import.
//
// We start from the `strict` preset (all four rules at severity 2) and override
// boundaries/elements and boundaries/dependencies with the project graph.
// ---------------------------------------------------------------------------
const boundariesConfig = createConfig({
files: ["src/**/*.ts", "tests/**/*.ts", "scripts/**/*.ts"],
settings: {
"boundaries/root-path": resolve(import.meta.dirname),
"boundaries/legacy-templates": false,
"boundaries/elements": [
{ type: "action", pattern: "src/action" },
{ type: "artifact", pattern: "src/artifact" },
{ type: "builder", pattern: "src/builder" },
{ type: "comment", pattern: "src/comment" },
{ type: "diff", pattern: "src/diff" },
{ type: "drift-filter", pattern: "src/drift-filter" },
{ type: "elements", pattern: "src/elements" },
{ type: "env", pattern: "src/env" },
{ type: "flattener", pattern: "src/flattener" },
{ type: "github", pattern: "src/github" },
{ type: "html", pattern: "src/html" },
{ type: "http", pattern: "src/http" },
{ type: "inputs", pattern: "src/inputs" },
{ type: "jsonl-scanner", pattern: "src/jsonl-scanner" },
{ type: "logger", pattern: "src/logger" },
{ type: "model", pattern: "src/model" },
{ type: "parser", pattern: "src/parser" },
{ type: "pipelines", pattern: "src/pipelines" },
{ type: "raw-formatter", pattern: "src/raw-formatter" },
{ type: "renderable", pattern: "src/renderable" },
{ type: "sensitivity", pattern: "src/sensitivity" },
{ type: "steps", pattern: "src/steps" },
{ type: "tfjson", pattern: "src/tfjson" },
{ type: "tests", pattern: "tests" },
{ type: "scripts", pattern: "scripts" },
],
},
rules: {
...strict.rules,
"boundaries/dependencies": [
"error",
{
default: "disallow",
checkAllOrigins: true,
checkUnknownLocals: true,
policies: [
// Folders with no local dependencies
{ from: { element: { type: "tfjson" } }, allow: [] },
{ from: { element: { type: "env" } }, allow: [] },
{ from: { element: { type: "diff" } }, allow: [] },
{ from: { element: { type: "sensitivity" } }, allow: [] },
{ from: { element: { type: "raw-formatter" } }, allow: [] },
{ from: { element: { type: "logger" } }, allow: [] },
{ from: { element: { type: "html" } }, allow: [] },
{
from: { element: { type: "model" } },
allow: [{ to: { element: { type: "tfjson" } } }],
},
{
from: { element: { type: "renderable" } },
allow: [{ to: { element: { type: "model" } } }],
},
{
from: { element: { type: "flattener" } },
allow: [{ to: { element: { type: "tfjson" } } }],
},
{
from: { element: { type: "jsonl-scanner" } },
allow: [
{ to: { element: { type: "model" } } },
{ to: { element: { type: "tfjson" } } },
{ to: { module: { origin: "core", source: "node:fs" } } },
],
},
{
from: { element: { type: "http" } },
allow: [
{ to: { element: { type: "env" } } },
{ to: { module: { origin: "core", source: "node:http" } } },
{ to: { module: { origin: "core", source: "node:https" } } },
{ to: { module: { origin: "core", source: "node:tls" } } },
],
},
{
from: { element: { type: "parser" } },
allow: [
{ to: { element: { type: "model" } } },
{ to: { element: { type: "tfjson" } } },
],
},
{
from: { element: { type: "steps" } },
allow: [
{ to: { element: { type: "env" } } },
{ to: { element: { type: "model" } } },
{ to: { module: { origin: "core", source: "node:fs" } } },
{ to: { module: { origin: "core", source: "node:path" } } },
],
},
{
from: { element: { type: "github" } },
allow: [{ to: { element: { type: "http" } } }],
},
{
from: { element: { type: "inputs" } },
allow: [
{ to: { element: { type: "env" } } },
{ to: { module: { origin: "core", source: "node:fs" } } },
],
},
{
from: { element: { type: "drift-filter" } },
allow: [{ to: { element: { type: "model" } } }],
},
{
from: { element: { type: "artifact" } },
allow: [
{ to: { element: { type: "http" } } },
{ to: { module: { origin: "core", source: "node:crypto" } } },
],
},
{
from: { element: { type: "comment" } },
allow: [
{ to: { element: { type: "env" } } },
{ to: { element: { type: "model" } } },
],
},
{
from: { element: { type: "builder" } },
allow: [
{ to: { element: { type: "diff" } } },
{ to: { element: { type: "drift-filter" } } },
{ to: { element: { type: "env" } } },
{ to: { element: { type: "flattener" } } },
{ to: { element: { type: "jsonl-scanner" } } },
{ to: { element: { type: "model" } } },
{ to: { element: { type: "parser" } } },
{ to: { element: { type: "renderable" } } },
{ to: { element: { type: "sensitivity" } } },
{ to: { element: { type: "steps" } } },
{ to: { element: { type: "tfjson" } } },
{ to: { module: { origin: "core", source: "node:os" } } },
],
},
{
from: { element: { type: "elements" } },
allow: [
{ to: { element: { type: "builder" } } },
{ to: { element: { type: "diff" } } },
{ to: { element: { type: "model" } } },
{ to: { element: { type: "renderable" } } },
{ to: { element: { type: "tfjson" } } },
],
},
{
from: { element: { type: "pipelines" } },
allow: [
{ to: { element: { type: "builder" } } },
{ to: { element: { type: "elements" } } },
{ to: { element: { type: "jsonl-scanner" } } },
{ to: { element: { type: "model" } } },
{ to: { element: { type: "parser" } } },
{ to: { element: { type: "renderable" } } },
],
},
{
from: { element: { type: "action" } },
allow: [
{ to: { element: { type: "artifact" } } },
{ to: { element: { type: "builder" } } },
{ to: { element: { type: "comment" } } },
{ to: { element: { type: "env" } } },
{ to: { element: { type: "github" } } },
{ to: { element: { type: "html" } } },
{ to: { element: { type: "http" } } },
{ to: { element: { type: "inputs" } } },
{ to: { element: { type: "logger" } } },
{ to: { element: { type: "pipelines" } } },
{ to: { module: { origin: "core", source: "node:crypto" } } },
],
},
// tests and scripts may import anything
{
from: { element: { type: "tests" } },
allow: [
{ to: { module: { origin: "local" } } },
{ to: { module: { origin: "core" } } },
{ to: { module: { origin: "external" } } },
],
},
{
from: { element: { type: "scripts" } },
allow: [
{ to: { module: { origin: "local" } } },
{ to: { module: { origin: "core" } } },
{ to: { module: { origin: "external" } } },
],
},
],
},
],
},
});
// The import/resolver setting is not a boundaries/* key, so createConfig cannot
// accept it. Merge it onto the generated entry (it resolves .js specifiers to
// their .ts sources so boundaries can classify imports).
const boundariesEntry = {
...boundariesConfig,
settings: {
...boundariesConfig.settings,
"import/resolver": {
typescript: { project: "./tsconfig.test.json" },
},
},
};
export default tseslint.config(
// .mjs files in scripts/ use plain JS and can't be included in tsconfig —
// exclude them from TypeScript type-aware linting.
{ ignores: ["scripts/*.mjs"] },
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
{
languageOptions: {
parserOptions: {
// tsconfig.test.json includes both src/**/*.ts and tests/**/*.ts,
// making it the single source of truth for all linted files.
project: "./tsconfig.test.json",
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {
"import-x": importPlugin,
},
rules: {
// Require .js extensions on all relative ESM imports
"import-x/extensions": ["error", "ignorePackages", { js: "always" }],
// Prefer explicit return types on exported functions for readability
"@typescript-eslint/explicit-module-boundary-types": "error",
// These are fine in well-typed code
"@typescript-eslint/no-unnecessary-condition": "error",
// Allow void as a statement (e.g. fire-and-forget patterns)
"@typescript-eslint/no-confusing-void-expression": "off",
// non-nullable-type-assertion-style conflicts with no-non-null-assertion:
// the former wants "!", the latter forbids it. Disable the former.
"@typescript-eslint/non-nullable-type-assertion-style": "off",
},
},
{
// Test files don't need explicit return types; relax several strict rules
files: ["tests/**/*.ts"],
rules: {
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-explicit-any": "off",
// Test assertions commonly use ! to access array elements after asserting length
"@typescript-eslint/no-non-null-assertion": "off",
},
},
{
// Sentinel string constants must only be used in the builder layer (where they
// are assigned as display text). The elements layer must use boolean flags
// (isSensitive, isKnownAfterApply) for logic, never string comparison.
files: ["src/elements/**/*.ts"],
rules: {
"no-restricted-imports": [
"error",
{
paths: [
{
name: "../model/sentinels.js",
message:
"Elements must not import sentinel strings. Use boolean flags (isSensitive, isKnownAfterApply) instead of string comparison.",
},
],
},
],
},
},
{
// tfjson/ is copied external code — skip linting it
files: ["src/tfjson/**/*.ts"],
rules: {
"import-x/extensions": "off",
"@typescript-eslint/consistent-indexed-object-style": "off",
"@typescript-eslint/no-empty-object-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
},
},
boundariesEntry,
{
// Forbid direct process/console access in source files — all I/O must go
// through the injected Logger interface. The only exception is
// src/logger/index.ts which provides the production implementation.
//
// Also forbid inline import("...") type expressions; they are invisible to
// eslint-plugin-boundaries and bypass folder dependency checks.
files: ["src/**/*.ts"],
ignores: ["src/logger/index.ts"],
rules: {
"no-restricted-syntax": [
"error",
{
selector: "TSImportType",
message:
"Use a top-level 'import type' declaration instead of an inline import() type expression. Inline import() types are invisible to eslint-plugin-boundaries and bypass folder dependency checks.",
},
{
selector:
"MemberExpression[object.name='process'][property.name='stderr']",
message:
"Use the injected Logger interface instead of process.stderr. See src/logger/index.ts.",
},
{
selector:
"MemberExpression[object.name='process'][property.name='stdout']",
message:
"Use the injected Logger interface instead of process.stdout. See src/logger/index.ts.",
},
{
selector:
"MemberExpression[object.name='console'][property.name='log']",
message:
"Use the injected Logger interface instead of console.log. See src/logger/index.ts.",
},
{
selector:
"MemberExpression[object.name='console'][property.name='error']",
message:
"Use the injected Logger interface instead of console.error. See src/logger/index.ts.",
},
{
selector:
"MemberExpression[object.name='console'][property.name='warn']",
message:
"Use the injected Logger interface instead of console.warn. See src/logger/index.ts.",
},
],
},
},
{
// Also forbid inline import("...") type expressions in tests and scripts.
// Kept as a separate block because the src/ block above uses `ignores` to
// carve out src/logger/index.ts; these two dirs have no such exception.
files: ["tests/**/*.ts", "scripts/**/*.ts"],
rules: {
"no-restricted-syntax": [
"error",
{
selector: "TSImportType",
message:
"Use a top-level 'import type' declaration instead of an inline import() type expression. Inline import() types are invisible to eslint-plugin-boundaries and bypass folder dependency checks.",
},
],
},
},
{
ignores: ["dist/**", "coverage/**", "node_modules/**"],
},
{
// Prohibit barrel files (re-exporting imported bindings) across all source.
// This codebase is not a library; every import must point to the file that
// defines the symbol.
files: ["src/**/*.ts", "tests/**/*.ts", "scripts/**/*.ts"],
plugins: {
"no-barrel-files": noBarrelFiles,
},
rules: {
"no-barrel-files/no-barrel-files": "error",
},
},
);