@kirill.konshin/lint 0.3.0 → 0.3.2

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.
@@ -1,29 +1,40 @@
1
1
  import { readFileSync } from 'node:fs';
2
+ import { isAbsolute, resolve } from 'node:path';
2
3
 
3
- import { asOptions, GLOBAL_IGNORES, hasTailwind, scanWorkspace } from '../lib.js';
4
+ import { findWorkspaceRoot, GLOBAL_IGNORES, hasTailwind, packageDirOf, scanWorkspace, toolGate } from '../lib.js';
4
5
 
5
6
  /**
6
- * Auto-find the Tailwind v4 entry CSS: the single `*.css` below the workspace root (see
7
- * `scanWorkspace` - up to five directory levels, `.gitignore`- and build-output-aware) containing
8
- * the Tailwind v4 marker `@import "tailwindcss"`.
9
- *
10
- * eslint-plugin-tailwindcss v4 loads the entry (`settings.tailwindcss.cssConfigPath`) and
11
- * HARD-CRASHES with ENOENT when it can't, so {@link tailwindConfig} only enables the plugin when
12
- * exactly one entry is found; with zero or several the consumer configures `cssConfigPath`
13
- * manually (MANDATORY for the plugin) - see README "Tailwind CSS rules".
7
+ * All Tailwind v4 entry CSS candidates: every `*.css` across the workspace (see `scanWorkspace` -
8
+ * the root plus every workspace package, `.gitignore`- and build-output-aware) containing the
9
+ * Tailwind v4 marker `@import "tailwindcss"`.
14
10
  *
15
11
  * @param {string[]} ignores glob patterns to skip
16
- * @returns {string | null} absolute path of the single entry, or null when zero or several were found
12
+ * @returns {string[]} absolute paths
17
13
  */
