@kirill.konshin/lint 0.3.6 → 0.4.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.
Files changed (58) hide show
  1. package/README.md +137 -57
  2. package/dist/configs/base.d.ts +29 -0
  3. package/dist/configs/base.d.ts.map +1 -0
  4. package/{configs → dist/configs}/base.js +7 -25
  5. package/dist/configs/imports.d.ts +21 -0
  6. package/dist/configs/imports.d.ts.map +1 -0
  7. package/{configs → dist/configs}/imports.js +0 -10
  8. package/dist/configs/nx.d.ts +16 -0
  9. package/dist/configs/nx.d.ts.map +1 -0
  10. package/{configs → dist/configs}/nx.js +3 -8
  11. package/dist/configs/prettier.d.ts +17 -0
  12. package/dist/configs/prettier.d.ts.map +1 -0
  13. package/{configs → dist/configs}/prettier.js +0 -3
  14. package/dist/configs/promise.d.ts +6 -0
  15. package/dist/configs/promise.d.ts.map +1 -0
  16. package/{configs → dist/configs}/promise.js +0 -3
  17. package/dist/configs/react.d.ts +84 -0
  18. package/dist/configs/react.d.ts.map +1 -0
  19. package/{configs → dist/configs}/react.js +14 -41
  20. package/dist/configs/storybook.d.ts +14 -0
  21. package/dist/configs/storybook.d.ts.map +1 -0
  22. package/{configs → dist/configs}/storybook.js +3 -6
  23. package/dist/configs/tailwind.d.ts +29 -0
  24. package/dist/configs/tailwind.d.ts.map +1 -0
  25. package/{configs → dist/configs}/tailwind.js +9 -24
  26. package/dist/configs/testing.d.ts +22 -0
  27. package/dist/configs/testing.d.ts.map +1 -0
  28. package/{configs → dist/configs}/testing.js +11 -25
  29. package/dist/configs/turbo.d.ts +9 -0
  30. package/dist/configs/turbo.d.ts.map +1 -0
  31. package/{configs → dist/configs}/turbo.js +6 -6
  32. package/dist/configs/typescriptTypeAware.d.ts +20 -0
  33. package/dist/configs/typescriptTypeAware.d.ts.map +1 -0
  34. package/{configs → dist/configs}/typescriptTypeAware.js +10 -23
  35. package/dist/configs/unicorn.d.ts +10 -0
  36. package/dist/configs/unicorn.d.ts.map +1 -0
  37. package/{configs → dist/configs}/unicorn.js +0 -4
  38. package/dist/index.d.ts +80 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/{index.js → dist/index.js} +5 -54
  41. package/dist/lib.d.ts +116 -0
  42. package/dist/lib.d.ts.map +1 -0
  43. package/{lib.js → dist/lib.js} +69 -145
  44. package/dist/lintPrepare.d.ts +105 -0
  45. package/dist/lintPrepare.d.ts.map +1 -0
  46. package/{lintPrepare.js → dist/lintPrepare.js} +11 -65
  47. package/dist/yarn.cjs +117 -0
  48. package/dist/yarn.d.cts +8 -0
  49. package/dist/yarn.d.cts.map +1 -0
  50. package/package.json +42 -34
  51. package/rules/code-style.md +2 -0
  52. package/rules/mui.md +1 -1
  53. package/rules/nextjs.md +1 -1
  54. package/rules/npm-yarn.md +36 -6
  55. package/rules/nx.md +6 -6
  56. package/rules/typescript.md +13 -7
  57. package/rules/webstorm.md +20 -0
  58. package/index.d.ts +0 -281
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescriptTypeAware.d.ts","sourceRoot":"","sources":["../../src/configs/typescriptTypeAware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,gBAAgB,EAAE,MAAM,UAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,CAqFpG"}
@@ -1,9 +1,5 @@
1
1
  import { isAbsolute, relative } from 'node:path';
2
-
3
2
  import { asOptions, findWorkspaceRoot } from '../lib.js';
4
-
5
- /** @typedef {import('../index.js').TypeAwareOptions} TypeAwareOptions Defined in index.d.ts. */
6
-
7
3
  /**
8
4
  * Type-aware rules. Off by default (FIXME: does not perform) - enable via
9
5
  * `defineLintConfig({ typeAware: true })` or by composing this block manually; it is self-contained
@@ -18,28 +14,20 @@ import { asOptions, findWorkspaceRoot } from '../lib.js';
18
14
  * `allowDefaultProject` when that list is given (upstream default is 8), and `tsconfigRootDir`
19
15
  * defaults to the detected workspace root.
20
16
  *
21
- * @param {boolean | TypeAwareOptions} [option] the defineLintConfig `typeAware` flag; there is
22
- * nothing to auto-detect, so only an explicit `true` / options object enables the block
23
- * @returns {import('eslint').Linter.Config[]}
17
+ * There is nothing to auto-detect, so only an explicit `true` or options object enables the block.
24
18
  */
