@shayanthenerd/eslint-config 0.31.0 → 0.33.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 +76 -42
- package/dist/configs/astro.mjs +5 -1
- package/dist/configs/javascript.mjs +1 -1
- package/dist/configs/packageJson.mjs +1 -1
- package/dist/configs/react.mjs +2 -2
- package/dist/configs/tailwind.mjs +7 -1
- package/dist/configs/tanstack.mjs +26 -0
- package/dist/configs/typescript.mjs +4 -6
- package/dist/helpers/ignores/defaultIgnorePatterns.mjs +1 -6
- package/dist/helpers/options/defaultOptions.mjs +19 -3
- package/dist/helpers/options/enableDetectedConfigs.mjs +22 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +3 -35
- package/dist/rules/astro.mjs +61 -54
- package/dist/rules/baseline.mjs +1 -1
- package/dist/rules/css.mjs +35 -7
- package/dist/rules/html.mjs +3 -2
- package/dist/rules/importX.mjs +2 -2
- package/dist/rules/javascript.mjs +6 -5
- package/dist/rules/next.mjs +2 -0
- package/dist/rules/node.mjs +1 -1
- package/dist/rules/packageJson.mjs +166 -153
- package/dist/rules/perfectionist.mjs +41 -11
- package/dist/rules/playwright.mjs +10 -0
- package/dist/rules/react.mjs +57 -54
- package/dist/rules/stylistic.mjs +1 -1
- package/dist/rules/tanstack.mjs +39 -0
- package/dist/rules/typescript.mjs +2 -2
- package/dist/rules/unicorn.mjs +15 -6
- package/dist/rules/vue.mjs +38 -41
- package/dist/rules/zod.mjs +2 -0
- package/dist/types/eslint-schema.d.mts +851 -651
- package/dist/types/index.d.mts +57 -7
- package/dist/types/options/baseline.d.mts +24 -3
- package/dist/types/options/react.d.mts +9 -9
- package/dist/types/options/tanstack.d.mts +32 -0
- package/dist/types/options/typescript.d.mts +3 -3
- package/dist/types/options/vue.d.mts +1 -1
- package/package.json +38 -34
package/README.md
CHANGED
|
@@ -25,44 +25,45 @@ ESLint configuration for enforcing best practices and maintaining a consistent c
|
|
|
25
25
|
## Plugin Support
|
|
26
26
|
Legend:
|
|
27
27
|
- ✅ — **Enabled** by default
|
|
28
|
+
- 🔍 — [**Automatically detected**](#automatic-dependency-detection)
|
|
28
29
|
- ⚙️ — **Opt-in** (requires manual configuration)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
| [
|
|
35
|
-
| [
|
|
36
|
-
| [
|
|
37
|
-
| [
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
| [
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
| [
|
|
44
|
-
| [
|
|
45
|
-
| [
|
|
46
|
-
| [Vue & Nuxt][plugin-vue] ([vue-accessibility][plugin-vue-a11y])
|
|
47
|
-
| [Tailwind][plugin-tailwind]
|
|
48
|
-
| [Zod & Zod Mini][plugin-zod]
|
|
49
|
-
| **Testing Tools**
|
|
50
|
-
| [Storybook][plugin-storybook]
|
|
51
|
-
| [Vitest][plugin-vitest]
|
|
52
|
-
| [Cypress][plugin-cypress]
|
|
53
|
-
| [Playwright][plugin-playwright]
|
|
54
|
-
| **Miscellaneous**
|
|
55
|
-
| [_package.json_][plugin-package-json]
|
|
56
|
-
| [Node][plugin-n]
|
|
57
|
-
| [Promises][plugin-promise]
|
|
58
|
-
| [Imports][plugin-import-x]
|
|
59
|
-
| [Unicorn][plugin-unicorn]
|
|
60
|
-
| [Baseline][plugin-baseline] ([css/use-baseline], [@html-eslint/use-baseline], [@html-eslint/react/use-baseline])
|
|
30
|
+
|
|
31
|
+
| Category | Activation |
|
|
32
|
+
| :------------------------------------------------------------------------------------------------------ | :--------: |
|
|
33
|
+
| **Languages** | |
|
|
34
|
+
| [JavaScript][eslint] | ✅ |
|
|
35
|
+
| [TypeScript][plugin-ts] | 🔍 |
|
|
36
|
+
| [Markdown][plugin-md] | ✅ |
|
|
37
|
+
| [HTML][plugin-html] | ⚙️ |
|
|
38
|
+
| [CSS][plugin-css] | ⚙️ |
|
|
39
|
+
| **Formatting** | |
|
|
40
|
+
| [Stylistic][plugin-stylistic] | ✅ |
|
|
41
|
+
| [Perfectionist][plugin-perfectionist] | ✅ |
|
|
42
|
+
| **Frameworks & Libraries** | |
|
|
43
|
+
| [Astro][plugin-astro] ([jsx-accessibility][plugin-jsx-a11y-x]) | 🔍 |
|
|
44
|
+
| [React][plugin-react] ([jsx-accessibility][plugin-jsx-a11y-x], [@html-eslint/react][plugin-html-react]) | 🔍 |
|
|
45
|
+
| [Next][plugin-next] | 🔍 |
|
|
46
|
+
| [TanStack Start][plugin-tanstack-start], [TanStack Query][plugin-tanstack-query], [TanStack Router][plugin-tanstack-router] | 🔍 |
|
|
47
|
+
| [Vue & Nuxt][plugin-vue] ([vue-accessibility][plugin-vue-a11y]) | 🔍 |
|
|
48
|
+
| [Tailwind][plugin-tailwind] | ⚙️ |
|
|
49
|
+
| [Zod & Zod Mini][plugin-zod] | 🔍 |
|
|
50
|
+
| **Testing Tools** | |
|
|
51
|
+
| [Storybook][plugin-storybook] | 🔍 |
|
|
52
|
+
| [Vitest][plugin-vitest] | 🔍 |
|
|
53
|
+
| [Cypress][plugin-cypress] | 🔍 |
|
|
54
|
+
| [Playwright][plugin-playwright] | 🔍 |
|
|
55
|
+
| **Miscellaneous** | |
|
|
56
|
+
| [_package.json_][plugin-package-json] | ✅ |
|
|
57
|
+
| [Node][plugin-n] | ✅ |
|
|
58
|
+
| [Promises][plugin-promise] | ✅ |
|
|
59
|
+
| [Imports][plugin-import-x] | ✅ |
|
|
60
|
+
| [Unicorn][plugin-unicorn] | ✅ |
|
|
61
|
+
| [Baseline][plugin-baseline] ([css/use-baseline], [@html-eslint/use-baseline], [@html-eslint/react/use-baseline]) | 🔍 |
|
|
61
62
|
|
|
62
63
|
## Installation and Configuration
|
|
63
64
|
1. Install the package and ESLint as dev dependencies:
|
|
64
65
|
```shell
|
|
65
|
-
|
|
66
|
+
pnpm i -D @shayanthenerd/eslint-config eslint
|
|
66
67
|
```
|
|
67
68
|
|
|
68
69
|
2. Create an ESLint configuration file (_eslint.config.js_) at the root of your project:
|
|
@@ -80,7 +81,7 @@ Legend:
|
|
|
80
81
|
"scripts": {
|
|
81
82
|
"lint": "eslint --max-warnings=0 --cache --cache-location='node_modules/.cache/.eslintcache'",
|
|
82
83
|
"lint:fix": "eslint --fix --max-warnings=0 --cache --cache-location='node_modules/.cache/.eslintcache'",
|
|
83
|
-
"lint:inspect": "
|
|
84
|
+
"lint:inspect": "pnpx @eslint/config-inspector"
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
```
|
|
@@ -88,9 +89,9 @@ Legend:
|
|
|
88
89
|
---
|
|
89
90
|
|
|
90
91
|
After installation:
|
|
91
|
-
- Use `
|
|
92
|
-
- Use `
|
|
93
|
-
- Use `
|
|
92
|
+
- Use `pnpm run lint` to lint files without modifying them (useful for CI).
|
|
93
|
+
- Use `pnpm run lint:fix` to lint and fix files.
|
|
94
|
+
- Use `pnpm run lint:inspect` to see a visual breakdown of your configuration.
|
|
94
95
|
- See [IDE Support](#ide-support) for editor integration.
|
|
95
96
|
- See [Customization](#customization) for advanced configuration.
|
|
96
97
|
- See [Formatting](#formatting) for formatting options and Prettier integration.
|
|
@@ -213,8 +214,27 @@ For editor integration, to reduce noise and avoid inconsistent diagnostics from
|
|
|
213
214
|
}
|
|
214
215
|
```
|
|
215
216
|
|
|
217
|
+
### Astro
|
|
218
|
+
The accessibility rules in [eslint-plugin-astro][plugin-astro] require [eslint-plugin-jsx-a11y-x][plugin-jsx-a11y-x] as a peer dependency. Install it with:
|
|
219
|
+
```shell
|
|
220
|
+
pnpm add -D eslint-plugin-jsx-a11y-x
|
|
221
|
+
```
|
|
222
|
+
When both `astro` and `eslint-plugin-jsx-a11y-x` are detected as dependencies, `configs.astro.accessibility` is set to `true` automatically. To disable the accessibility rules, set `configs.astro.accessibility` to `false`.
|
|
223
|
+
|
|
224
|
+
### Vue
|
|
225
|
+
[ESLint Stylistic][plugin-stylistic] and [eslint-plugin-vue][plugin-vue] don't format `<style>` blocks inside Vue SFCs. On the other hand, [Prettier][prettier] cannot be limited to just `<style>` blocks, and formats the whole file, including `<script>` and `<template>` blocks, which could conflict with ESLint. To work around this, you may use Tailwind, format styles manually, keep styles in separate `.css` files, or use Prettier and resolve any resulting conflicts.
|
|
226
|
+
|
|
227
|
+
Read more about the formatting options and Prettier integration in the [Formatting](#formatting) section.
|
|
228
|
+
|
|
216
229
|
### Nuxt
|
|
217
|
-
The required Nuxt configurations and rules are already included, so there's no need to
|
|
230
|
+
The required Nuxt configurations and rules are already included, so there's no need to use the [@nuxt/eslint][eslint-nuxt] module.
|
|
231
|
+
|
|
232
|
+
### React/Next
|
|
233
|
+
The required Next configurations and rules, including for core web vitals, are already provided, so there's no need to use [eslint-config-next][eslint-next]. Similarly, the React integration also provides React-specific configurations and rules for accessibility and React Hooks.
|
|
234
|
+
|
|
235
|
+
### TanStack Start
|
|
236
|
+
> [!NOTE]
|
|
237
|
+
> The rules in [@tanstack/eslint-plugin-start][plugin-tanstack-start] require type information, and will be disabled automatically if the TypeScript integration is not enabled.
|
|
218
238
|
|
|
219
239
|
### Markdown
|
|
220
240
|
Markdown linting is powered by [@eslint/markdown][plugin-md].
|
|
@@ -313,7 +333,7 @@ For file types that ESLint Stylistic does not handle—such as CSS, JSON, YAML,
|
|
|
313
333
|
|
|
314
334
|
1. Install Prettier as a dev dependency:
|
|
315
335
|
```shell
|
|
316
|
-
|
|
336
|
+
pnpm i -D prettier
|
|
317
337
|
```
|
|
318
338
|
|
|
319
339
|
2. Create a Prettier config file in the root of your project (_prettier.config.js_):
|
|
@@ -343,7 +363,7 @@ For file types that ESLint Stylistic does not handle—such as CSS, JSON, YAML,
|
|
|
343
363
|
```json title="package.json"
|
|
344
364
|
{
|
|
345
365
|
"scripts": {
|
|
346
|
-
"format": "prettier --write . '!**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,html,vue,astro}' --cache"
|
|
366
|
+
"format": "prettier --write . '!pnpm-lock.yaml' '!**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,html,vue,astro}' --cache"
|
|
347
367
|
}
|
|
348
368
|
}
|
|
349
369
|
```
|
|
@@ -426,7 +446,7 @@ For file types that ESLint Stylistic does not handle—such as CSS, JSON, YAML,
|
|
|
426
446
|
```json title="package.json"
|
|
427
447
|
{
|
|
428
448
|
"scripts": {
|
|
429
|
-
"format": "prettier --write . --cache",
|
|
449
|
+
"format": "prettier --write . '!pnpm-lock.yaml' --cache",
|
|
430
450
|
}
|
|
431
451
|
}
|
|
432
452
|
```
|
|
@@ -516,6 +536,7 @@ For file types that ESLint Stylistic does not handle—such as CSS, JSON, YAML,
|
|
|
516
536
|
|
|
517
537
|
configs?: {
|
|
518
538
|
astro?: boolean | {
|
|
539
|
+
accessibility?: boolean,
|
|
519
540
|
overrides?: Overrides,
|
|
520
541
|
},
|
|
521
542
|
baseline?: boolean | {
|
|
@@ -536,6 +557,7 @@ For file types that ESLint Stylistic does not handle—such as CSS, JSON, YAML,
|
|
|
536
557
|
overrides?: Overrides,
|
|
537
558
|
},
|
|
538
559
|
css?: boolean | {
|
|
560
|
+
allowedUnknownPseudoSelectors?: string[],
|
|
539
561
|
overrides?: Overrides,
|
|
540
562
|
},
|
|
541
563
|
html?: boolean | {
|
|
@@ -573,6 +595,8 @@ For file types that ESLint Stylistic does not handle—such as CSS, JSON, YAML,
|
|
|
573
595
|
overrides?: Overrides,
|
|
574
596
|
},
|
|
575
597
|
packageJson?: boolean | {
|
|
598
|
+
allowedDistTags?: string[],
|
|
599
|
+
allowedDistTagsFor?: ('dependencies' | 'devDependencies' | 'peerDependencies' | 'optionalDependencies')[],
|
|
576
600
|
overrides?: Overrides,
|
|
577
601
|
},
|
|
578
602
|
perfectionist?: boolean | {
|
|
@@ -619,6 +643,12 @@ For file types that ESLint Stylistic does not handle—such as CSS, JSON, YAML,
|
|
|
619
643
|
multilineSort?: boolean,
|
|
620
644
|
overrides?: Overrides,
|
|
621
645
|
},
|
|
646
|
+
tanstack?: boolean | {
|
|
647
|
+
query?: boolean,
|
|
648
|
+
router?: boolean,
|
|
649
|
+
start?: boolean,
|
|
650
|
+
overrides?: Overrides,
|
|
651
|
+
},
|
|
622
652
|
test?: {
|
|
623
653
|
maxNestedDescribe?: number,
|
|
624
654
|
testFunction?: 'it' | 'test',
|
|
@@ -756,7 +786,7 @@ This project was inspired by the work of [Anthony Fu][antfu], whose generous con
|
|
|
756
786
|
[plugin-html]: https://html-eslint.org
|
|
757
787
|
[plugin-html-react]: https://html-eslint.org/docs/react/getting-started
|
|
758
788
|
[plugin-import-x]: https://github.com/un-ts/eslint-plugin-import-x
|
|
759
|
-
[plugin-jsx-a11y]: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y
|
|
789
|
+
[plugin-jsx-a11y-x]: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y-x
|
|
760
790
|
[plugin-md]: https://github.com/eslint/markdown
|
|
761
791
|
[plugin-n]: https://github.com/eslint-community/eslint-plugin-n
|
|
762
792
|
[plugin-next]: https://github.com/vercel/next.js/tree/HEAD/packages/eslint-plugin-next
|
|
@@ -768,6 +798,9 @@ This project was inspired by the work of [Anthony Fu][antfu], whose generous con
|
|
|
768
798
|
[plugin-storybook]: https://storybook.js.org/docs/configure/integration/eslint-plugin
|
|
769
799
|
[plugin-stylistic]: https://eslint.style
|
|
770
800
|
[plugin-tailwind]: https://github.com/schoero/eslint-plugin-better-tailwindcss
|
|
801
|
+
[plugin-tanstack-query]: https://tanstack.com/query/latest/docs/eslint/eslint-plugin-query
|
|
802
|
+
[plugin-tanstack-router]: https://tanstack.com/router/latest/docs/eslint/eslint-plugin-router
|
|
803
|
+
[plugin-tanstack-start]: https://tanstack.com/start/latest/docs/eslint/eslint-plugin-start
|
|
771
804
|
[plugin-ts]: https://typescript-eslint.io
|
|
772
805
|
[plugin-unicorn]: https://github.com/sindresorhus/eslint-plugin-unicorn
|
|
773
806
|
[plugin-vitest]: https://github.com/vitest-dev/eslint-plugin-vitest
|
|
@@ -786,6 +819,7 @@ This project was inspired by the work of [Anthony Fu][antfu], whose generous con
|
|
|
786
819
|
[eslint]: https://eslint.org
|
|
787
820
|
[online-preview]: https://eslintconfig.netlify.app
|
|
788
821
|
[eslint-config-ts-setup]: https://eslint.org/docs/latest/use/configure/configuration-files#typescript-configuration-files
|
|
822
|
+
[eslint-next]: https://nextjs.org/docs/app/api-reference/config/eslint
|
|
789
823
|
[eslint-nuxt]: https://eslint.nuxt.com
|
|
790
824
|
[local-pkg]: https://github.com/antfu-collective/local-pkg
|
|
791
825
|
[prettier]: https://prettier.io
|
package/dist/configs/astro.mjs
CHANGED
|
@@ -6,9 +6,10 @@ import * as eslintParserAstro from "astro-eslint-parser";
|
|
|
6
6
|
import { mergeConfigs } from "eslint-flat-config-utils";
|
|
7
7
|
import eslintPluginAstro from "eslint-plugin-astro";
|
|
8
8
|
import { parser } from "typescript-eslint";
|
|
9
|
+
import path from "node:path";
|
|
9
10
|
//#region src/configs/astro.ts
|
|
10
11
|
function getAstroConfig(options) {
|
|
11
|
-
const { astro } = options
|
|
12
|
+
const { tsConfig, configs: { astro } } = options;
|
|
12
13
|
const { overrides } = isEnabled(astro) ? astro : defaultOptions.configs.astro;
|
|
13
14
|
const astroConfig = {
|
|
14
15
|
name: "shayanthenerd/astro",
|
|
@@ -22,6 +23,9 @@ function getAstroConfig(options) {
|
|
|
22
23
|
parser: eslintParserAstro,
|
|
23
24
|
parserOptions: {
|
|
24
25
|
parser,
|
|
26
|
+
projectService: false,
|
|
27
|
+
project: tsConfig ? path.resolve(tsConfig.rootDir, tsConfig.filename) : void 0,
|
|
28
|
+
tsconfigRootDir: tsConfig ? path.resolve(tsConfig.rootDir) : void 0,
|
|
25
29
|
extraFileExtensions: [".astro"]
|
|
26
30
|
}
|
|
27
31
|
},
|
|
@@ -9,7 +9,7 @@ import globals from "globals";
|
|
|
9
9
|
function getJavascriptConfig(options) {
|
|
10
10
|
const { env, configs: { vue, astro, javascript: { overrides } }, project: { globals: { bun, node, deno, vitest, worker, browser, commonjs, nodeBuiltin, audioWorklet, webextension, sharedWorker, serviceworker, vue: vueGlobals, astro: astroGlobals, custom: userGlobals } } } = options;
|
|
11
11
|
const baseConfig = {
|
|
12
|
-
name: "shayanthenerd/
|
|
12
|
+
name: "shayanthenerd/javascript",
|
|
13
13
|
files: [
|
|
14
14
|
globs.src,
|
|
15
15
|
globs.jsxTsx,
|
|
@@ -13,7 +13,7 @@ function getPackageJsonConfig(options) {
|
|
|
13
13
|
files: [globs.packageJson],
|
|
14
14
|
plugins: { "package-json": eslintPluginPackageJson },
|
|
15
15
|
languageOptions: { parser: eslintPluginPackageJson.configs.recommended.languageOptions.parser },
|
|
16
|
-
rules: getPackageJsonRules()
|
|
16
|
+
rules: getPackageJsonRules(options)
|
|
17
17
|
};
|
|
18
18
|
return mergeConfigs(packageJsonConfig, overrides);
|
|
19
19
|
}
|
package/dist/configs/react.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { isEnabled } from "../utils/isEnabled.mjs";
|
|
|
4
4
|
import { getReactRules } from "../rules/react.mjs";
|
|
5
5
|
import { mergeConfigs } from "eslint-flat-config-utils";
|
|
6
6
|
import eslintPluginUnicorn from "eslint-plugin-unicorn";
|
|
7
|
-
import
|
|
7
|
+
import eslintPluginJsxA11yX from "eslint-plugin-jsx-a11y-x";
|
|
8
8
|
import eslintPluginReact from "@eslint-react/eslint-plugin";
|
|
9
9
|
import eslintPluginHtmlReact from "@html-eslint/eslint-plugin-react";
|
|
10
10
|
//#region src/configs/react.ts
|
|
@@ -18,7 +18,7 @@ function getReactConfig(options) {
|
|
|
18
18
|
"@eslint-react": eslintPluginReact,
|
|
19
19
|
"@html-eslint/react": eslintPluginHtmlReact,
|
|
20
20
|
...isEnabled(unicorn) && { unicorn: eslintPluginUnicorn },
|
|
21
|
-
...isEnabled(accessibility) && { "jsx-a11y":
|
|
21
|
+
...isEnabled(accessibility) && { "jsx-a11y-x": eslintPluginJsxA11yX }
|
|
22
22
|
},
|
|
23
23
|
rules: getReactRules(options)
|
|
24
24
|
};
|
|
@@ -14,6 +14,11 @@ const astroAttributes = {
|
|
|
14
14
|
name: "^class:list$",
|
|
15
15
|
match: [{ type: MatcherType.String }, { type: MatcherType.ObjectKey }]
|
|
16
16
|
};
|
|
17
|
+
const reactAttributes = {
|
|
18
|
+
kind: SelectorKind.Attribute,
|
|
19
|
+
name: "^(?:className|.*Class)$",
|
|
20
|
+
match: [{ type: MatcherType.String }, { type: MatcherType.ObjectKey }]
|
|
21
|
+
};
|
|
17
22
|
const vueAttributes = {
|
|
18
23
|
kind: SelectorKind.Attribute,
|
|
19
24
|
name: "^(?:v-bind:)?(exactActiveClass|activeClass|inactiveClass|active-class|inactive-class)$",
|
|
@@ -43,13 +48,14 @@ const nuxtUiAppConfigUiFields = {
|
|
|
43
48
|
}]
|
|
44
49
|
};
|
|
45
50
|
function getTailwindConfig(options) {
|
|
46
|
-
const { tsConfig, configs: { vue, nuxt, html, astro, tailwind } } = options;
|
|
51
|
+
const { tsConfig, configs: { vue, nuxt, html, astro, react, tailwind } } = options;
|
|
47
52
|
const { cwd, config, overrides, entryPoint } = isEnabled(tailwind) ? tailwind : defaultOptions.configs.tailwind;
|
|
48
53
|
const tsconfigPath = tsConfig ? path.resolve(tsConfig.rootDir, tsConfig.filename) : void 0;
|
|
49
54
|
const isNuxtUiEnabled = isEnabled(nuxt) && isEnabled(nuxt.ui);
|
|
50
55
|
const selectors = [
|
|
51
56
|
...getDefaultSelectors(),
|
|
52
57
|
isEnabled(astro) ? astroAttributes : void 0,
|
|
58
|
+
isEnabled(react) ? reactAttributes : void 0,
|
|
53
59
|
isEnabled(vue) ? vueAttributes : void 0,
|
|
54
60
|
isNuxtUiEnabled ? nuxtUiAttributes : void 0,
|
|
55
61
|
isNuxtUiEnabled ? nuxtUiAppConfigUiFields : void 0
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { globs } from "../helpers/globs.mjs";
|
|
2
|
+
import { defaultOptions } from "../helpers/options/defaultOptions.mjs";
|
|
3
|
+
import { isEnabled } from "../utils/isEnabled.mjs";
|
|
4
|
+
import { getTanstackRules } from "../rules/tanstack.mjs";
|
|
5
|
+
import { mergeConfigs } from "eslint-flat-config-utils";
|
|
6
|
+
import eslintPluginTanstackQuery from "@tanstack/eslint-plugin-query";
|
|
7
|
+
import eslintPluginTanstackRouter from "@tanstack/eslint-plugin-router";
|
|
8
|
+
import eslintPluginTanstackStart from "@tanstack/eslint-plugin-start";
|
|
9
|
+
//#region src/configs/tanstack.ts
|
|
10
|
+
function getTanstackConfig(options) {
|
|
11
|
+
const { tanstack } = options.configs;
|
|
12
|
+
const { overrides } = isEnabled(tanstack) ? tanstack : defaultOptions.configs.tanstack;
|
|
13
|
+
const tanstackConfig = {
|
|
14
|
+
name: "shayanthenerd/tanstack",
|
|
15
|
+
files: [globs.src, globs.jsxTsx],
|
|
16
|
+
plugins: isEnabled(tanstack) ? {
|
|
17
|
+
...isEnabled(tanstack.start) && { "@tanstack/start": eslintPluginTanstackStart },
|
|
18
|
+
...isEnabled(tanstack.query) && { "@tanstack/query": eslintPluginTanstackQuery },
|
|
19
|
+
...isEnabled(tanstack.router) && { "@tanstack/router": eslintPluginTanstackRouter }
|
|
20
|
+
} : {},
|
|
21
|
+
rules: getTanstackRules(options)
|
|
22
|
+
};
|
|
23
|
+
return mergeConfigs(tanstackConfig, overrides);
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { getTanstackConfig };
|
|
@@ -8,26 +8,24 @@ import { parser, plugin } from "typescript-eslint";
|
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
//#region src/configs/typescript.ts
|
|
10
10
|
function getTypescriptConfig(options) {
|
|
11
|
-
const { tsConfig, configs: { vue,
|
|
12
|
-
const { allowedDefaultProjects } = isEnabled(typescript) ? typescript : defaultOptions.configs.typescript;
|
|
11
|
+
const { tsConfig, configs: { vue, typescript } } = options;
|
|
12
|
+
const { allowedDefaultProjects: userAllowedDefaultProjects } = isEnabled(typescript) ? typescript : defaultOptions.configs.typescript;
|
|
13
13
|
const { overrides } = isEnabled(typescript) ? typescript : defaultOptions.configs.typescript;
|
|
14
14
|
const typescriptConfig = {
|
|
15
15
|
name: "shayanthenerd/typescript",
|
|
16
16
|
files: [
|
|
17
17
|
globs.src,
|
|
18
18
|
globs.jsxTsx,
|
|
19
|
-
isEnabled(vue) ? globs.vue : ""
|
|
20
|
-
isEnabled(astro) ? globs.astro : ""
|
|
19
|
+
isEnabled(vue) ? globs.vue : ""
|
|
21
20
|
].filter(isTruthy),
|
|
22
21
|
plugins: { "@typescript-eslint": plugin },
|
|
23
22
|
languageOptions: {
|
|
24
23
|
parser,
|
|
25
24
|
parserOptions: {
|
|
26
|
-
warnOnUnsupportedTypeScriptVersion: false,
|
|
27
25
|
tsconfigRootDir: tsConfig ? path.resolve(tsConfig.rootDir) : void 0,
|
|
28
26
|
projectService: {
|
|
29
27
|
defaultProject: tsConfig ? tsConfig.filename : void 0,
|
|
30
|
-
allowDefaultProject:
|
|
28
|
+
allowDefaultProject: userAllowedDefaultProjects
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
31
|
},
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
//#region src/helpers/ignores/defaultIgnorePatterns.ts
|
|
2
2
|
const defaultIgnorePatterns = [
|
|
3
|
-
"**/*.min.*",
|
|
4
3
|
"**/jspm_packages",
|
|
5
4
|
"**/pnpm-lock.yaml",
|
|
6
|
-
"**/bower_components",
|
|
7
5
|
"**/package-lock.json",
|
|
8
6
|
"**/typegen.d.ts",
|
|
9
7
|
"**/next-env.d.ts",
|
|
@@ -18,6 +16,7 @@ const defaultIgnorePatterns = [
|
|
|
18
16
|
"**/public",
|
|
19
17
|
"**/output",
|
|
20
18
|
"**/.output",
|
|
19
|
+
"**/*.min.*",
|
|
21
20
|
"**/.serverless",
|
|
22
21
|
"**/.eslint-config-inspector",
|
|
23
22
|
"**/tmp",
|
|
@@ -29,22 +28,18 @@ const defaultIgnorePatterns = [
|
|
|
29
28
|
"**/.cache",
|
|
30
29
|
"**/deno_dir",
|
|
31
30
|
"**/.parcel-cache",
|
|
32
|
-
"**/*.lerna_backup",
|
|
33
31
|
"**/.postcss-cache",
|
|
34
32
|
"**/.vitepress/cache",
|
|
35
33
|
"**/vite.config.*.timestamp-*",
|
|
36
34
|
"**/.nx",
|
|
37
35
|
"**/.vite",
|
|
38
|
-
"**/.yarn",
|
|
39
36
|
"**/.nuxt",
|
|
40
37
|
"**/.next",
|
|
41
38
|
"**/.astro",
|
|
42
39
|
"**/.vitest",
|
|
43
40
|
"**/.vercel",
|
|
44
|
-
"**/.svelte-kit",
|
|
45
41
|
"**/.vite-inspect",
|
|
46
42
|
"**/coverage",
|
|
47
|
-
"**/_fixtures",
|
|
48
43
|
"**/.nyc_output",
|
|
49
44
|
"**/__snapshots__",
|
|
50
45
|
"**/.idea",
|
|
@@ -34,7 +34,10 @@ const defaultOptions = {
|
|
|
34
34
|
settings: {}
|
|
35
35
|
},
|
|
36
36
|
configs: {
|
|
37
|
-
astro: {
|
|
37
|
+
astro: {
|
|
38
|
+
accessibility: false,
|
|
39
|
+
overrides: {}
|
|
40
|
+
},
|
|
38
41
|
baseline: {
|
|
39
42
|
baseline: "widely",
|
|
40
43
|
css: {
|
|
@@ -52,7 +55,10 @@ const defaultOptions = {
|
|
|
52
55
|
},
|
|
53
56
|
overrides: {}
|
|
54
57
|
},
|
|
55
|
-
css: {
|
|
58
|
+
css: {
|
|
59
|
+
allowedUnknownPseudoSelectors: [],
|
|
60
|
+
overrides: {}
|
|
61
|
+
},
|
|
56
62
|
html: {
|
|
57
63
|
idNamingConvention: "snake_case",
|
|
58
64
|
overrides: {}
|
|
@@ -77,7 +83,11 @@ const defaultOptions = {
|
|
|
77
83
|
ui: { prefix: "U" },
|
|
78
84
|
overrides: {}
|
|
79
85
|
},
|
|
80
|
-
packageJson: {
|
|
86
|
+
packageJson: {
|
|
87
|
+
allowedDistTags: [],
|
|
88
|
+
allowedDistTagsFor: [],
|
|
89
|
+
overrides: {}
|
|
90
|
+
},
|
|
81
91
|
perfectionist: {
|
|
82
92
|
sortType: "line-length",
|
|
83
93
|
overrides: {}
|
|
@@ -131,6 +141,12 @@ const defaultOptions = {
|
|
|
131
141
|
multilineSort: true,
|
|
132
142
|
overrides: {}
|
|
133
143
|
},
|
|
144
|
+
tanstack: {
|
|
145
|
+
query: false,
|
|
146
|
+
router: false,
|
|
147
|
+
start: false,
|
|
148
|
+
overrides: {}
|
|
149
|
+
},
|
|
134
150
|
test: {
|
|
135
151
|
maxNestedDescribe: 1,
|
|
136
152
|
testFunction: "test",
|
|
@@ -7,8 +7,12 @@ function enableDetectedConfigs(options) {
|
|
|
7
7
|
"typescript": options.configs?.typescript === false,
|
|
8
8
|
"zod": options.configs?.zod === false,
|
|
9
9
|
"astro": options.configs?.astro === false,
|
|
10
|
+
"eslint-plugin-jsx-a11y-x": isEnabled(options.configs?.astro) && options.configs?.astro?.accessibility === false,
|
|
10
11
|
"react": options.configs?.react === false,
|
|
11
12
|
"next": options.configs?.next === false,
|
|
13
|
+
"@tanstack/react-router": isEnabled(options.configs?.tanstack) && options.configs?.tanstack?.router === false,
|
|
14
|
+
"@tanstack/react-start": isEnabled(options.configs?.tanstack) && options.configs?.tanstack?.start === false,
|
|
15
|
+
"@tanstack/react-query": isEnabled(options.configs?.tanstack) && options.configs?.tanstack?.query === false,
|
|
12
16
|
"vue": options.configs?.vue === false,
|
|
13
17
|
"nuxt": options.configs?.nuxt === false,
|
|
14
18
|
"@nuxt/ui": isEnabled(options.configs?.nuxt) && options.configs?.nuxt?.ui === false,
|
|
@@ -23,8 +27,12 @@ function enableDetectedConfigs(options) {
|
|
|
23
27
|
typescript: isPackageDetected("typescript", options),
|
|
24
28
|
zod: isPackageDetected("zod", options),
|
|
25
29
|
astro: isPackageDetected("astro", options),
|
|
30
|
+
eslintPluginJsxA11yX: isPackageDetected("eslint-plugin-jsx-a11y-x", options),
|
|
26
31
|
react: isPackageDetected("react", options),
|
|
27
32
|
next: isPackageDetected("next", options),
|
|
33
|
+
tanstackStart: isPackageDetected("@tanstack/react-start", options),
|
|
34
|
+
tanstackQuery: isPackageDetected("@tanstack/react-query", options),
|
|
35
|
+
tanstackRouter: isPackageDetected("@tanstack/react-router", options),
|
|
28
36
|
vue: isPackageDetected("vue", options),
|
|
29
37
|
nuxt: isPackageDetected("nuxt", options),
|
|
30
38
|
nuxtUI: isPackageDetected("@nuxt/ui", options),
|
|
@@ -35,6 +43,8 @@ function enableDetectedConfigs(options) {
|
|
|
35
43
|
storybook: isPackageDetected("storybook", options),
|
|
36
44
|
playwright: isPackageDetected("@playwright/test", options)
|
|
37
45
|
};
|
|
46
|
+
options.autoDetectDeps ??= defaultOptions.autoDetectDeps;
|
|
47
|
+
options.env ??= defaultOptions.env;
|
|
38
48
|
options.configs ??= {};
|
|
39
49
|
options.configs.test ??= {};
|
|
40
50
|
options.configs.node ??= true;
|
|
@@ -47,7 +57,7 @@ function enableDetectedConfigs(options) {
|
|
|
47
57
|
options.configs.importX ??= true;
|
|
48
58
|
options.configs.stylistic ??= true;
|
|
49
59
|
options.configs.perfectionist ??= true;
|
|
50
|
-
options.configs.baseline ??= options.env === "browser";
|
|
60
|
+
options.configs.baseline ??= options.autoDetectDeps && options.env === "browser";
|
|
51
61
|
options.configs.typescript ??= autoDetectedPackages.typescript;
|
|
52
62
|
options.configs.zod ??= autoDetectedPackages.zod;
|
|
53
63
|
options.configs.astro ??= autoDetectedPackages.astro;
|
|
@@ -55,6 +65,7 @@ function enableDetectedConfigs(options) {
|
|
|
55
65
|
options.configs.nuxt ??= autoDetectedPackages.nuxt;
|
|
56
66
|
options.configs.react ??= autoDetectedPackages.react;
|
|
57
67
|
options.configs.next ??= autoDetectedPackages.next;
|
|
68
|
+
options.configs.tanstack ??= autoDetectedPackages.tanstackStart || autoDetectedPackages.tanstackQuery || autoDetectedPackages.tanstackRouter;
|
|
58
69
|
options.configs.test.vitest ??= autoDetectedPackages.vitest;
|
|
59
70
|
options.configs.test.cypress ??= autoDetectedPackages.cypress;
|
|
60
71
|
options.configs.test.storybook ??= autoDetectedPackages.storybook;
|
|
@@ -82,6 +93,16 @@ function enableDetectedConfigs(options) {
|
|
|
82
93
|
options.configs.nuxt.icon ??= autoDetectedPackages.nuxtIcon;
|
|
83
94
|
options.configs.nuxt.image ??= autoDetectedPackages.nuxtImage;
|
|
84
95
|
}
|
|
96
|
+
if (options.configs.astro) {
|
|
97
|
+
options.configs.astro = options.configs.astro === true ? {} : options.configs.astro;
|
|
98
|
+
options.configs.astro.accessibility ??= autoDetectedPackages.eslintPluginJsxA11yX;
|
|
99
|
+
}
|
|
100
|
+
if (options.configs.tanstack) {
|
|
101
|
+
if (options.configs.tanstack === true) options.configs.tanstack = {};
|
|
102
|
+
options.configs.tanstack.start ??= autoDetectedPackages.tanstackStart;
|
|
103
|
+
options.configs.tanstack.query ??= autoDetectedPackages.tanstackQuery;
|
|
104
|
+
options.configs.tanstack.router ??= autoDetectedPackages.tanstackRouter;
|
|
105
|
+
}
|
|
85
106
|
if (options.autoDetectDeps === "verbose") logDetectedPackages(explicitlyDisabledConfigs);
|
|
86
107
|
return options;
|
|
87
108
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Options } from "./types/index.mjs";
|
|
2
2
|
import { Linter } from "eslint";
|
|
3
3
|
//#region src/index.d.ts
|
|
4
|
-
/** Valid argument combinations for `defineConfig`. */
|
|
5
|
-
type DefineConfigArguments = [] | [options: Options] | [configs: Linter.Config[]] | [options: Options, configs: Linter.Config[]];
|
|
6
4
|
/**
|
|
7
5
|
* Define your ESLint configuration based on the provided options and/or custom Flat Config Objects.
|
|
8
6
|
*
|
|
@@ -37,6 +35,9 @@ type DefineConfigArguments = [] | [options: Options] | [configs: Linter.Config[]
|
|
|
37
35
|
* ],
|
|
38
36
|
* );
|
|
39
37
|
*/
|
|
40
|
-
declare function defineConfig(
|
|
38
|
+
declare function defineConfig(): Linter.Config[];
|
|
39
|
+
declare function defineConfig(options: Options): Linter.Config[];
|
|
40
|
+
declare function defineConfig(configs: Linter.Config[]): Linter.Config[];
|
|
41
|
+
declare function defineConfig(options: Options, configs: Linter.Config[]): Linter.Config[];
|
|
41
42
|
//#endregion
|
|
42
43
|
export { defineConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -19,6 +19,7 @@ import { getReactConfig } from "./configs/react.mjs";
|
|
|
19
19
|
import { getStorybookConfig } from "./configs/storybook.mjs";
|
|
20
20
|
import { getStylisticConfig } from "./configs/stylistic.mjs";
|
|
21
21
|
import { getTailwindConfig } from "./configs/tailwind.mjs";
|
|
22
|
+
import { getTanstackConfig } from "./configs/tanstack.mjs";
|
|
22
23
|
import { getTypescriptConfig } from "./configs/typescript.mjs";
|
|
23
24
|
import { getUnicornConfig } from "./configs/unicorn.mjs";
|
|
24
25
|
import { getVitestConfig } from "./configs/vitest.mjs";
|
|
@@ -28,40 +29,6 @@ import { getIgnorePatterns } from "./helpers/ignores/getIgnorePatterns.mjs";
|
|
|
28
29
|
import { mergeWithDefaults } from "./helpers/options/mergeWithDefaults.mjs";
|
|
29
30
|
import { defineConfig as defineConfig$1, globalIgnores } from "eslint/config";
|
|
30
31
|
//#region src/index.ts
|
|
31
|
-
/**
|
|
32
|
-
* Define your ESLint configuration based on the provided options and/or custom Flat Config Objects.
|
|
33
|
-
*
|
|
34
|
-
* @param {...DefineConfigArguments} args The configuration options and/or custom Flat Config objects.
|
|
35
|
-
* @returns {Linter.Config[]} The merged ESLint configuration array
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* defineConfig();
|
|
39
|
-
* // or
|
|
40
|
-
* defineConfig({ autoDetectDeps: 'verbose' });
|
|
41
|
-
* // or
|
|
42
|
-
* defineConfig([
|
|
43
|
-
* {
|
|
44
|
-
* name: 'custom',
|
|
45
|
-
* rules: {
|
|
46
|
-
* 'no-console': 'error',
|
|
47
|
-
* },
|
|
48
|
-
* },
|
|
49
|
-
* { ... },
|
|
50
|
-
* ]);
|
|
51
|
-
* // or
|
|
52
|
-
* defineConfig(
|
|
53
|
-
* { autoDetectDeps: 'verbose' },
|
|
54
|
-
* [
|
|
55
|
-
* {
|
|
56
|
-
* name: 'custom',
|
|
57
|
-
* rules: {
|
|
58
|
-
* 'no-console': 'error',
|
|
59
|
-
* },
|
|
60
|
-
* },
|
|
61
|
-
* { ... },
|
|
62
|
-
* ],
|
|
63
|
-
* );
|
|
64
|
-
*/
|
|
65
32
|
function defineConfig(...args) {
|
|
66
33
|
let options = {};
|
|
67
34
|
let userConfigs = [];
|
|
@@ -72,7 +39,7 @@ function defineConfig(...args) {
|
|
|
72
39
|
userConfigs = secondArgument ?? [];
|
|
73
40
|
}
|
|
74
41
|
const mergedOptions = mergeWithDefaults(options);
|
|
75
|
-
const { gitignore, project: { rules, ignores, settings, linterOptions }, configs: { css, vue, zod, html, next, node, nuxt, react, astro, unicorn, importX, promise, baseline, markdown, tailwind, stylistic, typescript, packageJson, perfectionist, test: { vitest, cypress, storybook, playwright } } } = mergedOptions;
|
|
42
|
+
const { gitignore, project: { rules, ignores, settings, linterOptions }, configs: { css, vue, zod, html, next, node, nuxt, react, astro, unicorn, importX, promise, baseline, markdown, tailwind, tanstack, stylistic, typescript, packageJson, perfectionist, test: { vitest, cypress, storybook, playwright } } } = mergedOptions;
|
|
76
43
|
const ignorePatterns = getIgnorePatterns({
|
|
77
44
|
gitignore,
|
|
78
45
|
patterns: ignores
|
|
@@ -103,6 +70,7 @@ function defineConfig(...args) {
|
|
|
103
70
|
isEnabled(astro) && getAstroConfig(mergedOptions),
|
|
104
71
|
isEnabled(react) && getReactConfig(mergedOptions),
|
|
105
72
|
isEnabled(next) && getNextConfig(mergedOptions),
|
|
73
|
+
isEnabled(tanstack) && getTanstackConfig(mergedOptions),
|
|
106
74
|
isEnabled(vue) && getVueConfig(mergedOptions),
|
|
107
75
|
...isEnabled(nuxt) ? getNuxtConfigs(mergedOptions) : [],
|
|
108
76
|
isEnabled(storybook) && getStorybookConfig(mergedOptions),
|