@kirill.konshin/lint 0.2.0 → 0.3.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/README.md +127 -31
- package/configs/base.js +98 -0
- package/configs/imports.js +162 -0
- package/configs/next.js +179 -0
- package/configs/nx.js +40 -0
- package/configs/prettier.js +21 -0
- package/configs/promise.js +21 -0
- package/configs/storybook.js +15 -0
- package/configs/tailwind.js +72 -0
- package/configs/testing.js +136 -0
- package/configs/turbo.js +29 -0
- package/configs/typescriptTypeAware.js +109 -0
- package/configs/unicorn.js +47 -0
- package/index.d.ts +241 -0
- package/index.js +114 -612
- package/lib.js +212 -14
- package/package.json +10 -4
- package/rules/tailwind.md +8 -13
- package/rules/testing.md +5 -4
- package/skills/lint-repo.md +2 -2
- package/findTailwindEntry.js +0 -46
- package/ruleTestColocation.js +0 -50
package/index.d.ts
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hand-written declarations for the raw-JS package (see README "Why raw JS" - there is no build to
|
|
3
|
+
* emit them from). Keep in sync with index.js / configs/*.js and their JSDoc.
|
|
4
|
+
*
|
|
5
|
+
* Types are pulled from the real underlying packages wherever they export them (eslint's
|
|
6
|
+
* `Linter.Config`, eslint-plugin-tailwindcss's `PluginSettings`, prettier's `Config`,
|
|
7
|
+
* lint-staged's `Configuration`, the plugins' own default-export types), so the options here stay
|
|
8
|
+
* in sync with how the tools themselves define their configs. `@next/eslint-plugin-next` exports
|
|
9
|
+
* no settings type - `NextOptions.rootDir` mirrors its documented `settings.next.rootDir` schema.
|
|
10
|
+
*/
|
|
11
|
+
import type { ParserOptions as TsParserOptions } from '@typescript-eslint/parser';
|
|
12
|
+
import type { Linter } from 'eslint';
|
|
13
|
+
import type { PluginSettings as TailwindPluginSettings } from 'eslint-plugin-tailwindcss';
|
|
14
|
+
import type { Configuration as LintStagedConfiguration } from 'lint-staged';
|
|
15
|
+
import type { Config as PrettierConfig } from 'prettier';
|
|
16
|
+
|
|
17
|
+
type ProjectServiceOptions = Exclude<NonNullable<TsParserOptions['projectService']>, boolean>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Base shape of every tool's options object. Using the object form implies the tool is ON -
|
|
21
|
+
* `enabled` defaults to `true`, so a partially configured tool doesn't also need a separate
|
|
22
|
+
* `true` anywhere; set `enabled: false` to force it off while keeping the other options in place.
|
|
23
|
+
*/
|
|
24
|
+
export type ToggleOptions = {
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Options for the Next.js blocks ({@link nextBaseConfig}). */
|
|
29
|
+
export type NextOptions = ToggleOptions & {
|
|
30
|
+
/**
|
|
31
|
+
* Root of the Next.js app(s) for `@next/eslint-plugin-next` (`settings.next.rootDir`) - needed
|
|
32
|
+
* 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.
|
|
35
|
+
*
|
|
36
|
+
* @see https://nextjs.org/docs/app/api-reference/config/eslint
|
|
37
|
+
*/
|
|
38
|
+
rootDir?: string | string[];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** Options for the Tailwind block ({@link tailwindConfig}). */
|
|
42
|
+
export type TailwindOptions = ToggleOptions & {
|
|
43
|
+
/**
|
|
44
|
+
* Tailwind v4 entry CSS for `eslint-plugin-tailwindcss` (`settings.tailwindcss.cssConfigPath`),
|
|
45
|
+
* absolute or relative to the lint working directory. When omitted, auto-detected via
|
|
46
|
+
* {@link findTailwindEntry}.
|
|
47
|
+
*/
|
|
48
|
+
cssConfigPath?: TailwindPluginSettings['cssConfigPath'];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Options for the type-aware block ({@link typeAwareConfig}). `allowDefaultProject` and
|
|
53
|
+
* `maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING` are typescript-eslint's own
|
|
54
|
+
* `projectService` options (real types). `allowDefaultProject` has NO default - generate the file
|
|
55
|
+
* list with {@link scanWorkspace} (absolute entries are relativized against `tsconfigRootDir`
|
|
56
|
+
* automatically); the match cap defaults to that list's length when it is given (set it explicitly
|
|
57
|
+
* when using multi-match globs); `tsconfigRootDir` defaults to the detected workspace root.
|
|
58
|
+
*/
|
|
59
|
+
export type TypeAwareOptions = ToggleOptions &
|
|
60
|
+
Pick<
|
|
61
|
+
ProjectServiceOptions,
|
|
62
|
+
'allowDefaultProject' | 'maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING'
|
|
63
|
+
> & {
|
|
64
|
+
/** Defaults to {@link findWorkspaceRoot}. */
|
|
65
|
+
tsconfigRootDir?: TsParserOptions['tsconfigRootDir'];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** Options for the default-ignore block ({@link defaultIgnoreConfig}). */
|
|
69
|
+
export type DefaultIgnoreOptions = ToggleOptions & {
|
|
70
|
+
/**
|
|
71
|
+
* `import.meta.url` of the consumer's `eslint.config.mjs` - the `.gitignore` and
|
|
72
|
+
* `.prettierignore` files are resolved next to it. Required: the config file location cannot
|
|
73
|
+
* be auto-detected.
|
|
74
|
+
*/
|
|
75
|
+
importMetaUrl: string;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Per-tool toggles for {@link defineLintConfig}. Every flag is optional:
|
|
80
|
+
* - `undefined` (default) - auto-detect via the corresponding `has*` export
|
|
81
|
+
* - `true` or an options object - force the tool's blocks ON (use when detection misses a tool
|
|
82
|
+
* that lives only in leaf packages of a monorepo); in the object form `enabled` defaults to
|
|
83
|
+
* `true` and can be set to `false` to force OFF while keeping the other options in place
|
|
84
|
+
* - `false` - force OFF
|
|
85
|
+
*
|
|
86
|
+
* The gated `*Config()` block functions accept the same flag value directly.
|
|
87
|
+
*/
|
|
88
|
+
export type LintOptions = {
|
|
89
|
+
/** Next.js (`eslint-config-next`); when off, generic React/JSX rules apply instead */
|
|
90
|
+
next?: boolean | NextOptions;
|
|
91
|
+
/** Storybook (`eslint-plugin-storybook`) */
|
|
92
|
+
storybook?: boolean | ToggleOptions;
|
|
93
|
+
/** Turborepo (`eslint-plugin-turbo`) */
|
|
94
|
+
turbo?: boolean | ToggleOptions;
|
|
95
|
+
/** Nx (`@nx/eslint-plugin` base + `@nx/dependency-checks`) */
|
|
96
|
+
nx?: boolean | ToggleOptions;
|
|
97
|
+
/** Jest recommended rules for `*.{test,spec}.*` */
|
|
98
|
+
jest?: boolean | ToggleOptions;
|
|
99
|
+
/** Vitest recommended rules for `*.{test,spec}.*` */
|
|
100
|
+
vitest?: boolean | ToggleOptions;
|
|
101
|
+
/** Tailwind (`eslint-plugin-tailwindcss`); forcing ON without a resolvable entry CSS is a hard error */
|
|
102
|
+
tailwind?: boolean | TailwindOptions;
|
|
103
|
+
/** Type-aware TypeScript rules; off by default (slow), nothing to auto-detect */
|
|
104
|
+
typeAware?: boolean | TypeAwareOptions;
|
|
105
|
+
/** `.gitignore` + `.prettierignore` as ESLint ignores; off by default, `true` without `importMetaUrl` is a hard error */
|
|
106
|
+
defaultIgnore?: boolean | DefaultIgnoreOptions;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Build the shared flat ESLint config. By default every tool integration is auto-detected (see the
|
|
111
|
+
* `has*` exports); pass {@link LintOptions} to force any of them on/off or to supply tool-specific
|
|
112
|
+
* settings. ESLint natively awaits a Promise default export, so a plain
|
|
113
|
+
* `export default defineLintConfig({...})` works; `await` it only when composing with extra blocks.
|
|
114
|
+
*/
|
|
115
|
+
export function defineLintConfig(
|
|
116
|
+
options?: LintOptions | Promise<LintOptions> | (() => LintOptions | Promise<LintOptions>),
|
|
117
|
+
): Promise<Linter.Config[]>;
|
|
118
|
+
|
|
119
|
+
// ----- Blocks (in the order defineLintConfig applies them; from configs/*.js) -----
|
|
120
|
+
// Gated blocks take their LintOptions flag and return [] when resolved off.
|
|
121
|
+
|
|
122
|
+
/** Core JS recommended rules, global ignores, browser + Node globals, and core-rule overrides. */
|
|
123
|
+
export function baseConfig(): Linter.Config[];
|
|
124
|
+
/**
|
|
125
|
+
* `.gitignore` + `.prettierignore` (next to the consumer's config file, both must exist) as
|
|
126
|
+
* ESLint ignores. Off by default; enabling without `importMetaUrl` is a hard error.
|
|
127
|
+
*/
|
|
128
|
+
export function defaultIgnoreConfig(option?: boolean | DefaultIgnoreOptions): Linter.Config[];
|
|
129
|
+
/** The whole `eslint-config-next` flat config, plus `settings.next.rootDir` when given. Next-only, ungated. */
|
|
130
|
+
export function nextBaseConfig(options?: NextOptions): Promise<Linter.Config[]>;
|
|
131
|
+
/** 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[]>;
|
|
135
|
+
/** `eslint-config-next/typescript` (typescript-eslint wiring, which stems from Next) + deliberate rule overrides. */
|
|
136
|
+
export function typescriptOverridesConfig(): Linter.Config[];
|
|
137
|
+
/** Overrides of rules set by `eslint-config-next` (always applied, harmless without Next). */
|
|
138
|
+
export function nextOverridesConfig(): Linter.Config[];
|
|
139
|
+
/** React version settings workaround (ESLint 10 + Next). Always applied. */
|
|
140
|
+
export function reactSettingsConfig(): Linter.Config[];
|
|
141
|
+
/** Prettier compatibility (`eslint-config-prettier/flat`). */
|
|
142
|
+
export function prettierConfig(): Linter.Config[];
|
|
143
|
+
/** Storybook recommended rules. */
|
|
144
|
+
export function storybookConfig(option?: boolean | ToggleOptions): Promise<Linter.Config[]>;
|
|
145
|
+
/** eslint-plugin-import-x recommended rules + overrides + the default-export relaxation for conventional files. */
|
|
146
|
+
export function importXConfig(): Linter.Config[];
|
|
147
|
+
/** Deterministic import ordering (eslint-plugin-simple-import-sort). */
|
|
148
|
+
export function importSortConfig(): Linter.Config[];
|
|
149
|
+
/** Autofixable removal of unused imports. */
|
|
150
|
+
export function unusedImportsConfig(): Linter.Config[];
|
|
151
|
+
/** eslint-plugin-promise recommended rules + overrides. */
|
|
152
|
+
export function promiseConfig(): Linter.Config[];
|
|
153
|
+
/** Filename casing + node: protocol (two hand-picked unicorn rules). */
|
|
154
|
+
export function unicornConfig(): Linter.Config[];
|
|
155
|
+
/** 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[];
|
|
157
|
+
/** Turborepo rules. */
|
|
158
|
+
export function turboConfig(option?: boolean | ToggleOptions): Promise<Linter.Config[]>;
|
|
159
|
+
/**
|
|
160
|
+
* 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.
|
|
163
|
+
*/
|
|
164
|
+
export function tailwindConfig(option?: boolean | TailwindOptions): Promise<Linter.Config[]>;
|
|
165
|
+
/** Nx plugin registration + `@nx/dependency-checks`. */
|
|
166
|
+
export function nxConfig(option?: boolean | ToggleOptions): Promise<Linter.Config[]>;
|
|
167
|
+
/** Jest recommended rules, scoped to test files. */
|
|
168
|
+
export function jestConfig(option?: boolean | ToggleOptions): Linter.Config[];
|
|
169
|
+
/** Vitest recommended rules + globals, scoped to test files. */
|
|
170
|
+
export function vitestConfig(option?: boolean | ToggleOptions): Linter.Config[];
|
|
171
|
+
/** Runner-agnostic test rules (consistent-test-it, test colocation). Always applied. */
|
|
172
|
+
export function testConfig(): Linter.Config[];
|
|
173
|
+
|
|
174
|
+
// ----- Detection (module-load time capability probes, exported for debugging; from lib.js) -----
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Workspace root of the consumer project - the anchor for every config-file scan and for `nx.json`
|
|
178
|
+
* detection. Resolved from the package manager (env: Yarn Berry `PROJECT_CWD` / npm
|
|
179
|
+
* `npm_config_local_prefix`; CLIs: `pnpm root -w`, Yarn Berry via `yarn node`, `npm prefix`),
|
|
180
|
+
* falling back to a lockfile walk bounded by `.git`; every candidate must contain `cwd`.
|
|
181
|
+
* Cached per `cwd`.
|
|
182
|
+
*/
|
|
183
|
+
export function findWorkspaceRoot(cwd?: string): string;
|
|
184
|
+
|
|
185
|
+
export const hasNext: boolean;
|
|
186
|
+
export const hasStorybook: boolean;
|
|
187
|
+
export const hasVite: boolean;
|
|
188
|
+
export const hasJest: boolean;
|
|
189
|
+
export const hasVitest: boolean;
|
|
190
|
+
export const hasTurbo: boolean;
|
|
191
|
+
export const hasNx: boolean;
|
|
192
|
+
export const hasTailwind: boolean;
|
|
193
|
+
|
|
194
|
+
// ----- Extension lists (from lib.js) -----
|
|
195
|
+
|
|
196
|
+
export const tsExtsRaw: string;
|
|
197
|
+
export const eslintExtsRaw: string;
|
|
198
|
+
export const prettierExtsRaw: string;
|
|
199
|
+
export const tsExts: string;
|
|
200
|
+
export const eslintExts: string;
|
|
201
|
+
export const prettierExts: string;
|
|
202
|
+
|
|
203
|
+
// ----- Plugin re-exports (detection-gated at module load; null when the tool wasn't detected) -----
|
|
204
|
+
|
|
205
|
+
export const nextPlugin: typeof import('@next/eslint-plugin-next').default | null;
|
|
206
|
+
export const nxPlugin: typeof import('@nx/eslint-plugin').default | null;
|
|
207
|
+
export const turboPlugin: typeof import('eslint-plugin-turbo').default | null;
|
|
208
|
+
export const jestPlugin: typeof import('eslint-plugin-jest');
|
|
209
|
+
export const vitestPlugin: typeof import('@vitest/eslint-plugin').default;
|
|
210
|
+
|
|
211
|
+
// ----- Helpers & companion configs -----
|
|
212
|
+
|
|
213
|
+
/**
|
|
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
|
|
216
|
+
* `@import "tailwindcss"`; null when zero or several match.
|
|
217
|
+
*/
|
|
218
|
+
export function findTailwindEntry(ignores: string[]): string | null;
|
|
219
|
+
|
|
220
|
+
/**
|
|
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.
|
|
224
|
+
*/
|
|
225
|
+
export function findNextRoots(ignores: string[]): string[];
|
|
226
|
+
|
|
227
|
+
/**
|
|
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`.
|
|
231
|
+
*/
|
|
232
|
+
export function scanWorkspace(fileGlob: string, ignores?: string[]): string[];
|
|
233
|
+
|
|
234
|
+
/** Convert an ignore file (`.gitignore`, `.prettierignore`) into an ESLint ignores block. */
|
|
235
|
+
export function includeIgnoreFile(importMetaUrl: string, ignoreFile: string): Linter.Config;
|
|
236
|
+
|
|
237
|
+
/** Shared Prettier configuration (`.prettierrc.mjs`: `export default prettier`). */
|
|
238
|
+
export const prettier: PrettierConfig;
|
|
239
|
+
|
|
240
|
+
/** Shared lint-staged configuration (`.lintstagedrc.mjs`: `export default listStaged`). */
|
|
241
|
+
export const listStaged: LintStagedConfiguration;
|