25
19
  export function typeAwareConfig(option, strict = false) {
26
- let {
27
- enabled = false,
28
- allowDefaultProject,
29
- // matches the list when it's exact files (the scanWorkspace flow); with multi-match globs
30
- // set the cap explicitly - typescript-eslint errors loudly when matches exceed it
31
- maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING = allowDefaultProject?.length,
32
- // strict detection avoids the workspace walk
33
- tsconfigRootDir = strict ? process.cwd() : findWorkspaceRoot(),
34
- } = asOptions(option);
35
- if (!enabled) return [];
36
-
20
+ const { enabled = false, allowDefaultProject: configuredDefaultProject,
21
+ // matches the list when it's exact files (the scanWorkspace flow); with multi-match globs
22
+ // set the cap explicitly - typescript-eslint errors loudly when matches exceed it
23
+ maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING = configuredDefaultProject?.length,
24
+ // strict detection avoids the workspace walk
25
+ tsconfigRootDir = strict ? process.cwd() : findWorkspaceRoot(), } = asOptions(option);
26
+ if (!enabled)
27
+ return [];
37
28
  // typescript-eslint requires allowDefaultProject globs to be RELATIVE to tsconfigRootDir -
38
29
  // absolute entries (e.g. produced by scanWorkspace, see README) are relativized automatically
39
- allowDefaultProject = allowDefaultProject?.map((file) =>
40
- isAbsolute(file) ? relative(tsconfigRootDir, file) : file,
41
- );
42
-
30
+ const allowDefaultProject = configuredDefaultProject?.map((file) => isAbsolute(file) ? relative(tsconfigRootDir, file) : file);
43
31
  return [
44
32
  {
45
33
  name: 'Type-aware rules (separate for performance)',
@@ -58,7 +46,6 @@ export function typeAwareConfig(option, strict = false) {
58
46
  rules: {
59
47
  '@typescript-eslint/prefer-optional-chain': 'warn',
60
48
  '@typescript-eslint/prefer-nullish-coalescing': 'warn',
61
-
62
49
  /**
63
50
  * https://typescript-eslint.io/rules/naming-convention/
64
51
  *
@@ -0,0 +1,10 @@
1
+ import type { Linter } from 'eslint';
2
+ /**
3
+ * Filename casing + node: protocol.
4
+ *
5
+ * Deliberately NOT using unicorn.configs['flat/recommended'] - it's 337 rules (it even folds in
6
+ * a few unprefixed core-ESLint rules), extremely opinionated, and far beyond what was asked for.
7
+ * Only the two rules below are actually wanted.
8
+ */
9
+ export declare function unicornConfig(): Linter.Config[];
10
+ //# sourceMappingURL=unicorn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unicorn.d.ts","sourceRoot":"","sources":["../../src/configs/unicorn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKrC;;;;;;GAMG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,CAiC/C"}
@@ -1,15 +1,11 @@
1
1
  import unicornPlugin from 'eslint-plugin-unicorn';
2
-
3
2
  import { tsExts } from '../lib.js';
4
-
5
3
  /**
6
4
  * Filename casing + node: protocol.
7
5
  *
8
6
  * Deliberately NOT using unicorn.configs['flat/recommended'] - it's 337 rules (it even folds in
9
7
  * a few unprefixed core-ESLint rules), extremely opinionated, and far beyond what was asked for.
10
8
  * Only the two rules below are actually wanted.
11
- *
12
- * @returns {import('eslint').Linter.Config[]}
13
9
  */
14
10
  export function unicornConfig() {
15
11
  return [
@@ -0,0 +1,80 @@
1
+ import type { ParserOptions as TsParserOptions } from '@typescript-eslint/parser';
2
+ import type { Linter } from 'eslint';
3
+ import type { PluginSettings as TailwindPluginSettings } from 'eslint-plugin-tailwindcss';
4
+ import type { Configuration as LintStagedConfiguration } from 'lint-staged';
5
+ import type { Config as PrettierConfig } from 'prettier';
6
+ export * from './configs/base.js';
7
+ export * from './configs/imports.js';
8
+ export * from './configs/react.js';
9
+ export * from './configs/nx.js';
10
+ export * from './configs/prettier.js';
11
+ export * from './configs/promise.js';
12
+ export * from './configs/storybook.js';
13
+ export * from './configs/tailwind.js';
14
+ export * from './configs/testing.js';
15
+ export * from './configs/turbo.js';
16
+ export * from './configs/typescriptTypeAware.js';
17
+ export * from './configs/unicorn.js';
18
+ export * from './lib.js';
19
+ type ProjectServiceOptions = Exclude<NonNullable<TsParserOptions['projectService']>, boolean>;
20
+ export type ToggleOptions = {
21
+ enabled?: boolean;
22
+ };
23
+ export type DetectionOptions = ToggleOptions & {
24
+ strict?: boolean;
25
+ };
26
+ export type NextOptions = ToggleOptions & {
27
+ rootDir?: string | string[];
28
+ };
29
+ export type TailwindOptions = ToggleOptions & {
30
+ cssConfigPath?: TailwindPluginSettings['cssConfigPath'];
31
+ scoped?: boolean;
32
+ };
33
+ export type TypeAwareOptions = ToggleOptions & Pick<ProjectServiceOptions, 'allowDefaultProject' | 'maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING'> & {
34
+ tsconfigRootDir?: TsParserOptions['tsconfigRootDir'];
35
+ };
36
+ export type DefaultIgnoreOptions = {
37
+ enabled: false;
38
+ importMetaUrl?: string;
39
+ } | {
40
+ enabled?: true;
41
+ importMetaUrl: string;
42
+ };
43
+ export type LintOptions = {
44
+ detection?: boolean | DetectionOptions;
45
+ next?: boolean | NextOptions;
46
+ storybook?: boolean | ToggleOptions;
47
+ turbo?: boolean | ToggleOptions;
48
+ nx?: boolean | ToggleOptions;
49
+ jest?: boolean | ToggleOptions;
50
+ vitest?: boolean | ToggleOptions;
51
+ tailwind?: boolean | TailwindOptions;
52
+ typeAware?: boolean | TypeAwareOptions;
53
+ defaultIgnore?: boolean | DefaultIgnoreOptions;
54
+ };
55
+ /**
56
+ * Build the shared flat ESLint config.
57
+ *
58
+ * By default every tool integration is auto-detected (see the `has*` exports); pass
59
+ * {@link LintOptions} to force any of them on/off or to supply tool-specific settings.
60
+ *
61
+ * Returns a Promise - ESLint natively awaits a Promise default export, so a plain
62
+ * `export default defineLintConfig({...})` works; `await` it only when composing with extra blocks.
63
+ *
64
+ */
65
+ export declare function defineLintConfig(options?: LintOptions | Promise<LintOptions> | (() => LintOptions | Promise<LintOptions>)): Promise<Linter.Config[]>;
66
+ export declare const prettier: PrettierConfig;
67
+ /**
68
+ * https://nextjs.org/docs/app/api-reference/config/eslint#running-lint-on-staged-files
69
+ *
70
+ * Pay extra attention when the configured globs overlap, and tasks make edits to files. Prettier and eslint might try
71
+ * to make changes to the same *.ts file at the same time, causing a race condition.
72
+ *
73
+ * https://github.com/lint-staged/lint-staged?tab=readme-ov-file#reformatting-the-code
74
+ * https://github.com/lint-staged/lint-staged/issues/775
75
+ * You don't need git add since lint-staged 10
76
+ *
77
+ * TODO Screw yarn, just use eslint directly? Yarn gives greater control over what is in the console...
78
+ */
79
+ export declare const listStaged: LintStagedConfiguration;
80
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAClF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,cAAc,IAAI,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAC1F,OAAO,KAAK,EAAE,aAAa,IAAI,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,UAAU,CAAC;AAgBzD,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAw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G,aAAa,CAAC;IACpC,KAAK,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IAChC,EAAE,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IAC7B,IAAI,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IAC/B,MAAM,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IACjC,QAAQ,CAAC,EAAE,OAAO,GAAG,eAAe,CAAC;IACrC,SAAS,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC;IACvC,aAAa,CAAC,EAAE,OAAO,GAAG,oBAAoB,CAAC;CAClD,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CAClC,OAAO,GAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAM,GAC9F,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAgD1B;AAED,eAAO,MAAM,QAAQ,EAAE,cAatB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,EAAE,uBAGxB,CAAC"}
@@ -1,20 +1,3 @@
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"). Types live in the hand-written `index.d.ts` next to this file, which
5
- * pulls real types from the underlying packages; the option types (LintOptions, NextOptions,
6
- * TailwindOptions) are defined ONLY there and referenced from JSDoc via import() aliases - keep
7
- * the function signatures in sync with the JSDoc here.
8
- *
9
- * The config is built by `defineLintConfig(options)`, which is pure ordering: every block lives in a
10
- * themed `configs/*.js` file as an exported `*Config()` function, and the tool-gated ones take
11
- * their own defineLintConfig flag (`undefined` auto-detect / `true` or options force on / `false` off)
12
- * and gate themselves - see the detection block in lib.js for why forcing exists. Tool-gated
13
- * plugins are imported
14
- * lazily inside their block functions so consumers without the tool don't pay their load cost;
15
- * the plugin re-exports below follow module-load DETECTION (not defineLintConfig options, which they
16
- * cannot see) and are null when the tool wasn't detected.
17
- */
18
1
  import { baseConfig, defaultIgnoreConfig } from './configs/base.js';
19
2
  import { importSortConfig, importXConfig, unusedImportsConfig } from './configs/imports.js';
20
3
  import { nxConfig } from './configs/nx.js';
@@ -28,7 +11,6 @@ import { turboConfig } from './configs/turbo.js';
28
11
  import { typeAwareConfig } from './configs/typescriptTypeAware.js';
29
12
  import { unicornConfig } from './configs/unicorn.js';
30
13
  import { asOptions, eslintExts, prettierExts } from './lib.js';
31
-
32
14
  export * from './configs/base.js';
33
15
  export * from './configs/imports.js';
34
16
  export * from './configs/react.js';
@@ -41,31 +23,7 @@ export * from './configs/testing.js';
41
23
  export * from './configs/turbo.js';
42
24
  export * from './configs/typescriptTypeAware.js';
43
25
  export * from './configs/unicorn.js';
44
-
45
- // deliberately NOT the whole lib.js - asOptions/GLOBAL_IGNORES and the fs helpers stay internal
46
- export {
47
- // extensions
48
- tsExts,
49
- tsExtsRaw,
50
- eslintExts,
51
- eslintExtsRaw,
52
- prettierExts,
53
- prettierExtsRaw,
54
- // detection
55
- findWorkspaceRoot,
56
- scanWorkspace,
57
- hasJest,
58
- hasNext,
59
- hasNx,
60
- hasStorybook,
61
- hasTailwind,
62
- hasTurbo,
63
- hasVite,
64
- hasVitest,
65
- } from './lib.js';
66
-
67
- /** @typedef {import('./index.js').LintOptions} LintOptions Per-tool toggles - defined once in index.d.ts (resolved via the sibling declaration file), backed by real upstream types. */
68
-
26
+ export * from './lib.js';
69
27
  /**
70
28
  * Build the shared flat ESLint config.
71
29
  *
@@ -75,13 +33,11 @@ export {
75
33
  * Returns a Promise - ESLint natively awaits a Promise default export, so a plain
76
34
  * `export default defineLintConfig({...})` works; `await` it only when composing with extra blocks.
77
35
  *
78
- * @param {LintOptions | Promise<LintOptions> | (() => LintOptions | Promise<LintOptions>)} [options]
79
- * @returns {Promise<import('eslint').Linter.Config[]>}
80
36
  */
81
37
  export async function defineLintConfig(options = {}) {
82
- if (typeof options === 'function') options = options();
38
+ if (typeof options === 'function')
39
+ options = options();
83
40
  options = (await options) ?? {};
84
-
85
41
  /*
86
42
  * `detection` uses the same toggle notation as the tool flags (true <> { enabled: true } <>
87
43
  * false <> { enabled: false }): `enabled` = are tools ON unless said otherwise (default true),
@@ -90,8 +46,7 @@ export async function defineLintConfig(options = {}) {
90
46
  */
91
47
  const { enabled: defaultOn = true, strict = false } = asOptions(options.detection);
92
48
  // with detection off, tools not mentioned explicitly are OFF instead of auto-detected
93
- const flag = (option) => (option === undefined && !defaultOn ? false : option);
94
-
49
+ const flag = (option) => option === undefined && !defaultOn ? false : option;
95
50
  // blocks from the same configs/* file stay consecutive - ordering inside a family matters
96
51
  // (e.g. next: base config, then the TS wiring stemming from it, then overrides, then settings)
97
52
  return [
@@ -126,12 +81,11 @@ export async function defineLintConfig(options = {}) {
126
81
  ...testConfig(),
127
82
  ];
128
83
  }
129
-
130
- /** @type {import('prettier').Config} */
131
84
  export const prettier = {
132
85
  printWidth: 120,
133
86
  tabWidth: 2,
134
87
  singleQuote: true,
88
+ proseWrap: 'never',
135
89
  overrides: [
136
90
  {
137
91
  files: eslintExts,
@@ -141,7 +95,6 @@ export const prettier = {
141
95
  },
142
96
  ],
143
97
  };
144
-
145
98
  /**
146
99
  * https://nextjs.org/docs/app/api-reference/config/eslint#running-lint-on-staged-files
147
100
  *
@@ -153,8 +106,6 @@ export const prettier = {
153
106
  * You don't need git add since lint-staged 10
154
107
  *
155
108
  * TODO Screw yarn, just use eslint directly? Yarn gives greater control over what is in the console...
156
- *
157
- * @type {import('lint-staged').Configuration}
158
109
  */
159
110
  export const listStaged = {
160
111
  [prettierExts]: ['yarn prettier'],
package/dist/lib.d.ts ADDED
@@ -0,0 +1,116 @@
1
+ import type { ToggleOptions } from './index.js';
2
+ type NormalizedOptions<T extends ToggleOptions> = Omit<T, 'enabled'>;
3
+ type ToolGateSpec<T extends ToggleOptions> = {
4
+ tool: string;
5
+ has: boolean;
6
+ strictHas?: boolean;
7
+ packageName?: string;
8
+ requirePackage?: boolean;
9
+ absolutizeOptions?: (options: NormalizedOptions<T>) => string[];
10
+ scan?: () => string[];
11
+ allowMultiple?: boolean;
12
+ needs?: {
13
+ what: string;
14
+ detail: string;
15
+ hint: string;
16
+ };
17
+ };
18
+ type ToolGateResult<T extends ToggleOptions> = {
19
+ enabled: boolean;
20
+ options: NormalizedOptions<T>;
21
+ files: string[];
22
+ };
23
+ export declare const tsExtsRaw = "js,jsx,ts,tsx,cjs,cts,mjs,mts";
24
+ export declare const eslintExtsRaw = "js,jsx,ts,tsx,cjs,cts,mjs,mts,md,mdx,htm,html,vue";
25
+ export declare const prettierExtsRaw = "css,scss,sass,less,yml,yaml,json,json5,jsonc,graphql,graphqls,xml";
26
+ export declare const tsExts = "{js,jsx,ts,tsx,cjs,cts,mjs,mts}";
27
+ export declare const eslintExts = "*.{js,jsx,ts,tsx,cjs,cts,mjs,mts,md,mdx,htm,html,vue}";
28
+ export declare const prettierExts = "*.{css,scss,sass,less,yml,yaml,json,json5,jsonc,graphql,graphqls,xml}";
29
+ export declare const GLOBAL_IGNORES: string[];
30
+ /**
31
+ * Capability gate: is a package resolvable from the workspace root - the scope the ESLint plugins
32
+ * themselves resolve from at lint time?
33
+ */
34
+ export declare function isPackageResolvable(packageName: string): boolean;
35
+ /**
36
+ * Workspace root of the consumer project - the anchor for every config-file scan (Tailwind entry,
37
+ * `next.config.*`) and root-file detection (`nx.json`): `process.cwd()` alone is unreliable
38
+ * because lint often runs from INSIDE a package (lint-staged, IDE, `yarn workspace x lint`) while
39
+ * the shared config must see the whole repo.
40
+ *
41
+ * Resolution order, cheapest first - an env candidate must contain `cwd` or it is rejected:
42
+ * 1. env the package manager sets for its child processes: `PROJECT_CWD` (Yarn Berry),
43
+ * `npm_config_local_prefix` (npm >= 7, workspace-aware) - free, no fs walk at all
44
+ * 2. `@manypkg/find-root`: walks up to the nearest workspace manifest (package.json `workspaces`,
45
+ * pnpm-workspace.yaml, lerna.json, rush.json, bun), falling back to the nearest `package.json`
46
+ * for single-package repos - covers every manager, incl. the env-less ones (pnpm, Yarn 1)
47
+ *
48
+ * Cached per `cwd` - the config is rebuilt on every lint run.
49
+ *
50
+ * Returns an absolute path, or `cwd` itself when there is no package.json anywhere above.
51
+ */
52
+ export declare function findWorkspaceRoot(cwd?: string): string;
53
+ /**
54
+ * The workspace package owning `file` (e.g. the Tailwind entry CSS) - matched against the real
55
+ * workspace package dirs (see {@link findWorkspacePackages}), NOT by walking to the nearest
56
+ * package.json: a directory that is not a declared workspace member belongs to the root. Returns
57
+ * the workspace root when no package contains `file`.
58
+ *
59
+ */
60
+ export declare function packageDirOf(file: string): string;
61
+ /**
62
+ * Glob for config-file candidates across the workspace: the root directory plus every workspace
63
+ * package (the real `workspaces` globs via {@link findWorkspacePackages}, not a depth heuristic),
64
+ * skipping dot dirs, build outputs, the given ignore patterns and everything in the root
65
+ * `.gitignore`. Anchored to {@link findWorkspaceRoot}, NOT cwd.
66
+ *
67
+ * Public - useful for building consumer file lists (e.g. `typeAware.allowDefaultProject`, see README "Type-aware rules").
68
+ *
69
+ * `dot` also scans dot directories such as `.storybook`.
70
+ */
71
+ export declare function scanWorkspace(fileGlob: string, ignores?: string[], { dot }?: {
72
+ dot?: boolean;
73
+ }): string[];
74
+ export declare const hasNext: boolean;
75
+ export declare const hasStorybook: boolean;
76
+ export declare const hasVite: boolean;
77
+ export declare const hasJest: boolean;
78
+ export declare const hasVitest: boolean;
79
+ export declare const hasTurbo: boolean;
80
+ export declare const hasNx: boolean;
81
+ export declare const hasTailwind: boolean;
82
+ /**
83
+ * Normalize a defineLintConfig flag into its options object with a canonical `enabled`:
84
+ * - `true` / `false` → `{ enabled: true | false }`
85
+ * - an options object counts as enabled unless it explicitly says otherwise - `enabled` defaults
86
+ * to `true`, so providing options (even `{}`) implies turning the tool on
87
+ * - `undefined` (flag not passed) → `{}` - `enabled` stays undefined and the caller falls back to
88
+ * detection: `const { enabled = hasX, ...options } = asOptions(option)`
89
+ *
90
+ */
91
+ export declare function asOptions<T extends ToggleOptions>(option: boolean | T | null | undefined): NormalizedOptions<T> & {
92
+ enabled?: boolean;
93
+ };
94
+ /**
95
+ * Shared activation gate of the tool-scoped config blocks (next, storybook, turbo, nx, jest,
96
+ * vitest, tailwind) - the one decision every block repeats: is the tool ON, and can its plugin
97
+ * actually run. The `configs/*.ts` functions keep only their tool-specific parts (which blocks to
98
+ * emit, how the evidence feeds settings) and differ solely in the spec they pass here.
99
+ *
100
+ * Decision flow:
101
+ * - `enabled: false` → off, always.
102
+ * - strict (defineLintConfig `detection.strict`): the same-scope probe gates (`strictHas`,
103
+ * defaulting to `has`); `scan` never runs, but `absolutizeOptions` evidence still counts. A tool
104
+ * that is ON while its package is unresolvable (`requirePackage`) or its mandatory evidence is
105
+ * missing (`needs`) throws instead of producing a config that crashes at lint time.
106
+ * - non-strict: evidence-based detection - `absolutizeOptions(options)` wins over the `scan()`
107
+ * auto-discovery; the tool is detected when the package probe hits or evidence exists (`needs`
108
+ * makes evidence mandatory even when the probe hits). A tool that is ON while `packageName` is
109
+ * unresolvable from the workspace root throws an actionable HOISTING error (no silent skip, no
110
+ * symlink bridging - the plugins resolve from the root scope, so only hoisting actually fixes
111
+ * them; the user or their AI agent picks it up from the error).
112
+ *
113
+ */
114
+ export declare function toolGate<T extends ToggleOptions>(option: boolean | T | undefined, strict: boolean, spec: ToolGateSpec<T>): ToolGateResult<T>;
115
+ export {};
116
+ //# sourceMappingURL=lib.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,KAAK,iBAAiB,CAAC,CAAC,SAAS,aAAa,IAAI,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;AAErE,KAAK,YAAY,CAAC,CAAC,SAAS,aAAa,IAAI;IACzC,IAA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