@kirill.konshin/lint 0.2.0 → 0.3.1

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.
@@ -0,0 +1,262 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
3
+ import nextTs from 'eslint-config-next/typescript';
4
+ import jsxA11yPlugin from 'eslint-plugin-jsx-a11y';
5
+ import reactPlugin from 'eslint-plugin-react';
6
+ import reactHooksPlugin from 'eslint-plugin-react-hooks';
7
+ import { globSync } from 'glob';
8
+
9
+ import { findWorkspaceRoot, GLOBAL_IGNORES, hasNext, scanWorkspace, toolGate, tsExts } from '../lib.js';
10
+
11
+ // lazy so consumers without Next don't pay the load cost - re-exported from index.js
12
+ export const nextPlugin = hasNext ? (await import('@next/eslint-plugin-next')).default : null;
13
+
14
+ /** @typedef {import('../index.js').NextOptions} NextOptions Defined in index.d.ts. */
15
+
16
+ /**
17
+ * Does this `package.json` declare `next` as a dependency? Peer/optional declarations are
18
+ * deliberately ignored - they mark component libraries, not apps.
19
+ *
20
+ * @param {string} file absolute path of a `package.json`
21
+ * @returns {boolean}
22
+ */
23
+ function dependsOnNext(file) {
24
+ try {
25
+ const { dependencies, devDependencies } = JSON.parse(readFileSync(file, 'utf-8'));
26
+ return Boolean(dependencies?.next ?? devDependencies?.next);
27
+ } catch {
28
+ return false; // unreadable / malformed - not evidence
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Auto-find Next.js app roots below the workspace root (scanned like the Tailwind entry - see
34
+ * `scanWorkspace`). `next.config.*` is optional in Next.js, so any of three signals marks an app
35
+ * root:
36
+ * - a `next.config.*` file
37
+ * - a `package.json` depending on `next` (see {@link dependsOnNext})
38
+ * - a `src/app` or `src/pages` directory - the reported root is the directory CONTAINING `src`,
39
+ * because the plugin resolves both layouts (`pages`/`app` and `src/pages`/`src/app`) from the
40
+ * package root itself; the bare root-level dir names are too generic to scan for, but such apps
41
+ * are caught by the other two signals
42
+ *
43
+ * @param {string[]} ignores glob patterns to skip
44
+ * @returns {string[]} absolute directories, deduplicated (one app usually shows several signals) and
45
+ * sorted so the emitted settings block is deterministic across filesystems
46
+ */
47
+ export function findNextRoots(ignores) {
48
+ return [
49
+ ...new Set([
50
+ ...scanWorkspace('next.config.*', ignores).map((file) => dirname(file)),
51
+ ...scanWorkspace('package.json', ignores)
52
+ .filter(dependsOnNext)
53
+ .map((file) => dirname(file)),
54
+ // the trailing slash makes glob match directories only
55
+ ...scanWorkspace('src/{app,pages}/', ignores).map((dir) => dirname(dirname(dir))),
56
+ ]),
57
+ ].sort();
58
+ }
59
+
60
+ /**
61
+ * Next.js blocks: the whole `eslint-config-next` flat config, plus `settings.next.rootDir`.
62
+ *
63
+ * `rootDir` is auto-detected via {@link findNextRoots} when omitted: zero apps found → no settings
64
+ * block (the setting is optional and the plugin works without it - NOT an error, unlike the
65
+ * Tailwind entry); one or several → ALL of them (`settings.next.rootDir` accepts an array -
66
+ * pointing at just one app would break linting of the others).
67
+ *
68
+ * `eslint-config-next`'s own parser module does `require('next/dist/compiled/babel/eslint-parser')` -
69
+ * a file INSIDE the `next` package itself - so merely *importing* `eslint-config-next` crashes if
70
+ * `next` isn't installed at all (verified empirically: it throws "Cannot find module
71
+ * 'next/dist/compiled/babel/eslint-parser'" the instant the module loads). Hence the lazy import
72
+ * here; when the block is forced on without `next` around, that error IS the failure mode.
73
+ *
74
+ * @param {NextOptions} [options]
75
+ * @returns {Promise<import('eslint').Linter.Config[]>}
76
+ */
77
+ export async function nextBaseConfig({ rootDir = findNextRoots(GLOBAL_IGNORES) } = {}) {
78
+ const next = (await import('eslint-config-next')).default;
79
+ return [
80
+ ...next,
81
+ // eslint-config-next already registers the @next/next plugin, only the settings are needed
82
+ ...(rootDir?.length ? [{ name: '@next/eslint-plugin-next settings', settings: { next: { rootDir } } }] : []),
83
+ ];
84
+ }
85
+
86
+ /**
87
+ * Non-Next React projects - this config is also used for Vite+React apps - still want React/React
88
+ * Hooks/jsx-a11y linting, which `eslint-config-next` normally provides but only via the Next-specific
89
+ * parser. Cover the same ground directly instead, with whatever parser is already active
90
+ * (typescript-eslint for .ts/.tsx via typescriptConfig, the default parser otherwise).
91
+ *
92
+ * @returns {import('eslint').Linter.Config[]}
93
+ */
94
+ export function reactBaseConfig() {
95
+ return [
96
+ reactPlugin.configs.flat.recommended,
97
+ reactPlugin.configs.flat['jsx-runtime'],
98
+ reactHooksPlugin.configs.flat['recommended-latest'],
99
+ jsxA11yPlugin.flatConfigs.recommended,
100
+ ];
101
+ }
102
+
103
+ /**
104
+ * Composite: {@link nextBaseConfig} when Next is enabled, the {@link reactBaseConfig} fallback
105
+ * otherwise. Full evidence-based gate (see `toolGate` in lib.js), mirroring Tailwind: app-root
106
+ * evidence (see {@link findNextRoots} - `next.config.*`, a `package.json` depending on `next`, a
107
+ * `src/app`/`src/pages` tree) marks a Next repo even when the `next` package is installed only in
108
+ * a leaf app (invisible to `hasNext`) - and because `eslint-config-next` `require`s files INSIDE
109
+ * the `next` package, leaf-only installs are bridged from each app's own `package.json` (see
110
+ * `ensurePackageResolvable` in lib.js for the mechanism and PnP behavior).
111
+ *
112
+ * @param {boolean | NextOptions} [option] the defineLintConfig `next` flag
113
+ * @param {boolean} [strict] same-scope detection only - no `next.config.*` scan, no bridge (defineLintConfig `detection.strict`)
114
+ * @returns {Promise<import('eslint').Linter.Config[]>}
115
+ */
116
+ export async function nextConfig(option, strict = false) {
117
+ const { enabled, options, files } = toolGate(option, strict, {
118
+ tool: 'next',
119
+ has: hasNext,
120
+ packageName: 'next',
121
+ /*
122
+ * rootDir entries may be relative or absolute paths OR globs (`apps/*` - the plugin
123
+ * expands them itself for its settings), so for the bridge probes each entry is expanded
124
+ * against the workspace root into real app dirs; a plain path that exists simply matches
125
+ * itself. An entry matching nothing falls back to the literal path as the probe anchor
126
+ * (harmless - resolution just walks up from there). The probes resolve from each app's
127
+ * package.json.
128
+ */
129
+ absolutizeOptions: ({ rootDir }) =>
130
+ (Array.isArray(rootDir) ? rootDir : [rootDir]).filter(Boolean).flatMap((dir) => {
131
+ const pattern = isAbsolute(dir) ? dir : resolve(findWorkspaceRoot(), dir);
132
+ // trailing slash = directories only; backslash normalization mirrors the plugin
133
+ const dirs = globSync(`${pattern.replace(/\\/g, '/').replace(/\/+$/, '')}/`, { absolute: true });
134
+ return (dirs.length > 0 ? dirs : [pattern]).map((appDir) => join(appDir, 'package.json'));
135
+ }),
136
+ scan: () => findNextRoots(GLOBAL_IGNORES).map((dir) => join(dir, 'package.json')),
137
+ });
138
+ if (!enabled) return reactBaseConfig();
139
+
140
+ // explicit rootDir is passed through in the consumer's own notation; auto-detected roots are
141
+ // the evidence dirs (absolute; empty under strict → no settings block, the setting is optional)
142
+ return nextBaseConfig({ ...options, rootDir: options.rootDir ?? files.map((file) => dirname(file)) });
143
+ }
144
+
145
+ /**
146
+ * TypeScript blocks - lives here because the wiring stems from `eslint-config-next/typescript`
147
+ * (typescript-eslint recommended setup, useful with or without Next itself) + deliberate overrides
148
+ * of its rule set.
149
+ *
150
+ * @returns {import('eslint').Linter.Config[]}
151
+ */
152
+ export function typescriptOverridesConfig() {
153
+ return [
154
+ ...nextTs,
155
+ {
156
+ name: '@typescript-eslint overrides',
157
+ files: [`**/*.${tsExts}`],
158
+ rules: {
159
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
160
+ '@typescript-eslint/no-empty-function': 'off',
161
+ '@typescript-eslint/no-explicit-any': 'off',
162
+ '@typescript-eslint/no-require-imports': 'off',
163
+ '@typescript-eslint/no-unused-vars': 'off', // superseded by 'unused-imports/no-unused-imports', which is actually autofixable
164
+ '@typescript-eslint/consistent-type-definitions': ['error', 'type'],
165
+ '@typescript-eslint/consistent-type-imports': [
166
+ 'error',
167
+ { prefer: 'type-imports', fixStyle: 'inline-type-imports' },
168
+ ],
169
+ '@typescript-eslint/ban-ts-comment': [
170
+ 'error',
171
+ {
172
+ 'ts-expect-error': 'allow-with-description',
173
+ 'ts-ignore': true,
174
+ 'ts-nocheck': true,
175
+ 'ts-check': false,
176
+ minimumDescriptionLength: 3,
177
+ },
178
+ ],
179
+ /*
180
+ * `as const` is the mechanical half of "Prefer `as const` and `readonly` for immutable
181
+ * constants and objects" - the `readonly` half is a per-case judgment call (which objects
182
+ * deserve it), so that guidance stays in typescript.md instead of being lint-enforced here.
183
+ */
184
+ '@typescript-eslint/prefer-as-const': 'error',
185
+ },
186
+ },
187
+ {
188
+ name: '@typescript-eslint declaration-file overrides',
189
+ files: ['**/*.d.ts'],
190
+ rules: {
191
+ /*
192
+ * `typeof import('pkg')` annotations are the standard mechanism in declaration files
193
+ * (tsc itself emits them when generating .d.ts) - the annotation ban of
194
+ * consistent-type-imports is meant for source files.
195
+ */
196
+ '@typescript-eslint/consistent-type-imports': [
197
+ 'error',
198
+ { prefer: 'type-imports', fixStyle: 'inline-type-imports', disallowTypeAnnotations: false },
199
+ ],
200
+ },
201
+ },
202
+ ];
203
+ }
204
+
205
+ /**
206
+ * Overrides of rules set by `eslint-config-next`. Always applied (not gated on Next): the
207
+ * jsx-a11y/react entries matter for {@link reactBaseConfig} consumers too, and turning off rules of an
208
+ * unregistered plugin is harmless.
209
+ *
210
+ * @returns {import('eslint').Linter.Config[]}
211
+ */
212
+ export function nextOverridesConfig() {
213
+ return [
214
+ {
215
+ name: 'eslint-config-next overrides',
216
+ rules: {
217
+ '@next/next/no-html-link-for-pages': 'off',
218
+ '@next/next/no-img-element': 'off',
219
+ 'import/no-anonymous-default-export': 'off', // overrides eslint-config-next's own default
220
+ 'jsx-a11y/alt-text': 'off',
221
+ 'react/prop-types': 'off', // ts does it statically
222
+ },
223
+ },
224
+ ];
225
+ }
226
+
227
+ /**
228
+ * FIXME ESLint 10 + Next fix
229
+ * https://github.com/vercel/next.js/issues/89764
230
+ * https://gist.github.com/OscarGauss/1f305edf5b7c103bb2ee32ba479f4261
231
+ *
232
+ * @returns {import('eslint').Linter.Config[]}
233
+ */
234
+ export function reactSettingsConfig() {
235
+ return [
236
+ {
237
+ settings: {
238
+ react: { version: '19' },
239
+ },
240
+ },
241
+ ];
242
+ }
243
+
244
+ /**
245
+ * The whole React family in its load-bearing order: {@link nextConfig} (Next when enabled, plain
246
+ * React otherwise - Next is just a shortcut to an opinionated React/TypeScript setup), then
247
+ * {@link typescriptOverridesConfig}, {@link nextOverridesConfig} and {@link reactSettingsConfig} -
248
+ * which apply NO MATTER whether Next or plain React won, so composing them individually risks
249
+ * ordering mistakes; defineLintConfig uses this composite.
250
+ *
251
+ * @param {boolean | NextOptions} [option] the defineLintConfig `next` flag
252
+ * @param {boolean} [strict] same-scope detection only (defineLintConfig `detection.strict`)
253
+ * @returns {Promise<import('eslint').Linter.Config[]>}
254
+ */
255
+ export async function reactConfig(option, strict = false) {
256
+ return [
257
+ ...(await nextConfig(option, strict)),
258
+ ...typescriptOverridesConfig(),
259
+ ...nextOverridesConfig(),
260
+ ...reactSettingsConfig(),
261
+ ];
262
+ }
@@ -0,0 +1,26 @@
1
+ import { GLOBAL_IGNORES, hasStorybook, scanWorkspace, toolGate } from '../lib.js';
2
+
3
+ /**
4
+ * Storybook recommended rules. Full evidence-based gate (see `toolGate` in lib.js), mirroring
5
+ * Tailwind: a `.storybook/main.*` marks a Storybook repo even when the `storybook` package is
6
+ * installed only in a leaf package (invisible to `hasStorybook`) - and because
7
+ * `eslint-plugin-storybook` statically imports the `storybook` package itself, leaf-only installs
8
+ * are bridged (see `ensurePackageResolvable` in lib.js for the mechanism and PnP behavior); the
9
+ * plugin stays lazily imported so consumers without Storybook never pay for it.
10
+ *
11
+ * @param {boolean | import('../index.js').ToggleOptions} [option] the defineLintConfig `storybook` flag; auto-detected when omitted
12
+ * @param {boolean} [strict] same-scope detection only - no `.storybook` scan, no bridge (defineLintConfig `detection.strict`)
13
+ * @returns {Promise<import('eslint').Linter.Config[]>}
14
+ */
15
+ export async function storybookConfig(option, strict = false) {
16
+ const { enabled } = toolGate(option, strict, {
17
+ tool: 'storybook',
18
+ has: hasStorybook,
19
+ packageName: 'storybook',
20
+ scan: () => scanWorkspace('.storybook/main.*', GLOBAL_IGNORES, { dot: true }),
21
+ });
22
+ if (!enabled) return [];
23
+
24
+ const storybookPlugin = (await import('eslint-plugin-storybook')).default;
25
+ return storybookPlugin.configs['flat/recommended'];
26
+ }
@@ -0,0 +1,100 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { isAbsolute, resolve } from 'node:path';
3
+
4
+ import { findWorkspaceRoot, GLOBAL_IGNORES, hasTailwind, scanWorkspace, toolGate } from '../lib.js';
5
+
6
+ /**
7
+ * All Tailwind v4 entry CSS candidates: every `*.css` below the workspace root (see
8
+ * `scanWorkspace` - up to five directory levels, `.gitignore`- and build-output-aware) containing
9
+ * the Tailwind v4 marker `@import "tailwindcss"`.
10
+ *
11
+ * @param {string[]} ignores glob patterns to skip
12
+ * @returns {string[]} absolute paths
13
+ */
14
+ function findTailwindEntries(ignores) {
15
+ return scanWorkspace('*.css', ignores).filter((file) => {
16
+ try {
17
+ return /@import\s+['"]tailwindcss['"]/.test(readFileSync(file, 'utf-8'));
18
+ } catch {
19
+ return false;
20
+ }
21
+ });
22
+ }
23
+
24
+ /**
25
+ * Auto-find THE Tailwind v4 entry CSS ({@link findTailwindEntries} narrowed to exactly one).
26
+ *
27
+ * eslint-plugin-tailwindcss v4 loads the entry (`settings.tailwindcss.cssConfigPath`) and
28
+ * HARD-CRASHES with ENOENT when it can't, so {@link tailwindConfig} only enables the plugin when
29
+ * exactly one entry is found (`allowMultiple: false` in its gate spec); with zero or several the
30
+ * consumer must configure `cssConfigPath` manually (MANDATORY for the plugin; several candidates
31
+ * are a hard error) - see README "Detection".
32
+ *
33
+ * @param {string[]} ignores glob patterns to skip
34
+ * @returns {string | null} absolute path of the single entry, or null when zero or several were found
35
+ */
36
+ export function findTailwindEntry(ignores) {
37
+ const entries = findTailwindEntries(ignores);
38
+ return entries.length === 1 ? entries[0] : null;
39
+ }
40
+
41
+ /** @typedef {import('../index.js').TailwindOptions} TailwindOptions Defined in index.d.ts. */
42
+
43
+ /**
44
+ * Tailwind recommended rules (warnings + `no-contradicting-classname` as error) as a standalone
45
+ * block (simple to override wholesale).
46
+ *
47
+ * Auto-detection is driven by the entry CSS (see {@link findTailwindEntries}), not by the package
48
+ * probe: explicit `cssConfigPath` wins, otherwise auto-find. Zero entries stays inert in auto mode
49
+ * (nothing marks the repo as Tailwind) but fails loudly when Tailwind was FORCED on (`true` /
50
+ * options object) - and so does an entry whose `tailwindcss` package cannot be resolved at all.
51
+ * SEVERAL entries fail loudly even in auto mode: they prove the repo uses Tailwind, the right one
52
+ * cannot be guessed, and a silent skip would be hard to detect - pass `cssConfigPath` to pick one. Leaf-only installs (tailwindcss next to the entry but invisible from the
53
+ * workspace root, where the plugin's theme-loading workers resolve it) are bridged via
54
+ * `ensurePackageResolvable` in lib.js - see its doc for the full mechanism and PnP behavior.
55
+ *
56
+ * @param {boolean | TailwindOptions} [option] the defineLintConfig `tailwind` flag; auto-detected when omitted
57
+ * @param {boolean} [strict] same-scope detection only - no entry scan, no bridge (defineLintConfig `detection.strict`)
58
+ * @returns {Promise<import('eslint').Linter.Config[]>}
59
+ */
60
+ export async function tailwindConfig(option, strict = false) {
61
+ /*
62
+ * Detection is evidence-based: the entry CSS marker, NOT the package probe (`needs` makes the
63
+ * evidence mandatory in the gate) - in a monorepo `tailwindcss` is often installed only in a
64
+ * leaf package and unresolvable from here, while an entry CSS with `@import "tailwindcss"` is
65
+ * unambiguous proof of a Tailwind project (`hasTailwind` stays exported for debugging).
66
+ */
67
+ const { enabled, options, files } = toolGate(option, strict, {
68
+ tool: 'tailwind',
69
+ has: hasTailwind,
70
+ packageName: 'tailwindcss',
71
+ needs: {
72
+ what: 'entry CSS',
73
+ detail:
74
+ 'single Tailwind v4 entry CSS (a *.css containing `@import "tailwindcss"`, scanned up to ' +
75
+ '5 directory levels below the workspace root)',
76
+ hint: '`tailwind: { cssConfigPath }`',
77
+ },
78
+ // the plugin takes exactly ONE entry - several scan candidates are a hard error
79
+ allowMultiple: false,
80
+ // option paths may be relative; the resolution probe needs an absolute file context
81
+ absolutizeOptions: ({ cssConfigPath }) =>
82
+ cssConfigPath
83
+ ? [isAbsolute(cssConfigPath) ? cssConfigPath : resolve(findWorkspaceRoot(), cssConfigPath)]
84
+ : [],
85
+ scan: () => findTailwindEntries(GLOBAL_IGNORES),
86
+ });
87
+ if (!enabled) return [];
88
+
89
+ // an explicit path is passed through in the consumer's own notation (the absolutized copy only
90
+ // served the probes); an auto-found entry is the absolute evidence file
91
+ const cssConfigPath = options.cssConfigPath ?? files[0];
92
+
93
+ const tailwindPlugin = (await import('eslint-plugin-tailwindcss')).default;
94
+ return [
95
+ {
96
+ ...tailwindPlugin.configs.recommended,
97
+ settings: { tailwindcss: { cssConfigPath } },
98
+ },
99
+ ];
100
+ }
@@ -0,0 +1,158 @@
1
+ /*
2
+ * jest/vitest plugins are statically imported even though their recommended sets are gated:
3
+ * the runner-agnostic testConfig() registers both plugins unconditionally (its rules are pure
4
+ * AST checks that work without the runner installed).
5
+ *
6
+ * Each test-runner's recommended rule set is gated on the runner actually being installed - per
7
+ * rules/testing.md ("if project use vite use vitest, otherwise jest"), a project normally has
8
+ * exactly one of these, and applying the other runner's correctness rules to it would be
9
+ * conceptually wrong (even if mechanically harmless, since the rule namespaces don't collide).
10
+ */
11
+ import fs from 'node:fs';
12
+ import path from 'node:path';
13
+ import vitestPlugin from '@vitest/eslint-plugin';
14
+ import jestPlugin from 'eslint-plugin-jest';
15
+
16
+ import { GLOBAL_IGNORES, hasJest, hasVitest, scanWorkspace, toolGate, tsExts, tsExtsRaw } from '../lib.js';
17
+
18
+ export { jestPlugin, vitestPlugin };
19
+
20
+ /*
21
+ * Both runners use the evidence-based `toolGate` (see lib.js): a runner config file marks the repo
22
+ * even when the runner is installed only in a leaf package (invisible to the `has*` probe), and
23
+ * the runner package itself must then be resolvable - eslint-plugin-jest sniffs the installed
24
+ * `jest` version (jest/no-deprecated-functions) - so leaf-only installs are bridged. Unlike the
25
+ * plugin-crashing tools (next/storybook/tailwind) the rules are pure AST checks that work without
26
+ * the runner, so forcing a runner on never throws (`requirePackage: false`).
27
+ */
28
+
29
+ // derived from the shared extension list - one source of truth with the lint file globs
30
+ const SOURCE_EXTS = tsExtsRaw.split(',').map((ext) => `.${ext}`);
31
+ const TEST_SUFFIX = new RegExp(`\\.test\\.(${tsExtsRaw.replaceAll(',', '|')})$`);
32
+
33
+ /**
34
+ * Custom rule (registered as `local/test-colocation` by {@link testConfig}). Only `*.test.*` is
35
+ * checked, not `*.spec.*` - per testing.md, spec files cover e2e/integration flows that don't map
36
+ * 1:1 to a single sibling source file, so co-location isn't meaningful there.
37
+ */
38
+ const testColocation = {
39
+ meta: {
40
+ type: 'problem',
41
+ docs: {
42
+ description: 'require *.test.* files to sit next to the source file they test, not in a separate folder',
43
+ },
44
+ schema: [],
45
+ messages: {
46
+ missingSibling:
47
+ "No sibling source file found for '{{testFile}}'. Expected e.g. '{{expected}}' in the same directory, not a separate __tests__/ folder.",
48
+ },
49
+ },
50
+ create(context) {
51
+ const base = path.basename(context.filename);
52
+ const match = base.match(TEST_SUFFIX);
53
+
54
+ if (!match) return {};
55
+
56
+ const stem = base.slice(0, -match[0].length);
57
+
58
+ let siblings;
59
+ try {
60
+ siblings = fs.readdirSync(path.dirname(context.filename));
61
+ } catch {
62
+ return {}; // virtual filename (stdin, editor buffer) - no directory to check against
63
+ }
64
+
65
+ if (SOURCE_EXTS.some((ext) => siblings.includes(`${stem}${ext}`))) return {};
66
+
67
+ return {
68
+ Program(node) {
69
+ context.report({
70
+ node,
71
+ messageId: 'missingSibling',
72
+ data: { testFile: base, expected: `${stem}.ts` },
73
+ });
74
+ },
75
+ };
76
+ },
77
+ };
78
+
79
+ /**
80
+ * Jest recommended rules, scoped to test files.
81
+ *
82
+ * @param {boolean | import('../index.js').ToggleOptions} [option] the defineLintConfig `jest` flag; auto-detected when omitted
83
+ * @returns {import('eslint').Linter.Config[]}
84
+ */
85
+ export function jestConfig(option, strict = false) {
86
+ const { enabled } = toolGate(option, strict, {
87
+ tool: 'jest',
88
+ has: hasJest,
89
+ packageName: 'jest',
90
+ requirePackage: false,
91
+ scan: () => scanWorkspace('jest.config.*', GLOBAL_IGNORES),
92
+ });
93
+ if (!enabled) return [];
94
+ return [
95
+ {
96
+ ...jestPlugin.configs['flat/recommended'],
97
+ name: 'Jest Rules',
98
+ files: [`**/*.{test,spec}.${tsExts}`],
99
+ },
100
+ ];
101
+ }
102
+
103
+ /**
104
+ * Vitest recommended rules + globals, scoped to test files.
105
+ *
106
+ * @param {boolean | import('../index.js').ToggleOptions} [option] the defineLintConfig `vitest` flag; auto-detected when omitted
107
+ * @returns {import('eslint').Linter.Config[]}
108
+ */
109
+ export function vitestConfig(option, strict = false) {
110
+ const { enabled } = toolGate(option, strict, {
111
+ tool: 'vitest',
112
+ has: hasVitest,
113
+ packageName: 'vitest',
114
+ requirePackage: false,
115
+ // vitest is often configured inside vite.config.* - both count as evidence
116
+ scan: () => scanWorkspace('{vitest,vite}.config.*', GLOBAL_IGNORES),
117
+ });
118
+ if (!enabled) return [];
119
+ return [
120
+ {
121
+ ...vitestPlugin.configs.recommended,
122
+ name: 'Vitest Rules',
123
+ files: [`**/*.{test,spec}.${tsExts}`],
124
+ },
125
+ {
126
+ ...vitestPlugin.configs.env,
127
+ name: 'Vitest globals',
128
+ files: [`**/*.{test,spec}.${tsExts}`],
129
+ },
130
+ ];
131
+ }
132
+
133
+ /**
134
+ * Runner-agnostic test rules: pure AST/call-name checking, needs neither jest nor vitest installed
135
+ * to work correctly, so it applies regardless of which one (if either) is present.
136
+ *
137
+ * @returns {import('eslint').Linter.Config[]}
138
+ */
139
+ export function testConfig() {
140
+ return [
141
+ {
142
+ name: 'Test rules',
143
+ files: [`**/*.{test,spec}.${tsExts}`],
144
+ plugins: {
145
+ jest: jestPlugin,
146
+ vitest: vitestPlugin,
147
+ local: { rules: { 'test-colocation': testColocation } },
148
+ },
149
+ rules: {
150
+ 'jest/consistent-test-it': ['error', { fn: 'test' }],
151
+ 'vitest/consistent-test-it': ['error', { fn: 'test' }],
152
+ 'local/test-colocation': 'error',
153
+ 'jest/no-disabled-tests': 'warn',
154
+ 'vitest/no-disabled-tests': 'warn',
155
+ },
156
+ },
157
+ ];
158
+ }
@@ -0,0 +1,29 @@
1
+ import { hasTurbo, toolGate } from '../lib.js';
2
+
3
+ // lazy so consumers without Turbo don't pay the load cost - re-exported from index.js
4
+ export const turboPlugin = hasTurbo ? (await import('eslint-plugin-turbo')).default : null;
5
+
6
+ /**
7
+ * Turborepo rules. Probe-only gate (see `toolGate` in lib.js) - no evidence scan, no bridge.
8
+ *
9
+ * @param {boolean | import('../index.js').ToggleOptions} [option] the defineLintConfig `turbo` flag; auto-detected when omitted
10
+ * @returns {Promise<import('eslint').Linter.Config[]>}
11
+ */
12
+ export async function turboConfig(option) {
13
+ const { enabled } = toolGate(option, false, { tool: 'turbo', has: hasTurbo });
14
+ if (!enabled) return [];
15
+ const turbo = (await import('eslint-plugin-turbo')).default;
16
+ return [
17
+ turbo.configs['flat/recommended'],
18
+ {
19
+ name: 'eslint-plugin-turbo overrides',
20
+ rules: {
21
+ /*
22
+ * Only covers undeclared env vars, not the full dependsOn/outputs consistency - that part has no
23
+ * ESLint-shaped check. Downgraded from their default 'error' to 'warn'.
24
+ */
25
+ 'turbo/no-undeclared-env-vars': 'warn',
26
+ },
27
+ },
28
+ ];
29
+ }