@kirill.konshin/lint 0.1.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/index.js ADDED
@@ -0,0 +1,657 @@
1
+ /*
2
+ * Raw ESM JS on purpose (no TS build): loaded by `eslint.config.mjs` and pre-commit `lint:staged`
3
+ * before anything is built, so a `dist/` main would need building before it could lint. See
4
+ * README ("Why raw JS").
5
+ *
6
+ * jest/vitest plugins stay statically imported even though their recommended sets are gated below:
7
+ * the runner-agnostic 'Test rules' block registers both plugins unconditionally (its rules are pure
8
+ * AST checks that work without the runner installed).
9
+ *
10
+ * Plugins used only behind capability gates (and for the re-exports at the bottom) are imported
11
+ * lazily so consumers without the tool don't pay their load cost — @nx/eslint-plugin in particular
12
+ * drags in a large part of nx itself. Like storybookConfig below, the re-exported bindings are null
13
+ * when the underlying tool isn't installed.
14
+ *
15
+ * Gate each test-runner's recommended rule set on the runner actually being installed - per
16
+ * packages/lint/rules/testing.md ("if project use vite use vitest, otherwise jest"), a project
17
+ * normally has exactly one of these, and applying the other runner's correctness rules to it would
18
+ * be conceptually wrong (even if mechanically harmless, since the rule namespaces don't collide).
19
+ */
20
+ import { existsSync } from 'node:fs';
21
+ import { dirname, resolve } from 'node:path';
22
+ import { fileURLToPath } from 'node:url';
23
+ import { includeIgnoreFile as includeIgnoreFileCompat } from '@eslint/compat';
24
+ import js from '@eslint/js';
25
+ import vitestPlugin from '@vitest/eslint-plugin';
26
+ import nextTs from 'eslint-config-next/typescript';
27
+ import prettierFlat from 'eslint-config-prettier/flat';
28
+ import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript';
29
+ import importXPlugin, { createNodeResolver } from 'eslint-plugin-import-x';
30
+ import jestPlugin from 'eslint-plugin-jest';
31
+ import jsxA11yPlugin from 'eslint-plugin-jsx-a11y';
32
+ import promisePlugin from 'eslint-plugin-promise';
33
+ import reactPlugin from 'eslint-plugin-react';
34
+ import reactHooksPlugin from 'eslint-plugin-react-hooks';
35
+ import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort';
36
+ import unicornPlugin from 'eslint-plugin-unicorn';
37
+ import unusedImportsPlugin from 'eslint-plugin-unused-imports';
38
+ import globals from 'globals';
39
+ import jsoncParser from 'jsonc-eslint-parser';
40
+
41
+ import { testColocation } from './ruleTestColocation.js';
42
+
43
+ export const tsExtsRaw = 'js,jsx,ts,tsx,cjs,cts,mjs,mts'; // TODO mdx, needs loader
44
+ export const eslintExtsRaw = `${tsExtsRaw},md,mdx,htm,html,vue`;
45
+ export const prettierExtsRaw = 'css,scss,sass,less,yml,yaml,json,json5,jsonc,graphql,graphqls,xml';
46
+
47
+ export const tsExts = `{${tsExtsRaw}}`;
48
+ export const eslintExts = `*.{${eslintExtsRaw}}`;
49
+ export const prettierExts = `*.{${prettierExtsRaw}}`;
50
+
51
+ function isPackageResolvable(specifier) {
52
+ try {
53
+ import.meta.resolve(specifier);
54
+ return true;
55
+ } catch {
56
+ return false;
57
+ }
58
+ }
59
+
60
+ const hasNext = isPackageResolvable('next/package.json');
61
+ const nextPlugin = hasNext ? (await import('@next/eslint-plugin-next')).default : null;
62
+ const hasStorybook = isPackageResolvable('storybook/package.json');
63
+ const hasVite = isPackageResolvable('vite/package.json');
64
+ const hasJest = isPackageResolvable('jest/package.json');
65
+ const hasVitest = isPackageResolvable('vitest/package.json');
66
+
67
+ const ENABLE_TYPE_AWARE_RULES = false;
68
+
69
+ /*
70
+ * `eslint-plugin-storybook` is a dependency of this package (like `@next/eslint-plugin-next` is for
71
+ * Next), but its own code statically imports the `storybook` package itself, which most consumers won't
72
+ * have installed - it's an optional peer here, same as `next` the framework is for `@next/eslint-plugin-next`.
73
+ * Resolve it lazily so loading this module doesn't crash for non-Storybook consumers; `storybookConfig`
74
+ * is exported as `null` if it couldn't be resolved, mirroring how `nextPlugin` is always importable but
75
+ * only useful where the underlying tool is actually installed.
76
+ */
77
+ let storybookConfig = null;
78
+ try {
79
+ const storybook = await import('eslint-plugin-storybook');
80
+ storybookConfig = storybook.default.configs['flat/recommended'];
81
+ } catch {
82
+ // `storybook` isn't installed in this project - `storybookConfig` stays null.
83
+ }
84
+
85
+ /*
86
+ * `eslint-config-next`'s own parser module does `require('next/dist/compiled/babel/eslint-parser')` -
87
+ * a file INSIDE the `next` package itself - so merely *importing* `eslint-config-next` crashes if
88
+ * `next` isn't installed at all, regardless of any later conditional logic (verified empirically: it
89
+ * throws "Cannot find module 'next/dist/compiled/babel/eslint-parser'" the instant the module loads).
90
+ * Mirror the eslint-plugin-storybook pattern above: only import it when `next` is actually there.
91
+ */
92
+ let nextConfig = [];
93
+ if (hasNext) {
94
+ try {
95
+ const next = await import('eslint-config-next');
96
+ nextConfig = next.default;
97
+ } catch {
98
+ // shouldn't happen given hasNext already confirmed `next/package.json` resolves, but stay safe
99
+ }
100
+ }
101
+
102
+ /*
103
+ * Non-Next React projects - this config is also used for Vite+React apps - still want React/React
104
+ * Hooks/jsx-a11y linting, which `eslint-config-next` normally provides but only via the Next-specific
105
+ * parser above. Cover the same ground directly instead, with whatever parser is already active
106
+ * (typescript-eslint for .ts/.tsx via `nextTs` below, the default parser otherwise).
107
+ */
108
+ const reactFallbackConfig = hasNext
109
+ ? []
110
+ : [
111
+ reactPlugin.configs.flat.recommended,
112
+ reactPlugin.configs.flat['jsx-runtime'],
113
+ reactHooksPlugin.configs.flat['recommended-latest'],
114
+ jsxA11yPlugin.flatConfigs.recommended,
115
+ ];
116
+
117
+ /*
118
+ * Gate the Turbo rule set on the tool actually being installed, same as jest/vitest above. A bare cwd
119
+ * config-file check would make lint results depend on the invocation directory (IDE integrations and
120
+ * per-package runs launch eslint from subdirectories). Without the turbo gate,
121
+ * `turbo/no-undeclared-env-vars` treats "no turbo.json" as "nothing declared" and flags every single
122
+ * env var access - useless noise for consumers that use NX (or nothing) instead. `eslint-plugin-turbo`
123
+ * is bundled but does not drag in `turbo` itself, so this resolvability check stays honest.
124
+ */
125
+ const hasTurbo = isPackageResolvable('turbo/package.json');
126
+
127
+ /*
128
+ * NX cannot use the same resolvability gate: `nx` core is always resolvable here as a transitive dep of
129
+ * the bundled @nx/eslint-plugin (-> @nx/devkit -> nx), so `isPackageResolvable('nx')` reports true in
130
+ * every consumer - including plain non-Nx projects, where it wrongly switches on @nx/dependency-checks,
131
+ * which then fails with no project graph. Detect an actual Nx workspace by walking up from cwd to an
132
+ * `nx.json` instead: unlike a bare cwd check this is stable across subdirectory / per-package / IDE runs
133
+ * (they resolve to the same workspace root) and correctly stays off outside an Nx workspace.
134
+ */
135
+ function hasWorkspaceFile(fileName) {
136
+ let dir = process.cwd();
137
+ for (;;) {
138
+ if (existsSync(resolve(dir, fileName))) return true;
139
+ const parent = dirname(dir);
140
+ if (parent === dir) return false;
141
+ dir = parent;
142
+ }
143
+ }
144
+
145
+ const hasNx = hasWorkspaceFile('nx.json');
146
+
147
+ // lazy for the same reason as nextPlugin above
148
+ const turboPlugin = hasTurbo ? (await import('eslint-plugin-turbo')).default : null;
149
+ const nxPlugin = hasNx ? (await import('@nx/eslint-plugin')).default : null;
150
+
151
+ const index = [
152
+ js.configs.recommended,
153
+
154
+ /*
155
+ * `eslint-config-next` already ignores `next-env.d.ts`, but only as a bare pattern ('next-env.d.ts'),
156
+ * which only matches at the config's own root - not when the Next app (and its generated
157
+ * next-env.d.ts) lives in a subdirectory, like demo/web-static/ here. It's auto-generated and
158
+ * explicitly marked "should not be edited", so exclude it recursively instead of just working
159
+ * around individual rules (its `///` reference directives otherwise trip multiline-comment-style,
160
+ * which would corrupt them if autofixed into a `/* *\/` block).
161
+ */
162
+ {
163
+ ignores: [
164
+ //TODO coverage, dist, out, build?
165
+ '**/next-env.d.ts',
166
+ '**/viteEnv.d.ts',
167
+ '**/node_modules',
168
+ '**/.cache',
169
+ '**/.nx',
170
+ '**/.turbo',
171
+ '**/.yarn',
172
+ ],
173
+ },
174
+
175
+ ...nextConfig,
176
+ ...nextTs,
177
+ ...reactFallbackConfig,
178
+
179
+ /*
180
+ * @see https://github.com/prettier/eslint-plugin-prettier?tab=readme-ov-file#arrow-body-style-and-prefer-arrow-callback-issue
181
+ * Plugin is not recommended by Prettier, they suggest to just use config, and disable all the rules, except for
182
+ * these two in plugin last since they disable some previously set rules:
183
+ * import prettierConfigRecommended from 'eslint-plugin-prettier/recommended';
184
+ * 'arrow-body-style': 'off'
185
+ * 'prefer-arrow-callback': 'off',
186
+ *
187
+ * @see https://nextjs.org/docs/app/api-reference/config/eslint#with-prettier
188
+ * Note the `/flat` suffix here, the difference from default entry is that `/flat` added `name` property to the
189
+ * exported object to improve https://eslint.org/blog/2024/04/eslint-config-inspector/ experience.
190
+ */
191
+ prettierFlat,
192
+
193
+ ...(storybookConfig ?? []),
194
+
195
+ /*
196
+ * eslint-config-next already registers `eslint-plugin-import` under the 'import' key, and ESLint 10
197
+ * hard-errors ("Cannot redefine plugin") if a later config tries to reuse that same key with a
198
+ * different plugin instance. eslint-plugin-import-x is a drop-in replacement, registered under its
199
+ * own 'import-x' key instead (its own recommended config does this registration for us).
200
+ */
201
+ importXPlugin.configs['flat/recommended'],
202
+
203
+ promisePlugin.configs['flat/recommended'],
204
+
205
+ {
206
+ name: 'eslint-plugin-import-x overrides',
207
+ settings: {
208
+ /*
209
+ * `createTypeScriptImportResolver` correctly resolves relative imports and simple TS path
210
+ * aliases, but NOT cross-workspace-package imports in this monorepo (e.g. `@kirill.konshin/node`)
211
+ * or subpath exports (e.g. `next/constants`) - verified empirically. That's why the
212
+ * resolution-dependent rules below are turned off rather than left on the recommended default.
213
+ */
214
+ 'import-x/resolver-next': [createTypeScriptImportResolver(), createNodeResolver()],
215
+ },
216
+ rules: {
217
+ /*
218
+ * Off because of the workspace/subpath resolution gaps above - re-enable per-project once
219
+ * resolution is confirmed reliable there (e.g. a single-app, non-monorepo consumer).
220
+ */
221
+ 'import-x/no-unresolved': 'off',
222
+ 'import-x/named': 'off',
223
+ 'import-x/namespace': 'off',
224
+ 'import-x/default': 'off',
225
+ 'import-x/export': 'off',
226
+ /*
227
+ * Same resolution caveat, and also the two most expensive rules in the recommended set
228
+ * (they parse every imported module looking for its named exports).
229
+ */
230
+ 'import-x/no-named-as-default': 'off',
231
+ 'import-x/no-named-as-default-member': 'off',
232
+ 'import-x/no-default-export': 'warn', // see 'Storybook overrides' below
233
+ },
234
+ },
235
+
236
+ {
237
+ name: 'eslint-plugin-simple-import-sort',
238
+ files: [`**/*.${tsExts}`],
239
+ plugins: { 'simple-import-sort': simpleImportSortPlugin },
240
+ rules: {
241
+ /*
242
+ * Side-effect imports (polyfills, CSS) ARE sorted into their group; the sorter only
243
+ * preserves the relative order of multiple side-effect imports that land in the SAME
244
+ * group (so order-dependent side effects stay put). Non-import code between imports
245
+ * splits them into independently-sorted chunks (standard simple-import-sort behavior).
246
+ */
247
+ 'simple-import-sort/imports': [
248
+ 'error',
249
+ {
250
+ groups: [
251
+ // 1. Polyfills - side-effect imports that must run first
252
+ ['^\\u0000.*(polyfill|core-js|regenerator-runtime|whatwg-fetch|@vitest/web-worker)'],
253
+ // 2. React
254
+ ['^react(-dom)?(/|$)'],
255
+ // 3. Third-party packages (node: builtins + npm packages)
256
+ ['^node:', '^@?\\w'],
257
+ // 4. Local imports - path aliases then relative
258
+ ['^@/', '^\\.'],
259
+ // 5. CSS/styles from libraries (side-effect, package path)
260
+ ['^\\u0000@?\\w'],
261
+ // 6. Local CSS/styles (side-effect, relative path)
262
+ ['^\\u0000'],
263
+ ],
264
+ },
265
+ ],
266
+ },
267
+ },
268
+
269
+ {
270
+ name: 'Globals',
271
+ languageOptions: {
272
+ globals: {
273
+ ...globals.browser,
274
+ ...globals.node,
275
+ },
276
+ },
277
+ },
278
+
279
+ {
280
+ name: 'ESLint overrides',
281
+ rules: {
282
+ 'no-restricted-imports': [
283
+ 'error',
284
+ {
285
+ paths: [
286
+ {
287
+ name: 'next/router',
288
+ message: 'Please use next/navigation instead of next/router',
289
+ },
290
+ ],
291
+ },
292
+ ],
293
+ // 'multiline-comment-style': ['warn', 'starred-block'],
294
+ 'multiline-comment-style': 'off',
295
+ },
296
+ },
297
+
298
+ {
299
+ name: 'eslint-config-next overrides',
300
+ rules: {
301
+ '@next/next/no-html-link-for-pages': 'off',
302
+ '@next/next/no-img-element': 'off',
303
+ 'import/no-anonymous-default-export': 'off', // overrides eslint-config-next's own default
304
+ 'jsx-a11y/alt-text': 'off',
305
+ 'react/prop-types': 'off', // ts does it statically
306
+ },
307
+ },
308
+
309
+ {
310
+ name: '@typescript-eslint overrides',
311
+ files: [`**/*.${tsExts}`],
312
+ rules: {
313
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
314
+ '@typescript-eslint/no-empty-function': 'off',
315
+ '@typescript-eslint/no-explicit-any': 'off',
316
+ '@typescript-eslint/no-require-imports': 'off',
317
+ '@typescript-eslint/no-unused-vars': 'off', // superseded by 'unused-imports/no-unused-imports' below, which is actually autofixable
318
+ '@typescript-eslint/consistent-type-definitions': ['error', 'type'],
319
+ '@typescript-eslint/consistent-type-imports': [
320
+ 'error',
321
+ { prefer: 'type-imports', fixStyle: 'inline-type-imports' },
322
+ ],
323
+ '@typescript-eslint/ban-ts-comment': [
324
+ 'error',
325
+ {
326
+ 'ts-expect-error': 'allow-with-description',
327
+ 'ts-ignore': true,
328
+ 'ts-nocheck': true,
329
+ 'ts-check': false,
330
+ minimumDescriptionLength: 3,
331
+ },
332
+ ],
333
+ /*
334
+ * `as const` is the mechanical half of "Prefer `as const` and `readonly` for immutable
335
+ * constants and objects" - the `readonly` half is a per-case judgment call (which objects
336
+ * deserve it), so that guidance stays in typescript.md instead of being lint-enforced here.
337
+ */
338
+ '@typescript-eslint/prefer-as-const': 'error',
339
+ },
340
+ },
341
+
342
+ {
343
+ name: 'eslint-plugin-unused-imports',
344
+ plugins: { 'unused-imports': unusedImportsPlugin },
345
+ rules: {
346
+ /*
347
+ * Unlike `@typescript-eslint/no-unused-vars/core` `no-unused-vars`, this rule is
348
+ * autofixable - `--fix` deletes the unused import specifier (or the whole import
349
+ * statement if nothing from it is used) instead of just reporting it.
350
+ */
351
+ 'unused-imports/no-unused-imports': 'error',
352
+ },
353
+ },
354
+
355
+ {
356
+ name: 'Unicorn rules',
357
+ /*
358
+ * Deliberately NOT using unicorn.configs['flat/recommended'] - it's 337 rules (it even folds in
359
+ * a few unprefixed core-ESLint rules), extremely opinionated, and far beyond what was asked for.
360
+ * Only the two rules below are actually wanted.
361
+ */
362
+ files: [`**/*.${tsExts}`],
363
+ plugins: { unicorn: unicornPlugin },
364
+ rules: {
365
+ 'unicorn/filename-case': [
366
+ 'error',
367
+ {
368
+ case: 'camelCase',
369
+ /*
370
+ * code-style.md only mandates FILE names; this repo's own kebab-case package
371
+ * directories (e.g. electron-builder, react-native) are an established convention.
372
+ */
373
+ checkDirectories: false,
374
+ // Next.js App Router mandates these exact hyphenated filenames - not a naming choice.
375
+ ignore: [
376
+ /^not-found\.[jt]sx?$/,
377
+ /^global-error\.[jt]sx?$/,
378
+ /^opengraph-image\.[jt]sx?$/,
379
+ /^twitter-image\.[jt]sx?$/,
380
+ /^apple-icon\.[jt]sx?$/,
381
+ /^next-env\.d\.ts$/,
382
+ /^electron-builder\..+$/,
383
+ ],
384
+ },
385
+ ],
386
+ 'unicorn/prefer-node-protocol': 'error',
387
+ },
388
+ },
389
+
390
+ {
391
+ name: 'eslint-plugin-promise overrides',
392
+ rules: {
393
+ 'promise/prefer-await-to-then': 'warn',
394
+ 'promise/param-names': 'off',
395
+ 'promise/always-return': 'off',
396
+ 'promise/catch-or-return': 'off',
397
+ },
398
+ },
399
+
400
+ //FIXME Does not perform, turned off
401
+ ENABLE_TYPE_AWARE_RULES
402
+ ? {
403
+ name: 'Type-aware rules (separate for performance)',
404
+ files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts', '**/*.mdx'],
405
+ languageOptions: {
406
+ parserOptions: {
407
+ projectService: {
408
+ /*
409
+ * Config files like vite.config.ts and .storybook/{main,preview}.ts sit at the
410
+ * package root or in a dotfolder, outside its own tsconfig.json `include: ["src"]`
411
+ * - projectService has no tsconfig to attach them to otherwise. allowDefaultProject
412
+ * falls back to a synthetic single-file program for these instead of erroring.
413
+ * `**` isn't allowed here, so root-level, one-level-nested, and this monorepo's own
414
+ * packages/* layout are each spelled out explicitly.
415
+ */
416
+ allowDefaultProject: [
417
+ //FIXME NOT PROJECT AGNOSTIC
418
+ 'vite.config.ts',
419
+ '*/vite.config.ts',
420
+ 'packages/*/vite.config.ts',
421
+ '.storybook/main.ts',
422
+ '*/.storybook/main.ts',
423
+ 'packages/*/.storybook/main.ts',
424
+ '.storybook/preview.ts',
425
+ '*/.storybook/preview.ts',
426
+ 'packages/*/.storybook/preview.ts',
427
+ ],
428
+ // Default cap is 8; this monorepo alone has 14 vite.config.ts + 10 .storybook/*.ts files.
429
+ maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING: 50,
430
+ },
431
+ tsconfigRootDir: process.cwd(),
432
+ },
433
+ },
434
+ rules: {
435
+ '@typescript-eslint/prefer-optional-chain': 'warn',
436
+ '@typescript-eslint/prefer-nullish-coalescing': 'warn',
437
+
438
+ /**
439
+ * https://typescript-eslint.io/rules/naming-convention/
440
+ *
441
+ * Naming Conventions. Lives here (not 'Custom
442
+ * rules') because the `types: ['boolean']` filter below needs type info too, even
443
+ * though naming-convention as a whole isn't in the typed-linting rule set.
444
+ */
445
+ '@typescript-eslint/naming-convention': [
446
+ 'warn',
447
+ { selector: 'default', format: null },
448
+ /*
449
+ * PascalCase allowed too: this codebase's actual
450
+ * convention is `const Cmp: FC<Props> = memo(...)` - components are PascalCase
451
+ * variables, not just PascalCase function declarations.
452
+ */
453
+ {
454
+ selector: 'variable',
455
+ format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
456
+ leadingUnderscore: 'forbid',
457
+ },
458
+ {
459
+ selector: 'variable',
460
+ types: ['boolean'],
461
+ /*
462
+ * The part AFTER the prefix is naturally capitalized (isLoading, hasError, ...),
463
+ * so it's validated as PascalCase, not camelCase - format here is for the suffix,
464
+ * not the identifier as a whole.
465
+ */
466
+ format: ['PascalCase'],
467
+ prefix: ['is', 'has', 'had', 'can', 'should', 'will', 'did'],
468
+ },
469
+ /*
470
+ * Established exceptions to the boolean-prefix rule above - conventional enough on
471
+ * their own (React's own `loading`/`done` state names, DOM/library `enabled` flags)
472
+ * that requiring is/has/can/should here would just be noise.
473
+ */
474
+ {
475
+ selector: 'variable',
476
+ types: ['boolean'],
477
+ filter: { regex: '^(done|loading|enabled)$', match: true },
478
+ format: ['camelCase'],
479
+ },
480
+ { selector: 'function', format: ['camelCase', 'PascalCase'] },
481
+ { selector: 'class', format: ['PascalCase'] },
482
+ ],
483
+ },
484
+ }
485
+ : null,
486
+
487
+ {
488
+ name: 'Default export overrides',
489
+ files: [
490
+ '**/*.config.*',
491
+ `**/*.stories.${tsExts}`,
492
+ `**/.storybook/main.${tsExts}`,
493
+ `**/.storybook/preview.${tsExts}`,
494
+ '**/.lintstagedrc*',
495
+ '**/.prettierrc*',
496
+ `**/App.${tsExts}`,
497
+ `**/index.${tsExts}`,
498
+ `**/layout.${tsExts}`,
499
+ `**/loading.${tsExts}`,
500
+ `**/main.${tsExts}`,
501
+ `**/page.${tsExts}`,
502
+ ],
503
+ rules: {
504
+ /*
505
+ * Stories always default-export `meta`, and story exports (`Default`, `WithArgs`, ...) are PascalCase by
506
+ * Storybook's own convention, which the general rules above disallow.
507
+ */
508
+ 'import-x/no-default-export': 'off',
509
+ '@typescript-eslint/naming-convention': 'off',
510
+ },
511
+ },
512
+
513
+ ...(hasTurbo
514
+ ? [
515
+ turboPlugin.configs['flat/recommended'],
516
+ {
517
+ name: 'eslint-plugin-turbo overrides',
518
+ rules: {
519
+ /*
520
+ * Only covers undeclared env vars, not the full dependsOn/outputs consistency - that part has no
521
+ * ESLint-shaped check. Downgraded from their default 'error' to 'warn'.
522
+ */
523
+ 'turbo/no-undeclared-env-vars': 'warn',
524
+ },
525
+ },
526
+ ]
527
+ : []),
528
+
529
+ ...(hasNx
530
+ ? [
531
+ /*
532
+ * Only `flat/base` (registers the '@nx' plugin, no rules of its own).
533
+ *
534
+ * `flat/typescript`/ `flat/javascript` were deliberately NOT used - same call as with eslint-plugin-unicorn's
535
+ * recommended: they bundle the ENTIRE @stylistic plugin (hundreds of formatting rules - indent, quotes,
536
+ * semi, comma-dangle, ...) which would directly fight Prettier, plus a second full copy of
537
+ * @typescript-eslint/recommended that would relitigate rules already configured deliberately above.
538
+ */
539
+ ...nxPlugin.configs['flat/base'],
540
+ {
541
+ name: '@nx/dependency-checks',
542
+ files: ['**/package.json'],
543
+ languageOptions: {
544
+ parser: jsoncParser,
545
+ },
546
+ rules: {
547
+ // https://nx.dev/docs/technologies/eslint/eslint-plugin/guides/dependency-checks
548
+ '@nx/dependency-checks': 'error',
549
+ },
550
+ },
551
+ ]
552
+ : []),
553
+
554
+ ...(hasJest
555
+ ? [
556
+ {
557
+ ...jestPlugin.configs['flat/recommended'],
558
+ name: 'Jest Rules',
559
+ files: [`**/*.{test,spec}.${tsExts}`],
560
+ },
561
+ ]
562
+ : []),
563
+
564
+ ...(hasVitest
565
+ ? [
566
+ {
567
+ ...vitestPlugin.configs.recommended,
568
+ name: 'Vitest Rules',
569
+ files: [`**/*.{test,spec}.${tsExts}`],
570
+ },
571
+ {
572
+ ...vitestPlugin.configs.env,
573
+ name: 'Vitest globals',
574
+ files: [`**/*.{test,spec}.${tsExts}`],
575
+ },
576
+ ]
577
+ : []),
578
+
579
+ {
580
+ /*
581
+ * Runner-agnostic: this rule is pure AST/call-name checking, needs neither jest nor vitest
582
+ * installed to work correctly, so it applies regardless of which one (if either) is present.
583
+ */
584
+ name: 'Test rules',
585
+ files: [`**/*.{test,spec}.${tsExts}`],
586
+ plugins: {
587
+ jest: jestPlugin,
588
+ vitest: vitestPlugin,
589
+ local: { rules: { 'test-colocation': testColocation } },
590
+ },
591
+ rules: {
592
+ 'jest/consistent-test-it': ['error', { fn: 'test' }],
593
+ 'vitest/consistent-test-it': ['error', { fn: 'test' }],
594
+ 'local/test-colocation': 'error',
595
+ 'jest/no-disabled-tests': 'warn',
596
+ 'vitest/no-disabled-tests': 'warn',
597
+ },
598
+ },
599
+
600
+ /*
601
+ * FIXME ESLint 10 + Next fix
602
+ * https://github.com/vercel/next.js/issues/89764
603
+ * https://gist.github.com/OscarGauss/1f305edf5b7c103bb2ee32ba479f4261
604
+ */
605
+ {
606
+ settings: {
607
+ react: { version: '19' },
608
+ },
609
+ },
610
+ ].filter(Boolean);
611
+
612
+ export default index;
613
+
614
+ export { nextPlugin, nxPlugin, turboPlugin, jestPlugin, vitestPlugin, storybookConfig };
615
+
616
+ /**
617
+ * @param {string} importMetaUrl
618
+ * @param {string} ignoreFile
619
+ * @returns {import('@eslint/core').ConfigObject}
620
+ */
621
+ export function includeIgnoreFile(importMetaUrl, ignoreFile) {
622
+ // @see https://blog.linotte.dev/eslint-9-next-js-935c2b6d0371
623
+ return includeIgnoreFileCompat(resolve(dirname(fileURLToPath(importMetaUrl)), ignoreFile));
624
+ }
625
+
626
+ export const prettier = {
627
+ printWidth: 120,
628
+ tabWidth: 2,
629
+ singleQuote: true,
630
+ overrides: [
631
+ {
632
+ files: eslintExts,
633
+ options: {
634
+ tabWidth: 4,
635
+ },
636
+ },
637
+ ],
638
+ };
639
+
640
+ /**
641
+ * https://nextjs.org/docs/app/api-reference/config/eslint#running-lint-on-staged-files
642
+ *
643
+ * Pay extra attention when the configured globs overlap, and tasks make edits to files. Prettier and eslint might try
644
+ * to make changes to the same *.ts file at the same time, causing a race condition.
645
+ *
646
+ * https://github.com/lint-staged/lint-staged?tab=readme-ov-file#reformatting-the-code
647
+ * https://github.com/lint-staged/lint-staged/issues/775
648
+ * You don't need git add since lint-staged 10
649
+ *
650
+ * TODO Screw yarn, just use eslint directly? Yarn gives greater control over what is in the console...
651
+ *
652
+ * @returns {import('lint-staged').Configuration}
653
+ */
654
+ export const listStaged = {
655
+ [prettierExts]: ['yarn prettier'],
656
+ [eslintExts]: ['yarn eslint', 'yarn prettier'],
657
+ };