18
- export function findTailwindEntry(ignores) {
19
- const entries = scanWorkspace('*.css', ignores).filter((file) => {
14
+ function findTailwindEntries(ignores) {
15
+ return scanWorkspace('*.css', ignores).filter((file) => {
20
16
  try {
21
17
  return /@import\s+['"]tailwindcss['"]/.test(readFileSync(file, 'utf-8'));
22
18
  } catch {
23
19
  return false;
24
20
  }
25
21
  });
22
+ }
26
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);
27
38
  return entries.length === 1 ? entries[0] : null;
28
39
  }
29
40
 
@@ -33,39 +44,69 @@ export function findTailwindEntry(ignores) {
33
44
  * Tailwind recommended rules (warnings + `no-contradicting-classname` as error) as a standalone
34
45
  * block (simple to override wholesale).
35
46
  *
36
- * Detection alone isn't enough here: the plugin needs a resolvable entry CSS (see
37
- * {@link findTailwindEntry}). Explicit `cssConfigPath` wins; otherwise auto-find. Auto-detected +
38
- * zero-or-several entries stays inert (consumer passes the path manually), but when Tailwind was
39
- * FORCED on (`true` / options object) the consumer explicitly asked for it, so an empty/ambiguous
40
- * scan fails loudly instead of silently skipping.
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). SEVERAL entries fail loudly even in auto mode: they prove the repo uses
51
+ * Tailwind, the right one cannot be guessed, and a silent skip would be hard to detect - pass
52
+ * `cssConfigPath` to pick one. `tailwindcss` must be resolvable from the workspace root (where
53
+ * the plugin's theme-loading workers resolve it); a leaf-only install is a hard error with
54
+ * hoisting guidance (see `toolGate` in lib.js).
41
55
  *
42
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`)
43
58
  * @returns {Promise<import('eslint').Linter.Config[]>}
44
59
  */
45
- export async function tailwindConfig(option) {
46
- const { enabled, ...options } = asOptions(option);
47
- if (!(enabled ?? hasTailwind)) return [];
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 across ' +
75
+ 'the workspace root and every workspace package)',
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 [];
48
88
 
49
- const { cssConfigPath = findTailwindEntry(GLOBAL_IGNORES) } = options;
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];
50
92
 
51
- if (!cssConfigPath) {
52
- // `enabled` is only defined when the consumer explicitly turned Tailwind on - fail loudly
53
- // then; detection-driven activation (enabled === undefined) stays inert instead.
54
- if (enabled) {
55
- throw new Error(
56
- '[@kirill.konshin/lint] `tailwind` was enabled explicitly, but no single Tailwind v4 entry CSS ' +
57
- '(a *.css containing `@import "tailwindcss"`, scanned up to 5 directory levels below the ' +
58
- 'workspace root) was found - zero or several candidates. ' +
59
- 'Pass `tailwind: { cssConfigPath }` explicitly.',
60
- );
61
- }
62
- return [];
63
- }
93
+ /*
94
+ * The entry CSS pins down the ONE package that uses Tailwind, so by default the block is
95
+ * scoped to it via `basePath` (ESLint >= 9.30, absolute paths supported) instead of flagging
96
+ * class-like strings across the whole workspace. `files[0]` is the absolutized evidence path
97
+ * even when `cssConfigPath` was supplied relative. Owning package == workspace root (single-
98
+ * package repo, or the entry is not inside a declared workspace package) makes scoping a
99
+ * no-op - the block stays untouched.
100
+ */
101
+ const { scoped = true } = options;
102
+ const packageDir = scoped ? packageDirOf(files[0]) : null;
103
+ const basePath = packageDir && packageDir !== findWorkspaceRoot() ? { basePath: packageDir } : {};
64
104
 
65
105
  const tailwindPlugin = (await import('eslint-plugin-tailwindcss')).default;
66
106
  return [
67
107
  {
68
108
  ...tailwindPlugin.configs.recommended,
109
+ ...basePath,
69
110
  settings: { tailwindcss: { cssConfigPath } },
70
111
  },
71
112
  ];
@@ -13,10 +13,19 @@ import path from 'node:path';
13
13
  import vitestPlugin from '@vitest/eslint-plugin';
14
14
  import jestPlugin from 'eslint-plugin-jest';
15
15
 
16
- import { asOptions, hasJest, hasVitest, tsExts, tsExtsRaw } from '../lib.js';
16
+ import { GLOBAL_IGNORES, hasJest, hasVitest, scanWorkspace, toolGate, tsExts, tsExtsRaw } from '../lib.js';
17
17
 
18
18
  export { jestPlugin, vitestPlugin };
19
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
+
20
29
  // derived from the shared extension list - one source of truth with the lint file globs
21
30
  const SOURCE_EXTS = tsExtsRaw.split(',').map((ext) => `.${ext}`);
22
31
  const TEST_SUFFIX = new RegExp(`\\.test\\.(${tsExtsRaw.replaceAll(',', '|')})$`);
@@ -73,8 +82,14 @@ const testColocation = {
73
82
  * @param {boolean | import('../index.js').ToggleOptions} [option] the defineLintConfig `jest` flag; auto-detected when omitted
74
83
  * @returns {import('eslint').Linter.Config[]}
75
84
  */
76
- export function jestConfig(option) {
77
- const { enabled = hasJest } = asOptions(option);
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
+ });
78
93
  if (!enabled) return [];
79
94
  return [
80
95
  {
@@ -91,8 +106,15 @@ export function jestConfig(option) {
91
106
  * @param {boolean | import('../index.js').ToggleOptions} [option] the defineLintConfig `vitest` flag; auto-detected when omitted
92
107
  * @returns {import('eslint').Linter.Config[]}
93
108
  */
94
- export function vitestConfig(option) {
95
- const { enabled = hasVitest } = asOptions(option);
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
+ });
96
118
  if (!enabled) return [];
97
119
  return [
98
120
  {
package/configs/turbo.js CHANGED
@@ -1,16 +1,16 @@
1
- import { asOptions, hasTurbo } from '../lib.js';
1
+ import { hasTurbo, toolGate } from '../lib.js';
2
2
 
3
3
  // lazy so consumers without Turbo don't pay the load cost - re-exported from index.js
4
4
  export const turboPlugin = hasTurbo ? (await import('eslint-plugin-turbo')).default : null;
5
5
 
6
6
  /**
7
- * Turborepo rules.
7
+ * Turborepo rules. Probe-only gate (see `toolGate` in lib.js) - no evidence scan, no bridge.
8
8
  *
9
9
  * @param {boolean | import('../index.js').ToggleOptions} [option] the defineLintConfig `turbo` flag; auto-detected when omitted
10
10
  * @returns {Promise<import('eslint').Linter.Config[]>}
11
11
  */
12
12
  export async function turboConfig(option) {
13
- const { enabled = hasTurbo } = asOptions(option);
13
+ const { enabled } = toolGate(option, false, { tool: 'turbo', has: hasTurbo });
14
14
  if (!enabled) return [];
15
15
  const turbo = (await import('eslint-plugin-turbo')).default;
16
16
  return [
@@ -22,14 +22,15 @@ import { asOptions, findWorkspaceRoot } from '../lib.js';
22
22
  * nothing to auto-detect, so only an explicit `true` / options object enables the block
23
23
  * @returns {import('eslint').Linter.Config[]}
24
24
  */
25
- export function typeAwareConfig(option) {
25
+ export function typeAwareConfig(option, strict = false) {
26
26
  let {
27
27
  enabled = false,
28
28
  allowDefaultProject,
29
29
  // matches the list when it's exact files (the scanWorkspace flow); with multi-match globs
30
30
  // set the cap explicitly - typescript-eslint errors loudly when matches exceed it
31
31
  maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING = allowDefaultProject?.length,
32
- tsconfigRootDir = findWorkspaceRoot(),
32
+ // strict detection avoids the workspace walk
33
+ tsconfigRootDir = strict ? process.cwd() : findWorkspaceRoot(),
33
34
  } = asOptions(option);
34
35
  if (!enabled) return [];
35
36
 
package/index.d.ts CHANGED
@@ -25,13 +25,31 @@ export type ToggleOptions = {
25
25
  enabled?: boolean;
26
26
  };
27
27
 
28
+ /**
29
+ * Detection behavior ({@link defineLintConfig} `detection`) - the same toggle notation as the
30
+ * tool flags:
31
+ * - `undefined` / `true` / `{}` - tools default ON via full auto-detection
32
+ * - `false` / `{ enabled: false }` - tools default OFF; explicitly enabled tools still
33
+ * auto-detect their settings
34
+ * - `strict: true` - same-scope package probes only (exactly what the `has*` checks are): no
35
+ * evidence scans; mandatory settings like `cssConfigPath` must be explicit, and `nx.json` is
36
+ * checked at cwd instead of the workspace root. `{ enabled: false, strict: true }` is ideal for
37
+ * per-package monorepo configs.
38
+ */
39
+ export type DetectionOptions = ToggleOptions & {
40
+ /** same-scope package probes only - no workspace evidence scans */
41
+ strict?: boolean;
42
+ };
43
+
28
44
  /** Options for the Next.js blocks ({@link nextBaseConfig}). */
29
45
  export type NextOptions = ToggleOptions & {
30
46
  /**
31
47
  * Root of the Next.js app(s) for `@next/eslint-plugin-next` (`settings.next.rootDir`) - needed
32
48
  * when the apps don't live at the workspace root, e.g. `path/to/next-app` (globs are supported
33
- * by the plugin). When omitted, auto-detected via {@link findNextRoots}: no `next.config.*`
34
- * found → no settings (the setting is optional), several apps → all of them as an array.
49
+ * by the plugin; pass the package root, not `src` - the plugin resolves both the `pages`/`app`
50
+ * and `src/pages`/`src/app` layouts from it). When omitted, auto-detected via
51
+ * {@link findNextRoots}: no evidence found → no settings (the setting is optional), several
52
+ * apps → all of them as an array.
35
53
  *
36
54
  * @see https://nextjs.org/docs/app/api-reference/config/eslint
37
55
  */
@@ -46,6 +64,15 @@ export type TailwindOptions = ToggleOptions & {
46
64
  * {@link findTailwindEntry}.
47
65
  */
48
66
  cssConfigPath?: TailwindPluginSettings['cssConfigPath'];
67
+ /**
68
+ * Scope the Tailwind rules to the workspace package that owns the entry CSS (emitted as the
69
+ * block's `basePath`, ESLint >= 9.30) instead of the whole workspace. No-op when the entry is
70
+ * owned by the workspace root itself (single-package repo, or not inside a declared
71
+ * workspace package).
72
+ *
73
+ * @default true
74
+ */
75
+ scoped?: boolean;
49
76
  };
50
77
 
51
78
  /**
@@ -86,6 +113,8 @@ export type DefaultIgnoreOptions = ToggleOptions & {
86
113
  * The gated `*Config()` block functions accept the same flag value directly.
87
114
  */
88
115
  export type LintOptions = {
116
+ /** Detection behavior: default tool state + strict mode; see {@link DetectionOptions} */
117
+ detection?: boolean | DetectionOptions;
89
118
  /** Next.js (`eslint-config-next`); when off, generic React/JSX rules apply instead */
90
119
  next?: boolean | NextOptions;
91
120
  /** Storybook (`eslint-plugin-storybook`) */
@@ -98,7 +127,7 @@ export type LintOptions = {
98
127
  jest?: boolean | ToggleOptions;
99
128
  /** Vitest recommended rules for `*.{test,spec}.*` */
100
129
  vitest?: boolean | ToggleOptions;
101
- /** Tailwind (`eslint-plugin-tailwindcss`); forcing ON without a resolvable entry CSS is a hard error */
130
+ /** Tailwind (`eslint-plugin-tailwindcss`); forcing ON without a resolvable entry CSS is a hard error, several entry CSS candidates always are */
102
131
  tailwind?: boolean | TailwindOptions;
103
132
  /** Type-aware TypeScript rules; off by default (slow), nothing to auto-detect */
104
133
  typeAware?: boolean | TypeAwareOptions;
@@ -129,9 +158,16 @@ export function defaultIgnoreConfig(option?: boolean | DefaultIgnoreOptions): Li
129
158
  /** The whole `eslint-config-next` flat config, plus `settings.next.rootDir` when given. Next-only, ungated. */
130
159
  export function nextBaseConfig(options?: NextOptions): Promise<Linter.Config[]>;
131
160
  /** React/React Hooks/jsx-a11y rules for non-Next (e.g. Vite) React projects. Ungated. */
132
- export function reactConfig(): Linter.Config[];
133
- /** Composite: {@link nextBaseConfig} when Next is enabled, the {@link reactConfig} fallback otherwise. */
134
- export function nextConfig(option?: boolean | NextOptions): Promise<Linter.Config[]>;
161
+ export function reactBaseConfig(): Linter.Config[];
162
+ /** Chooser: {@link nextBaseConfig} when Next is enabled, the {@link reactBaseConfig} fallback otherwise. */
163
+ export function nextConfig(option?: boolean | NextOptions, strict?: boolean): Promise<Linter.Config[]>;
164
+ /**
165
+ * The whole React family in its load-bearing order - {@link nextConfig} (Next is just a shortcut
166
+ * to an opinionated React/TypeScript setup), then {@link typescriptOverridesConfig},
167
+ * {@link nextOverridesConfig} and {@link reactSettingsConfig}, which apply no matter whether Next
168
+ * or plain React won. Used by {@link defineLintConfig}; `option` is the `next` flag.
169
+ */
170
+ export function reactConfig(option?: boolean | NextOptions, strict?: boolean): Promise<Linter.Config[]>;
135
171
  /** `eslint-config-next/typescript` (typescript-eslint wiring, which stems from Next) + deliberate rule overrides. */
136
172
  export function typescriptOverridesConfig(): Linter.Config[];
137
173
  /** Overrides of rules set by `eslint-config-next` (always applied, harmless without Next). */
@@ -141,7 +177,7 @@ export function reactSettingsConfig(): Linter.Config[];
141
177
  /** Prettier compatibility (`eslint-config-prettier/flat`). */
142
178
  export function prettierConfig(): Linter.Config[];
143
179
  /** Storybook recommended rules. */
144
- export function storybookConfig(option?: boolean | ToggleOptions): Promise<Linter.Config[]>;
180
+ export function storybookConfig(option?: boolean | ToggleOptions, strict?: boolean): Promise<Linter.Config[]>;
145
181
  /** eslint-plugin-import-x recommended rules + overrides + the default-export relaxation for conventional files. */
146
182
  export function importXConfig(): Linter.Config[];
147
183
  /** Deterministic import ordering (eslint-plugin-simple-import-sort). */
@@ -153,21 +189,21 @@ export function promiseConfig(): Linter.Config[];
153
189
  /** Filename casing + node: protocol (two hand-picked unicorn rules). */
154
190
  export function unicornConfig(): Linter.Config[];
155
191
  /** Type-aware rules via typescript-eslint's projectService; off unless the flag is set (nothing to auto-detect). */
156
- export function typeAwareConfig(option?: boolean | TypeAwareOptions): Linter.Config[];
192
+ export function typeAwareConfig(option?: boolean | TypeAwareOptions, strict?: boolean): Linter.Config[];
157
193
  /** Turborepo rules. */
158
194
  export function turboConfig(option?: boolean | ToggleOptions): Promise<Linter.Config[]>;
159
195
  /**
160
196
  * Tailwind recommended rules. Explicit `cssConfigPath` wins; otherwise auto-found via
161
- * {@link findTailwindEntry}. Forced on (`true`/options) + zero-or-ambiguous scan throws;
162
- * auto-detected stays inert.
197
+ * {@link findTailwindEntry}. Zero entries: inert when auto-detected, throws when forced on
198
+ * (`true`/options). Several entries ALWAYS throw - pass `cssConfigPath` to pick one.
163
199
  */
164
- export function tailwindConfig(option?: boolean | TailwindOptions): Promise<Linter.Config[]>;
200
+ export function tailwindConfig(option?: boolean | TailwindOptions, strict?: boolean): Promise<Linter.Config[]>;
165
201
  /** Nx plugin registration + `@nx/dependency-checks`. */
166
- export function nxConfig(option?: boolean | ToggleOptions): Promise<Linter.Config[]>;
202
+ export function nxConfig(option?: boolean | ToggleOptions, strict?: boolean): Promise<Linter.Config[]>;
167
203
  /** Jest recommended rules, scoped to test files. */
168
- export function jestConfig(option?: boolean | ToggleOptions): Linter.Config[];
204
+ export function jestConfig(option?: boolean | ToggleOptions, strict?: boolean): Linter.Config[];
169
205
  /** Vitest recommended rules + globals, scoped to test files. */
170
- export function vitestConfig(option?: boolean | ToggleOptions): Linter.Config[];
206
+ export function vitestConfig(option?: boolean | ToggleOptions, strict?: boolean): Linter.Config[];
171
207
  /** Runner-agnostic test rules (consistent-test-it, test colocation). Always applied. */
172
208
  export function testConfig(): Linter.Config[];
173
209
 
@@ -211,25 +247,29 @@ export const vitestPlugin: typeof import('@vitest/eslint-plugin').default;
211
247
  // ----- Helpers & companion configs -----
212
248
 
213
249
  /**
214
- * Auto-find the Tailwind v4 entry CSS: the single `*.css` (scanned up to 5 directory levels below
215
- * the workspace root, skipping `.gitignore`d files and build outputs) containing
250
+ * Auto-find the Tailwind v4 entry CSS: the single `*.css` (scanned across the workspace root and
251
+ * every workspace package, skipping `.gitignore`d files and build outputs) containing
216
252
  * `@import "tailwindcss"`; null when zero or several match.
217
253
  */
218
254
  export function findTailwindEntry(ignores: string[]): string | null;
219
255
 
220
256
  /**
221
- * Auto-find Next.js app roots: every directory below the workspace root (scanned up to 5 levels,
222
- * skipping `.gitignore`d files and build outputs) containing a `next.config.*`; deduplicated and
223
- * sorted.
257
+ * Auto-find Next.js app roots (scanned across the workspace root and every workspace package,
258
+ * skipping `.gitignore`d files and build outputs). `next.config.*` is optional in Next.js, so any of three
259
+ * signals marks an app root: a `next.config.*`, a `package.json` depending on `next`
260
+ * (dependencies/devDependencies - peer declarations mark libraries, not apps), or a
261
+ * `src/app`/`src/pages` directory (the reported root is the directory containing `src`);
262
+ * deduplicated and sorted.
224
263
  */
225
264
  export function findNextRoots(ignores: string[]): string[];
226
265
 
227
266
  /**
228
- * Glob for config-file candidates below the workspace root (up to 5 directory levels, skipping
229
- * dot dirs, build outputs, extra `ignores` and everything in the root `.gitignore`). Returns
230
- * absolute paths - useful for building file lists like `typeAware.allowDefaultProject`.
267
+ * Glob for config-file candidates across the workspace - the root directory plus every workspace
268
+ * package (the real `workspaces` globs, not a depth heuristic) - skipping dot dirs unless `dot`,
269
+ * build outputs, extra `ignores` and everything in the root `.gitignore`.
270
+ * Returns absolute paths - useful for building file lists like `typeAware.allowDefaultProject`.
231
271
  */
232
- export function scanWorkspace(fileGlob: string, ignores?: string[]): string[];
272
+ export function scanWorkspace(fileGlob: string, ignores?: string[], options?: { dot?: boolean }): string[];
233
273
 
234
274
  /** Convert an ignore file (`.gitignore`, `.prettierignore`) into an ESLint ignores block. */
235
275
  export function includeIgnoreFile(importMetaUrl: string, ignoreFile: string): Linter.Config;
package/index.js CHANGED
@@ -17,21 +17,21 @@
17
17
  */
18
18
  import { baseConfig, defaultIgnoreConfig } from './configs/base.js';
19
19
  import { importSortConfig, importXConfig, unusedImportsConfig } from './configs/imports.js';
20
- import { nextConfig, nextOverridesConfig, reactSettingsConfig, typescriptOverridesConfig } from './configs/next.js';
21
20
  import { nxConfig } from './configs/nx.js';
22
21
  import { prettierConfig } from './configs/prettier.js';
23
22
  import { promiseConfig } from './configs/promise.js';
23
+ import { reactConfig } from './configs/react.js';
24
24
  import { storybookConfig } from './configs/storybook.js';
25
25
  import { tailwindConfig } from './configs/tailwind.js';
26
26
  import { jestConfig, testConfig, vitestConfig } from './configs/testing.js';
27
27
  import { turboConfig } from './configs/turbo.js';
28
28
  import { typeAwareConfig } from './configs/typescriptTypeAware.js';
29
29
  import { unicornConfig } from './configs/unicorn.js';
30
- import { eslintExts, prettierExts } from './lib.js';
30
+ import { asOptions, eslintExts, prettierExts } from './lib.js';
31
31
 
32
32
  export * from './configs/base.js';
33
33
  export * from './configs/imports.js';
34
- export * from './configs/next.js';
34
+ export * from './configs/react.js';
35
35
  export * from './configs/nx.js';
36
36
  export * from './configs/prettier.js';
37
37
  export * from './configs/promise.js';
@@ -82,23 +82,30 @@ export async function defineLintConfig(options = {}) {
82
82
  if (typeof options === 'function') options = options();
83
83
  options = (await options) ?? {};
84
84
 
85
+ /*
86
+ * `detection` uses the same toggle notation as the tool flags (true <> { enabled: true } <>
87
+ * false <> { enabled: false }): `enabled` = are tools ON unless said otherwise (default true),
88
+ * `strict` = same-scope package probes only, no workspace evidence scans (default false;
89
+ * ideal for per-package monorepo configs).
90
+ */
91
+ const { enabled: defaultOn = true, strict = false } = asOptions(options.detection);
92
+ // with detection off, tools not mentioned explicitly are OFF instead of auto-detected
93
+ const flag = (option) => (option === undefined && !defaultOn ? false : option);
94
+
85
95
  // blocks from the same configs/* file stay consecutive - ordering inside a family matters
86
96
  // (e.g. next: base config, then the TS wiring stemming from it, then overrides, then settings)
87
97
  return [
88
98
  // base.js
89
99
  ...baseConfig(),
90
100
  ...defaultIgnoreConfig(options.defaultIgnore),
91
- // next.js
92
- ...(await nextConfig(options.next)),
93
- ...typescriptOverridesConfig(),
94
- ...nextOverridesConfig(),
95
- ...reactSettingsConfig(),
101
+ // react.js - the whole family (Next or plain React + TS wiring + overrides + settings)
102
+ ...(await reactConfig(flag(options.next), strict)),
96
103
  // prettier.js
97
104
  ...prettierConfig(),
98
105
  // storybook.js
99
- ...(await storybookConfig(options.storybook)),
106
+ ...(await storybookConfig(flag(options.storybook), strict)),
100
107
  // typescriptTypeAware (should be before imports)
101
- ...typeAwareConfig(options.typeAware),
108
+ ...typeAwareConfig(options.typeAware, strict),
102
109
  // imports.js
103
110
  ...importXConfig(),
104
111
  ...importSortConfig(),
@@ -108,14 +115,14 @@ export async function defineLintConfig(options = {}) {
108
115
  // unicorn.js
109
116
  ...unicornConfig(),
110
117
  // turbo.js
111
- ...(await turboConfig(options.turbo)),
118
+ ...(await turboConfig(flag(options.turbo))),
112
119
  // tailwind.js
113
- ...(await tailwindConfig(options.tailwind)),
120
+ ...(await tailwindConfig(flag(options.tailwind), strict)),
114
121
  // nx.js
115
- ...(await nxConfig(options.nx)),
122
+ ...(await nxConfig(flag(options.nx), strict)),
116
123
  // testing.js
117
- ...jestConfig(options.jest),
118
- ...vitestConfig(options.vitest),
124
+ ...jestConfig(flag(options.jest), strict),
125
+ ...vitestConfig(flag(options.vitest), strict),
119
126
  ...testConfig(),
120
127
  ];
121
128
  }