Repository navigation
Expand file tree
/
Copy patheslint.config.js
More file actions
395 lines (391 loc) · 16.9 KB
/
Copy patheslint.config.js
File metadata and controls
395 lines (391 loc) · 16.9 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
import {readFileSync, readdirSync} from 'node:fs'
import js from '@eslint/js'
import eslintReact from '@eslint-react/eslint-plugin'
import {createTypeScriptImportResolver} from 'eslint-import-resolver-typescript'
import importX from 'eslint-plugin-import-x'
import jsxA11y from 'eslint-plugin-jsx-a11y'
import reactHooks from 'eslint-plugin-react-hooks'
import regexp from 'eslint-plugin-regexp'
import unicorn from 'eslint-plugin-unicorn'
import globals from 'globals'
import {defineConfig} from 'eslint/config'
import tseslint from 'typescript-eslint'
import {consideredPlugin} from './tools/scripts/considered-rule.mjs'
import {engineContractsRule} from './tools/scripts/engine-contracts.mjs'
import {lifecycleFiles, machinesPlugin} from './tools/scripts/check-machines/lifecycle-rule.mjs'
// Vendored shadcn/ui components: each with a pristine base in upstream/, which test/shadcn.test.mjs reproduces it from.
const shadcn = 'packages/host/core/src/ui/components'
const vendored = readdirSync(`${import.meta.dirname}/${shadcn}/upstream`)
.filter(file => file.endsWith('.json') && file !== 'manifest.json')
.map(file => `${shadcn}/${file.replace(/\.json$/u, '.tsx')}`)
// Workspace directories (a single trailing `/*` level is a glob, as in tools/scripts/lint.mjs).
const {workspaces} = JSON.parse(readFileSync(`${import.meta.dirname}/package.json`, 'utf8'))
// The workspaces whose source is React.
const react = [
'packages/{schemas,machine,cli,integrations/vscode}/src/**/*.{ts,tsx}',
'packages/host/{core,vscode-ui,inspector}/src/**/*.{ts,tsx}',
'packages/{engine,renderers,extractors}/*/src/**/*.{ts,tsx}',
'examples/renderers/*/src/**/*.{ts,tsx}',
'tools/storybook/{src,stories,harness}/**/*.{ts,tsx}',
]
export default defineConfig(
{
ignores: [
'**/dist/**',
'**/storybook-static/**',
'tools/storybook/static/**',
'**/target/**',
'**/node_modules/**',
'**/fixtures/**',
'**/bin/**',
'**/obj/**',
'**/.data/**',
'**/.venv/**',
'**/__pycache__/**',
'**/test-results/**',
'**/.vscode-test/**',
// Scaffolding templates are checked filled in: the CLI's browser test
// builds and checks a scaffolded renderer with its own TypeScript setup.
'packages/cli/templates/renderer/**',
// Generated from packages/sdk/src/extractor.ts, which is linted.
'packages/cli/node/extractor.mjs',
'**/playwright-report/**',
// Build and test output, as the .gitignore files list it.
'**/pkg/**',
'packages/engine/js/artifacts/**',
'packages/sdk/vendor/**',
'packages/integrations/vscode/.package/**',
'packages/extractors/typescript-support/.runtime-*/**',
'tools/storybook/screenshots/**',
...vendored,
],
},
js.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
regexp.configs['flat/recommended'],
{
languageOptions: {
globals: {...globals.node, ...globals.browser},
parserOptions: {
// Each file's nearest tsconfig.json: a workspace's own, or its browser/ or test/ one.
projectService: {
// Configuration beside a workspace's tsconfig.json, which compiles only src.
allowDefaultProject: [
'examples/renderers/minimal/playwright.config.ts',
'packages/cli/playwright.config.ts',
'packages/host/core/playwright.config.ts',
'packages/host/inspector/playwright.config.ts',
'packages/host/vscode-ui/playwright.config.ts',
'packages/host/inspector/vite.config.ts',
'packages/host/core/build/*.d.mts',
'packages/host/core/scripts/*.d.mts',
],
defaultProject: 'tsconfig.base.json',
maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING: 12,
},
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
// Tuned: each option allows one well-defined idiom and nothing else (docs/maintainers/linting.md).
'@typescript-eslint/restrict-template-expressions': ['error', {allowNumber: true}],
'@typescript-eslint/no-confusing-void-expression': ['error', {ignoreArrowShorthand: true}],
'@typescript-eslint/no-floating-promises': [
'error',
{
allowForKnownSafeCalls: [
{
from: 'package',
package: 'node:test',
name: ['test', 'it', 'describe', 'suite', 'before', 'after', 'beforeEach', 'afterEach'],
},
],
},
],
'@typescript-eslint/strict-boolean-expressions': ['error', {allowNullableString: true, allowNullableBoolean: true}],
'@typescript-eslint/prefer-promise-reject-errors': ['error', {allowThrowingUnknown: true}],
'@typescript-eslint/no-use-before-define': ['error', {functions: false, classes: false, typedefs: false, ignoreTypeReferences: true}],
'@typescript-eslint/class-methods-use-this': ['error', {ignoreClassesThatImplementAnInterface: true, ignoreOverrideMethods: true}],
'@typescript-eslint/no-shadow': ['error', {ignoreTypeValueShadow: true, ignoreFunctionTypeParameterNameValueShadow: true}],
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/require-array-sort-compare': ['error', {ignoreStringArrays: true}],
'@typescript-eslint/parameter-properties': ['error', {prefer: 'class-property'}],
'@typescript-eslint/method-signature-style': ['error', 'property'],
'@typescript-eslint/consistent-type-imports': ['error', {fixStyle: 'inline-type-imports'}],
'@typescript-eslint/consistent-type-exports': ['error', {fixMixedExportsWithInlineTypeSpecifier: true}],
'@typescript-eslint/consistent-return': 'error',
'@typescript-eslint/default-param-last': 'error',
'@typescript-eslint/no-import-type-side-effects': 'error',
'@typescript-eslint/no-loop-func': 'error',
'@typescript-eslint/no-unsafe-type-assertion': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/strict-void-return': 'error',
'@typescript-eslint/switch-exhaustiveness-check': 'error',
// The TypeScript versions above replace these.
'no-unused-vars': 'off',
'consistent-return': 'off',
curly: ['error', 'multi-line'],
eqeqeq: ['error', 'always'],
// The u flag: strict escapes, and code points rather than UTF-16 halves (docs/maintainers/linting.md).
'regexp/require-unicode-regexp': 'error',
// `!!value` narrows `value` in TypeScript; `Boolean(value)` doesn't.
'no-implicit-coercion': ['error', {allow: ['!!']}],
...Object.fromEntries(
[
'array-callback-return',
'default-case-last',
'grouped-accessor-pairs',
'guard-for-in',
'logical-assignment-operators',
'no-alert',
'no-caller',
'no-constructor-return',
'no-eval',
'no-extend-native',
'no-extra-bind',
'no-labels',
'no-lone-blocks',
'no-lonely-if',
'no-multi-assign',
'no-new',
'no-new-func',
'no-new-wrappers',
'no-object-constructor',
'no-param-reassign',
'no-promise-executor-return',
'no-proto',
'no-return-assign',
'no-script-url',
'no-self-compare',
'no-sequences',
'no-template-curly-in-string',
'no-unassigned-vars',
'no-unmodified-loop-condition',
'no-unneeded-ternary',
'no-unreachable-loop',
'no-useless-assignment',
'no-useless-call',
'no-useless-computed-key',
'no-useless-concat',
'no-useless-rename',
'no-useless-return',
'no-var',
'object-shorthand',
'operator-assignment',
'prefer-arrow-callback',
'prefer-const',
'prefer-exponentiation-operator',
'prefer-numeric-literals',
'prefer-object-has-own',
'prefer-object-spread',
'prefer-regex-literals',
'prefer-rest-params',
'prefer-spread',
'prefer-template',
'preserve-caught-error',
'radix',
'symbol-description',
'yoda',
].map(rule => [rule, 'error']),
),
},
},
{
// Shipped libraries and UIs report through their callers, not the console; CLIs, scripts and tests print by design.
files: ['packages/**/src/**/*.{ts,tsx}'],
ignores: ['packages/integrations/github-action/**'],
rules: {'no-console': 'error'},
},
{
// What Considered measures (.considered.yaml) has to be readable by its scc provider (tools/scripts/considered-rule.mjs).
plugins: {considered: consideredPlugin},
rules: {'considered/regex-backtick': 'error'},
},
{
// Tests of GitHub Actions workflows and of prose about template literals: the literal `${` text is what they check.
files: [
'packages/cli/test/release.test.mjs',
'packages/integrations/github-action/test/action.test.mjs',
'packages/renderers/agentic-workflows/test/agentic-workflows.test.mjs',
'packages/schemas/test/prose.test.mjs',
],
rules: {'no-template-curly-in-string': 'off'},
},
{
// JavaScript has no annotations, so type-aware rules would only report `any`; every other rule still applies.
files: ['**/*.{js,mjs,cjs}'],
...tseslint.configs.disableTypeChecked,
},
{
// Decisions the engine owns (tools/scripts/engine-contracts.mjs): the code outside it asks the engine.
files: ['**/src/**/*.{ts,tsx,js,mjs}', 'tools/**/*.{ts,tsx,js,mjs}'],
// Renderers can't reach the engine from their sandboxed frames; they classify rows through the renderer SDK.
ignores: ['packages/engine/**', 'packages/renderers/**', 'tools/scripts/engine-contracts.test.mjs'],
rules: {'no-restricted-syntax': engineContractsRule},
},
{
// The Rules of Hooks and the React Compiler's rules (refs, purity, immutability, set-state-in-effect…), all errors.
files: react,
plugins: {'react-hooks': reactHooks},
rules: Object.fromEntries(Object.keys(reactHooks.configs['recommended-latest'].rules).map(rule => [rule, 'error'])),
},
{
// What the React Compiler's rules don't cover: leaked listeners and timers, unstable context values and default
// props, conditions that render `0`, index keys, and the APIs React 19 replaces (docs/maintainers/linting.md).
files: react,
// The extractors aren't React, and NestJS has a `forwardRef` of its own.
ignores: ['packages/extractors/**'],
plugins: {'@eslint-react': eslintReact},
rules: Object.fromEntries(
[
'no-leaked-conditional-rendering',
'no-unstable-context-value',
'no-unstable-default-props',
'no-array-index-key',
'web-api-no-leaked-event-listener',
'web-api-no-leaked-timeout',
'dom-no-flush-sync',
'no-context-provider',
'no-forward-ref',
'no-use-context',
].map(rule => [`@eslint-react/${rule}`, 'error']),
),
},
{
// Accessibility of the hosts' and renderers' markup: semantic elements, keyboard support for what responds to the
// mouse, and a name for every control.
files: ['**/*.tsx'],
...jsxA11y.flatConfigs.strict,
rules: {
...jsxA11y.flatConfigs.strict.rules,
// Its label may be text a few elements in: a table header's button's code, a heading's prose.
'jsx-a11y/control-has-associated-label': [
'error',
{...jsxA11y.flatConfigs.strict.rules['jsx-a11y/control-has-associated-label'][1], depth: 4},
],
// A tab panel, a window splitter (a focusable separator) and a scrollable region take focus in the ARIA patterns.
'jsx-a11y/no-noninteractive-tabindex': ['error', {roles: ['tabpanel', 'separator', 'region']}],
// A component's `autoFocus` prop is its own API: the pane that takes focus when asked to (focus moves on purpose).
'jsx-a11y/no-autofocus': ['error', {ignoreNonDOM: true}],
},
},
{
// Imports between modules and packages: cycles, duplicate and redundant imports, and packages a workspace uses
// without declaring. TypeScript already reports imports that don't resolve, so no rule here repeats that.
plugins: {'import-x': importX},
settings: {
'import-x/extensions': ['.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.mjs', '.cjs'],
'import-x/parsers': {'@typescript-eslint/parser': ['.ts', '.tsx', '.mts', '.cts']},
'import-x/resolver-next': [
createTypeScriptImportResolver({
// Each workspace's tsconfig.json and its browser/ and test/ ones; a file resolves through the one including it.
project: workspaces.flatMap(workspace => [`${workspace}/tsconfig.json`, `${workspace}/{browser,test}/tsconfig.json`]),
noWarnOnMultipleProjects: true,
}),
],
// The VS Code host provides it to the extension at run time.
'import-x/core-modules': ['vscode'],
},
rules: {
// Type-only imports don't count: they're erased, so they can't make modules evaluate in the wrong order.
'import-x/no-cycle': ['error', {ignoreExternal: true}],
'import-x/no-self-import': 'error',
'import-x/no-duplicates': ['error', {'prefer-inline': true}],
'import-x/no-useless-path-segments': 'error',
'import-x/no-mutable-exports': 'error',
'import-x/first': 'error',
'import-x/no-extraneous-dependencies': 'error',
},
},
{
// What ships imports only its dependencies and peer dependencies; tests, specs, scripts and configuration may also
// use development ones. Workspaces that bundle their build declare what they bundle as development dependencies:
// the SDK bundles the internal workspaces, the VS Code extension everything but `vscode`, and the TypeScript helper
// replaces `typescript` with the examined repository's own installation.
files: ['packages/**/src/**'],
ignores: ['packages/sdk/**', 'packages/integrations/vscode/**', 'packages/extractors/typescript-support/**'],
rules: {'import-x/no-extraneous-dependencies': ['error', {devDependencies: false}]},
},
{
// The renderers' and the kit's browser suites run in the renderer harness, so they import it and what it declares
// (as npm run check:boundaries allows).
files: ['packages/renderers/*/browser/**'],
rules: {
'import-x/no-extraneous-dependencies': [
'error',
{
packageDir: [`${import.meta.dirname}/packages/renderers/harness`],
whitelist: ['@githubnext/projections-renderer-harness'],
},
],
},
},
{
// eslint-plugin-unicorn's rules that find bugs and footguns: mutating sorts, coercing globals, lost error types, wrong
// DOM and promise APIs. Its stylistic rules stay off (docs/maintainers/linting.md#eslint-plugin-unicorn).
plugins: {unicorn},
rules: {
'unicorn/prefer-export-from': ['error', {checkUsedVariables: false}],
...Object.fromEntries(
[
'consistent-assert',
'error-message',
'new-for-builtins',
'no-array-reverse',
'no-array-sort',
'no-await-in-promise-methods',
'no-instanceof-builtins',
'no-invalid-remove-event-listener',
'no-new-array',
'no-single-promise-in-promise-methods',
'no-typeof-undefined',
'no-unnecessary-await',
'no-useless-fallback-in-spread',
'no-useless-promise-resolve-reject',
'no-useless-spread',
'no-useless-switch-case',
'prefer-add-event-listener',
'prefer-array-find',
'prefer-array-flat-map',
'prefer-array-index-of',
'prefer-array-some',
'prefer-at',
'prefer-global-this',
'prefer-includes',
'prefer-node-protocol',
'prefer-number-properties',
'prefer-regexp-test',
'prefer-set-has',
'prefer-string-replace-all',
'prefer-structured-clone',
'prefer-type-error',
'require-array-join-separator',
'text-encoding-identifier-case',
'throw-new-error',
].map(rule => [`unicorn/${rule}`, 'error']),
),
},
},
{
// innerText lays the page out to read it: shipped code reads textContent. Browser tests read what is rendered.
files: ['packages/**/src/**/*.{ts,tsx}'],
rules: {'unicorn/prefer-dom-node-text-content': 'error'},
},
{
// Lifecycles are explicit state machines (docs/guides/state-machines.md). A warning here; npm run check:machines
// fails when a file gains one over tools/scripts/check-machines/baseline.json.
files: lifecycleFiles,
plugins: {machines: machinesPlugin},
rules: {'machines/lifecycle': 'warn'},
},
)