-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy patheslint.config.js
More file actions
356 lines (344 loc) · 13.1 KB
/
Copy patheslint.config.js
File metadata and controls
356 lines (344 loc) · 13.1 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
// Copyright (c) Meta Platforms, Inc. and affiliates.
import js from "@eslint/js";
import tseslint from "typescript-eslint";
import eslintReact from "@eslint-react/eslint-plugin";
import reactCompiler from "eslint-plugin-react-compiler";
import xdsPlugin from "./internal/eslint-plugin-astryx/index.js";
/* global process */
/**
* XDS ESLint Configuration
*
* Two-tier linting philosophy:
* - CI/Agents: Strict mode (errors) - Set ASTRYX_STRICT_LINT=1 or CI=true
* - Humans: Recommended mode (warnings) - Default for local development
*
* Usage:
* pnpm lint # Human mode (warnings)
* ASTRYX_STRICT_LINT=1 pnpm lint # Strict mode (errors)
* CI=true pnpm lint # Also triggers strict mode
*/
const isStrictMode = process.env.ASTRYX_STRICT_LINT === '1' || process.env.CI === 'true';
const xdsConfig = isStrictMode ? xdsPlugin.configs.strict : xdsPlugin.configs.recommended;
const reactSeverity = isStrictMode ? 'error' : 'warn';
export default tseslint.config(
js.configs.recommended,
...tseslint.configs.recommended,
{
ignores: [
"**/dist/**",
"**/node_modules/**",
".claude/**",
"**/internal/eslint-plugin-astryx/**",
".github/scripts/**",
"scripts/**",
// Changesets tooling (custom changelog module + config) is CommonJS
// build/release glue, not shipped source — keep it out of the TS/ESM
// lint pass (consistent with scripts/** above).
".changeset/**",
// .mjs is ignored everywhere EXCEPT the CLI package, whose runtime is
// entirely .mjs. The negations below opt packages/cli back into linting
// (see the dedicated CLI block lower down). Scoped to packages/cli on
// purpose — other packages' .mjs stay unlinted (#2468).
"**/*.mjs",
"!packages/cli/src/**/*.mjs",
"!packages/cli/bin/**/*.mjs",
"**/*.test-violations.tsx",
"apps/example-nextjs/*.js",
"**/next-env.d.ts",
"**/.next/**",
"apps/example-nextjs-source/*.js",
"apps/docsite/*.js",
"apps/docsite/scripts/**",
"apps/sandbox/*.js",
"apps/sandbox/out/**",
"packages/build/**",
],
},
{
files: ["**/*.{ts,tsx}"],
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
rules: {
"@typescript-eslint/no-unused-vars": ["warn", {
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
}],
"no-console": ["warn", { allow: ["warn", "error"] }],
"curly": "warn",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/consistent-type-assertions": ["warn", {
assertionStyle: "as",
objectLiteralTypeAssertions: "never",
}],
"@typescript-eslint/consistent-type-imports": [
"warn",
{fixStyle: "inline-type-imports"},
],
},
},
// Type-aware linting for core. Keep this scoped: projectService has a
// measurable startup cost, but catches async correctness issues syntax-only
// lint cannot see.
{
files: ["packages/core/src/**/*.{ts,tsx}"],
languageOptions: {
parserOptions: {
projectService: true,
},
},
rules: {
"@typescript-eslint/array-type": [
reactSeverity,
{default: "array", readonly: "generic"},
],
"@typescript-eslint/await-thenable": reactSeverity,
"@typescript-eslint/no-array-delete": reactSeverity,
"@typescript-eslint/no-base-to-string": reactSeverity,
"@typescript-eslint/no-duplicate-type-constituents": reactSeverity,
"@typescript-eslint/no-dynamic-delete": reactSeverity,
"@typescript-eslint/no-floating-promises": reactSeverity,
"@typescript-eslint/no-for-in-array": reactSeverity,
"@typescript-eslint/no-implied-eval": reactSeverity,
"@typescript-eslint/no-import-type-side-effects": reactSeverity,
"@typescript-eslint/no-invalid-void-type": reactSeverity,
"@typescript-eslint/no-misused-promises": reactSeverity,
"@typescript-eslint/no-unnecessary-type-conversion": reactSeverity,
"@typescript-eslint/no-unnecessary-type-assertion": reactSeverity,
"@typescript-eslint/no-useless-default-assignment": reactSeverity,
"@typescript-eslint/no-redeclare": reactSeverity,
"@typescript-eslint/only-throw-error": reactSeverity,
"@typescript-eslint/prefer-includes": reactSeverity,
"@typescript-eslint/prefer-string-starts-ends-with": reactSeverity,
"@typescript-eslint/promise-function-async": [
reactSeverity,
{allowAny: false},
],
"@typescript-eslint/require-array-sort-compare": reactSeverity,
"@typescript-eslint/restrict-plus-operands": reactSeverity,
"@typescript-eslint/restrict-template-expressions": reactSeverity,
"@typescript-eslint/return-await": reactSeverity,
"@typescript-eslint/switch-exhaustiveness-check": reactSeverity,
},
},
// Copyright header — all source files must have the Meta copyright notice
{
files: ["**/*.{ts,tsx}"],
ignores: ["**/*.d.ts", "**/dist/**"],
plugins: {
'@astryx': xdsPlugin,
},
rules: {
'@astryx/copyright-header': 'error',
},
},
// XDS design token enforcement - applies to core package (excluding theme files)
{
files: ["packages/core/src/**/*.{ts,tsx}"],
ignores: ["packages/core/src/theme/**"],
...xdsConfig,
rules: {
...xdsConfig.rules,
// Temporarily allow Children.* in files that need architectural fixes.
// Tracked: OverflowList, MetadataList, Carousel need data-driven APIs.
'@astryx/no-react-introspection': ['error', {
allowFiles: [
'OverflowList/OverflowList',
'MetadataList/MetadataList',
'Carousel/Carousel',
],
}],
},
},
// React bug-prevention rules - applies to core package
// Uses @eslint-react for bugs that TypeScript alone cannot catch.
// Children.*/cloneElement are already covered by @astryx/no-react-introspection.
{
files: ["packages/core/src/**/*.{ts,tsx}"],
plugins: {
...eslintReact.configs.recommended.plugins,
'react-compiler': reactCompiler,
},
rules: {
// React Compiler compatibility
'react-compiler/react-compiler': reactSeverity,
// React fundamentals
'@eslint-react/rules-of-hooks': reactSeverity,
'@eslint-react/purity': reactSeverity,
'@eslint-react/unsupported-syntax': reactSeverity,
'@eslint-react/exhaustive-deps': reactSeverity,
// Component structure bugs
'@eslint-react/no-nested-component-definitions': reactSeverity,
'@eslint-react/no-nested-lazy-component-declarations': reactSeverity,
'@eslint-react/no-unstable-default-props': reactSeverity,
'@eslint-react/no-unstable-context-value': reactSeverity,
'@eslint-react/set-state-in-effect': reactSeverity,
'@eslint-react/set-state-in-render': reactSeverity,
'@eslint-react/no-missing-component-display-name': reactSeverity,
// Hooks
'@eslint-react/use-memo': reactSeverity,
'@eslint-react/no-unnecessary-use-prefix': reactSeverity,
'@eslint-react/no-create-ref': reactSeverity,
'@eslint-react/no-forward-ref': reactSeverity,
'@eslint-react/no-unused-state': reactSeverity,
// DOM correctness
'@eslint-react/dom-no-missing-button-type': reactSeverity,
'@eslint-react/dom-no-missing-iframe-sandbox': reactSeverity,
'@eslint-react/dom-no-void-elements-with-children': reactSeverity,
'@eslint-react/dom-no-dangerously-set-innerhtml': reactSeverity,
'@eslint-react/dom-no-dangerously-set-innerhtml-with-children': reactSeverity,
'@eslint-react/dom-no-find-dom-node': reactSeverity,
'@eslint-react/dom-no-flush-sync': reactSeverity,
'@eslint-react/dom-no-script-url': reactSeverity,
'@eslint-react/dom-no-string-style-prop': reactSeverity,
'@eslint-react/dom-no-unsafe-target-blank': reactSeverity,
'@eslint-react/dom-no-unknown-property': reactSeverity,
// JSX correctness
'@eslint-react/no-missing-key': reactSeverity,
'@eslint-react/no-array-index-key': reactSeverity,
'@eslint-react/jsx-no-comment-textnodes': reactSeverity,
'@eslint-react/jsx-no-leaked-dollar': reactSeverity,
'@eslint-react/jsx-no-children-prop': reactSeverity,
'@eslint-react/jsx-no-children-prop-with-children': reactSeverity,
'@eslint-react/jsx-no-key-after-spread': reactSeverity,
'@eslint-react/jsx-no-leaked-semicolon': reactSeverity,
'@eslint-react/jsx-no-useless-fragment': reactSeverity,
// Naming conventions
'@eslint-react/naming-convention-context-name': reactSeverity,
'@eslint-react/naming-convention-ref-name': reactSeverity,
// React 19 modernization
'@eslint-react/no-context-provider': reactSeverity,
'@eslint-react/no-use-context': reactSeverity,
'@eslint-react/no-missing-context-display-name': reactSeverity,
// Resource leak prevention
'@eslint-react/web-api-no-leaked-event-listener': reactSeverity,
'@eslint-react/web-api-no-leaked-interval': reactSeverity,
'@eslint-react/web-api-no-leaked-timeout': reactSeverity,
'@eslint-react/web-api-no-leaked-resize-observer': reactSeverity,
'@eslint-react/web-api-no-leaked-fetch': reactSeverity,
},
},
// App preview surfaces may embed local pages, but every iframe must be sandboxed.
{
files: ["apps/docsite/**/*.{ts,tsx}", "apps/sandbox/**/*.{ts,tsx}"],
plugins: {
...eslintReact.configs.recommended.plugins,
},
rules: {
'@eslint-react/dom-no-missing-iframe-sandbox': reactSeverity,
},
},
// Browser documentation/demo surfaces should avoid unsafe new-tab links.
{
files: [
"apps/docsite/**/*.{ts,tsx}",
"apps/sandbox/**/*.{ts,tsx}",
"apps/storybook/**/*.{ts,tsx}",
],
plugins: {
...eslintReact.configs.recommended.plugins,
},
rules: {
'@eslint-react/dom-no-unsafe-target-blank': reactSeverity,
},
},
// Test files — relax rules for test ergonomics (must be after React rules
// block so it overrides react-compiler/react-compiler)
{
files: ["**/*.test.{ts,tsx}", "**/*.perf.test.{ts,tsx}"],
rules: {
"no-console": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/consistent-type-assertions": "off",
"react-compiler/react-compiler": "off",
},
},
// Non-production code — allow console.log for demos, tools, and examples
{
files: [
"apps/storybook/stories/**/*.{ts,tsx}",
"apps/docsite/src/generated/**/*.{ts,tsx}",
"apps/sandbox/**/*.{ts,tsx}",
"apps/example-*/**/*.{ts,tsx}",
"internal/**/*.{ts,tsx}",
"packages/cli/templates/**/*.{ts,tsx}",
],
rules: {
"no-console": "off",
},
},
// CLI runtime (.mjs). The CLI ships as ESM Node modules and was never linted
// (the global **/*.mjs ignore swallowed it; see #2468). This block gives the
// .mjs sources a Node language environment and enforces the JSON-stdout
// contract (#2467) at author time via @astryx/no-raw-console-cli.
{
files: ["packages/cli/src/**/*.mjs", "packages/cli/bin/**/*.mjs"],
plugins: {
'@astryx': xdsPlugin,
},
languageOptions: {
sourceType: "module",
globals: {
// Node globals (no `globals` package dependency in this repo).
process: "readonly",
console: "readonly",
Buffer: "readonly",
URL: "readonly",
URLSearchParams: "readonly",
TextEncoder: "readonly",
TextDecoder: "readonly",
setTimeout: "readonly",
clearTimeout: "readonly",
setInterval: "readonly",
clearInterval: "readonly",
setImmediate: "readonly",
clearImmediate: "readonly",
queueMicrotask: "readonly",
__dirname: "readonly",
__filename: "readonly",
global: "readonly",
globalThis: "readonly",
structuredClone: "readonly",
fetch: "readonly",
AbortController: "readonly",
},
},
rules: {
"@typescript-eslint/no-unused-vars": ["error", {
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
}],
// Bare console.log corrupts --json stdout. Route human chatter through
// humanLog(); console.error/console.warn (stderr) stay allowed.
"@astryx/no-raw-console-cli": "error",
},
},
// Copyright header for CLI .mjs sources (the main copyright block only
// covers .ts/.tsx).
{
files: ["packages/cli/src/**/*.mjs", "packages/cli/bin/**/*.mjs"],
plugins: {
'@astryx': xdsPlugin,
},
rules: {
'@astryx/copyright-header': 'error',
},
},
// CLI tests — relax author-ergonomics rules (test files emit freely and may
// keep intentionally-unused fixtures). Must come after the CLI block above.
{
files: ["packages/cli/**/*.test.mjs"],
rules: {
"@astryx/no-raw-console-cli": "off",
"@typescript-eslint/no-unused-vars": "off",
},
},
);