@anolilab/eslint-config 15.0.2 → 16.0.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/CHANGELOG.md +39 -0
- package/README.md +386 -466
- package/dist/index.cjs +20 -0
- package/dist/index.d.cts +16370 -0
- package/dist/index.d.mts +16370 -0
- package/dist/index.d.ts +16367 -2
- package/dist/index.mjs +20 -0
- package/package.json +89 -265
- package/bin/generate-eslint-cofig.js +0 -3
- package/dist/chunk-A6LXZAWN.js +0 -9
- package/dist/chunk-A6LXZAWN.js.map +0 -1
- package/dist/chunk-MFE6DF6Y.js +0 -8
- package/dist/chunk-MFE6DF6Y.js.map +0 -1
- package/dist/chunk-MKL3NIXX.js +0 -9
- package/dist/chunk-MKL3NIXX.js.map +0 -1
- package/dist/chunk-R26SPKXH.js +0 -9
- package/dist/chunk-R26SPKXH.js.map +0 -1
- package/dist/chunk-RG6NJDJA.js +0 -9
- package/dist/chunk-RG6NJDJA.js.map +0 -1
- package/dist/chunk-SEYYGHPU.js +0 -8
- package/dist/chunk-SEYYGHPU.js.map +0 -1
- package/dist/chunk-SLM5UENV.js +0 -14
- package/dist/chunk-SLM5UENV.js.map +0 -1
- package/dist/chunk-UGG52B5H.js +0 -11
- package/dist/chunk-UGG52B5H.js.map +0 -1
- package/dist/chunk-WG6GTAIA.js +0 -8
- package/dist/chunk-WG6GTAIA.js.map +0 -1
- package/dist/chunk-WW4PDMXQ.js +0 -9
- package/dist/chunk-WW4PDMXQ.js.map +0 -1
- package/dist/config/best-practices.d.ts +0 -5
- package/dist/config/best-practices.js +0 -11
- package/dist/config/best-practices.js.map +0 -1
- package/dist/config/errors.d.ts +0 -5
- package/dist/config/errors.js +0 -11
- package/dist/config/errors.js.map +0 -1
- package/dist/config/es6.d.ts +0 -5
- package/dist/config/es6.js +0 -11
- package/dist/config/es6.js.map +0 -1
- package/dist/config/plugins/antfu.d.ts +0 -5
- package/dist/config/plugins/antfu.js +0 -11
- package/dist/config/plugins/antfu.js.map +0 -1
- package/dist/config/plugins/array-func.d.ts +0 -5
- package/dist/config/plugins/array-func.js +0 -10
- package/dist/config/plugins/array-func.js.map +0 -1
- package/dist/config/plugins/ava.d.ts +0 -5
- package/dist/config/plugins/ava.js +0 -9
- package/dist/config/plugins/ava.js.map +0 -1
- package/dist/config/plugins/babel.d.ts +0 -5
- package/dist/config/plugins/babel.js +0 -16
- package/dist/config/plugins/babel.js.map +0 -1
- package/dist/config/plugins/compat.d.ts +0 -5
- package/dist/config/plugins/compat.js +0 -9
- package/dist/config/plugins/compat.js.map +0 -1
- package/dist/config/plugins/cypress.d.ts +0 -5
- package/dist/config/plugins/cypress.js +0 -9
- package/dist/config/plugins/cypress.js.map +0 -1
- package/dist/config/plugins/deprecation.d.ts +0 -5
- package/dist/config/plugins/deprecation.js +0 -10
- package/dist/config/plugins/deprecation.js.map +0 -1
- package/dist/config/plugins/editorconfig.d.ts +0 -5
- package/dist/config/plugins/editorconfig.js +0 -10
- package/dist/config/plugins/editorconfig.js.map +0 -1
- package/dist/config/plugins/es.d.ts +0 -5
- package/dist/config/plugins/es.js +0 -10
- package/dist/config/plugins/es.js.map +0 -1
- package/dist/config/plugins/eslint-comments.d.ts +0 -5
- package/dist/config/plugins/eslint-comments.js +0 -10
- package/dist/config/plugins/eslint-comments.js.map +0 -1
- package/dist/config/plugins/etc.d.ts +0 -5
- package/dist/config/plugins/etc.js +0 -18
- package/dist/config/plugins/etc.js.map +0 -1
- package/dist/config/plugins/html.d.ts +0 -5
- package/dist/config/plugins/html.js +0 -12
- package/dist/config/plugins/html.js.map +0 -1
- package/dist/config/plugins/import.d.ts +0 -5
- package/dist/config/plugins/import.js +0 -12
- package/dist/config/plugins/import.js.map +0 -1
- package/dist/config/plugins/jest-async.d.ts +0 -5
- package/dist/config/plugins/jest-async.js +0 -9
- package/dist/config/plugins/jest-async.js.map +0 -1
- package/dist/config/plugins/jest-dom.d.ts +0 -5
- package/dist/config/plugins/jest-dom.js +0 -9
- package/dist/config/plugins/jest-dom.js.map +0 -1
- package/dist/config/plugins/jest-formatting.d.ts +0 -5
- package/dist/config/plugins/jest-formatting.js +0 -9
- package/dist/config/plugins/jest-formatting.js.map +0 -1
- package/dist/config/plugins/jest.d.ts +0 -5
- package/dist/config/plugins/jest.js +0 -14
- package/dist/config/plugins/jest.js.map +0 -1
- package/dist/config/plugins/jsdoc.d.ts +0 -5
- package/dist/config/plugins/jsdoc.js +0 -12
- package/dist/config/plugins/jsdoc.js.map +0 -1
- package/dist/config/plugins/jsonc.d.ts +0 -5
- package/dist/config/plugins/jsonc.js +0 -17
- package/dist/config/plugins/jsonc.js.map +0 -1
- package/dist/config/plugins/jsx-a11y.d.ts +0 -5
- package/dist/config/plugins/jsx-a11y.js +0 -10
- package/dist/config/plugins/jsx-a11y.js.map +0 -1
- package/dist/config/plugins/markdown.d.ts +0 -5
- package/dist/config/plugins/markdown.js +0 -10
- package/dist/config/plugins/markdown.js.map +0 -1
- package/dist/config/plugins/mdx.d.ts +0 -5
- package/dist/config/plugins/mdx.js +0 -10
- package/dist/config/plugins/mdx.js.map +0 -1
- package/dist/config/plugins/no-extend-native.d.ts +0 -5
- package/dist/config/plugins/no-extend-native.js +0 -9
- package/dist/config/plugins/no-extend-native.js.map +0 -1
- package/dist/config/plugins/no-loops.d.ts +0 -5
- package/dist/config/plugins/no-loops.js +0 -9
- package/dist/config/plugins/no-loops.js.map +0 -1
- package/dist/config/plugins/no-only-tests.d.ts +0 -5
- package/dist/config/plugins/no-only-tests.js +0 -10
- package/dist/config/plugins/no-only-tests.js.map +0 -1
- package/dist/config/plugins/no-secrets.d.ts +0 -5
- package/dist/config/plugins/no-secrets.js +0 -9
- package/dist/config/plugins/no-secrets.js.map +0 -1
- package/dist/config/plugins/no-unsanitized.d.ts +0 -5
- package/dist/config/plugins/no-unsanitized.js +0 -9
- package/dist/config/plugins/no-unsanitized.js.map +0 -1
- package/dist/config/plugins/node.d.ts +0 -5
- package/dist/config/plugins/node.js +0 -10
- package/dist/config/plugins/node.js.map +0 -1
- package/dist/config/plugins/perfectionist.d.ts +0 -5
- package/dist/config/plugins/perfectionist.js +0 -14
- package/dist/config/plugins/perfectionist.js.map +0 -1
- package/dist/config/plugins/playwright.d.ts +0 -5
- package/dist/config/plugins/playwright.js +0 -10
- package/dist/config/plugins/playwright.js.map +0 -1
- package/dist/config/plugins/promise.d.ts +0 -5
- package/dist/config/plugins/promise.js +0 -9
- package/dist/config/plugins/promise.js.map +0 -1
- package/dist/config/plugins/react-hooks.d.ts +0 -5
- package/dist/config/plugins/react-hooks.js +0 -10
- package/dist/config/plugins/react-hooks.js.map +0 -1
- package/dist/config/plugins/react-redux.d.ts +0 -5
- package/dist/config/plugins/react-redux.js +0 -10
- package/dist/config/plugins/react-redux.js.map +0 -1
- package/dist/config/plugins/react-usememo.d.ts +0 -5
- package/dist/config/plugins/react-usememo.js +0 -10
- package/dist/config/plugins/react-usememo.js.map +0 -1
- package/dist/config/plugins/react.d.ts +0 -5
- package/dist/config/plugins/react.js +0 -29
- package/dist/config/plugins/react.js.map +0 -1
- package/dist/config/plugins/regexp.d.ts +0 -5
- package/dist/config/plugins/regexp.js +0 -10
- package/dist/config/plugins/regexp.js.map +0 -1
- package/dist/config/plugins/security.d.ts +0 -5
- package/dist/config/plugins/security.js +0 -9
- package/dist/config/plugins/security.js.map +0 -1
- package/dist/config/plugins/simple-import-sort.d.ts +0 -5
- package/dist/config/plugins/simple-import-sort.js +0 -10
- package/dist/config/plugins/simple-import-sort.js.map +0 -1
- package/dist/config/plugins/sonarjs.d.ts +0 -5
- package/dist/config/plugins/sonarjs.js +0 -10
- package/dist/config/plugins/sonarjs.js.map +0 -1
- package/dist/config/plugins/ssr-friendly.d.ts +0 -5
- package/dist/config/plugins/ssr-friendly.js +0 -10
- package/dist/config/plugins/ssr-friendly.js.map +0 -1
- package/dist/config/plugins/storybook.d.ts +0 -5
- package/dist/config/plugins/storybook.js +0 -9
- package/dist/config/plugins/storybook.js.map +0 -1
- package/dist/config/plugins/tailwindcss.d.ts +0 -5
- package/dist/config/plugins/tailwindcss.js +0 -10
- package/dist/config/plugins/tailwindcss.js.map +0 -1
- package/dist/config/plugins/tanstack-query.d.ts +0 -5
- package/dist/config/plugins/tanstack-query.js +0 -10
- package/dist/config/plugins/tanstack-query.js.map +0 -1
- package/dist/config/plugins/testing-library-dom.d.ts +0 -5
- package/dist/config/plugins/testing-library-dom.js +0 -12
- package/dist/config/plugins/testing-library-dom.js.map +0 -1
- package/dist/config/plugins/testing-library-react.d.ts +0 -5
- package/dist/config/plugins/testing-library-react.js +0 -12
- package/dist/config/plugins/testing-library-react.js.map +0 -1
- package/dist/config/plugins/toml.d.ts +0 -5
- package/dist/config/plugins/toml.js +0 -9
- package/dist/config/plugins/toml.js.map +0 -1
- package/dist/config/plugins/tsdoc.d.ts +0 -5
- package/dist/config/plugins/tsdoc.js +0 -10
- package/dist/config/plugins/tsdoc.js.map +0 -1
- package/dist/config/plugins/typescript.d.ts +0 -5
- package/dist/config/plugins/typescript.js +0 -19
- package/dist/config/plugins/typescript.js.map +0 -1
- package/dist/config/plugins/unicorn.d.ts +0 -5
- package/dist/config/plugins/unicorn.js +0 -12
- package/dist/config/plugins/unicorn.js.map +0 -1
- package/dist/config/plugins/validate-jsx-nesting.d.ts +0 -5
- package/dist/config/plugins/validate-jsx-nesting.js +0 -10
- package/dist/config/plugins/validate-jsx-nesting.js.map +0 -1
- package/dist/config/plugins/vitest.d.ts +0 -5
- package/dist/config/plugins/vitest.js +0 -10
- package/dist/config/plugins/vitest.js.map +0 -1
- package/dist/config/plugins/yml.d.ts +0 -5
- package/dist/config/plugins/yml.js +0 -12
- package/dist/config/plugins/yml.js.map +0 -1
- package/dist/config/plugins/you-dont-need-lodash-underscore.d.ts +0 -5
- package/dist/config/plugins/you-dont-need-lodash-underscore.js +0 -10
- package/dist/config/plugins/you-dont-need-lodash-underscore.js.map +0 -1
- package/dist/config/plugins/you-dont-need-momentjs.d.ts +0 -5
- package/dist/config/plugins/you-dont-need-momentjs.js +0 -10
- package/dist/config/plugins/you-dont-need-momentjs.js.map +0 -1
- package/dist/config/plugins/zod.d.ts +0 -5
- package/dist/config/plugins/zod.js +0 -10
- package/dist/config/plugins/zod.js.map +0 -1
- package/dist/config/style.d.ts +0 -5
- package/dist/config/style.js +0 -13
- package/dist/config/style.js.map +0 -1
- package/dist/config/variables.d.ts +0 -5
- package/dist/config/variables.js +0 -11
- package/dist/config/variables.js.map +0 -1
- package/dist/define-config.d.ts +0 -1
- package/dist/define-config.js +0 -17
- package/dist/define-config.js.map +0 -1
- package/dist/globals.d.ts +0 -8
- package/dist/globals.js +0 -17
- package/dist/globals.js.map +0 -1
- package/dist/index.js +0 -26
- package/dist/index.js.map +0 -1
- package/dist/postinstall.d.ts +0 -1
- package/dist/postinstall.js +0 -79
- package/dist/postinstall.js.map +0 -1
- package/dist/typescript-type-checking.d.ts +0 -5
- package/dist/typescript-type-checking.js +0 -13
- package/dist/typescript-type-checking.js.map +0 -1
- package/skip.js +0 -7
package/README.md
CHANGED
|
@@ -20,608 +20,527 @@
|
|
|
20
20
|
|
|
21
21
|
## Purpose
|
|
22
22
|
|
|
23
|
-
Our package serves as a valuable resource for JavaScript/Typescript-based projects, offering composable [ESLint](https://eslint.org/) configurations. It encompasses a range of features, including performance optimization and the flexibility to extend pre-defined base configurations.
|
|
23
|
+
Our package serves as a valuable resource for JavaScript/Typescript-based projects, offering composable [ESLint](https://eslint.org/) configurations. It encompasses a range of features, including performance optimization and the flexibility to extend pre-defined base configurations. We aim to provide a strong, opinionated foundation for code quality and consistency, while still allowing for customization to suit specific project needs.
|
|
24
24
|
|
|
25
|
-
-
|
|
25
|
+
- Tailored Configuration for Workspaces: With this package, each workspace within your monorepo gains the ability to have its own customized ESLint configuration. This ensures that individual projects can maintain their specific requirements while still adhering to the overall guidelines.
|
|
26
|
+
- Configurability at Your Fingertips: Crafting your workspace's ESLint configuration is a breeze, thanks to the seamless composition of pre-defined base configurations. This empowers you to tailor the settings to suit your project's unique needs, without starting from scratch.
|
|
26
27
|
|
|
27
|
-
-
|
|
28
|
+
- Enhanced Efficiency: We've optimized the package's performance by intelligently enabling plugins based on file naming conventions and project dependencies. This streamlined approach ensures that your ESLint checks run efficiently, targeting the relevant files and maximizing productivity.
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
> [!NOTE]
|
|
31
|
+
> Since v16.0.0, this config is rewritten to the new [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new).
|
|
32
|
+
>
|
|
33
|
+
> ESLint v9.5.0+ is now required.
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
> [!WARNING]
|
|
36
|
+
>
|
|
37
|
+
> Please keep in mind that this is still **_a personal config_** with a lot of opinions. Changes might not always work for everyone and every use case.
|
|
38
|
+
>
|
|
39
|
+
> If you are using this config directly, I suggest you **review the changes every time you update**. Or if you want more control over the rules, always feel free to fork it. Thanks!
|
|
34
40
|
|
|
35
41
|
## Highlights
|
|
36
42
|
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
43
|
+
- Zero-config for many common setups, but highly configurable when needed.
|
|
44
|
+
- Enforces readable and consistent code, because you read more code than you write.
|
|
45
|
+
- Lints a wide range of files, including JavaScript, TypeScript, JSON, YAML, Markdown, and more.
|
|
46
|
+
- No need to specify file paths to lint as it intelligently lints relevant files, respecting `.gitignore` and common ignore patterns.
|
|
47
|
+
- Config overrides per files/globs.
|
|
48
|
+
- First-class TypeScript support, automatically enabled if `typescript` is detected in your project.
|
|
49
|
+
- Includes a comprehensive set of ESLint plugins, like [unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn), [import](https://github.com/benmosher/eslint-plugin-import), [sonarjs](https://github.com/SonarSource/eslint-plugin-sonarjs), and [security](#security) plugins. (See more under [Plugins](#plugins)).
|
|
50
|
+
- Automatically enables relevant rules based on the [engines](https://docs.npmjs.com/files/package.json#engines) field in your `package.json`.
|
|
51
|
+
- Easily configure stylistic preferences like indent and semicolon without deep diving into rule configurations.
|
|
52
|
+
- Works alongside Prettier: Our configuration disables ESLint rules that would conflict with Prettier, allowing ESLint to focus on code quality and Prettier on formatting if you choose to use both. However, many stylistic rules are included and can be enforced by ESLint directly.
|
|
47
53
|
|
|
48
54
|
## Install
|
|
49
55
|
|
|
50
56
|
To install this config, run the following command.
|
|
51
57
|
|
|
52
|
-
> Note: `eslint-plugin-import@npm:eslint-plugin-i` is needed to use the correct package.
|
|
53
|
-
|
|
54
58
|
```bash
|
|
55
|
-
npm install --save-dev eslint @anolilab/eslint-config
|
|
59
|
+
npm install --save-dev eslint @anolilab/eslint-config
|
|
56
60
|
```
|
|
57
61
|
|
|
58
62
|
```sh
|
|
59
|
-
pnpm add -D eslint @anolilab/eslint-config
|
|
63
|
+
pnpm add -D eslint @anolilab/eslint-config
|
|
60
64
|
```
|
|
61
65
|
|
|
62
66
|
```sh
|
|
63
|
-
yarn add -D eslint @anolilab/eslint-config
|
|
67
|
+
yarn add -D eslint @anolilab/eslint-config
|
|
64
68
|
```
|
|
65
69
|
|
|
66
70
|
## Usage
|
|
67
71
|
|
|
68
|
-
|
|
72
|
+
Our default export is designed to be used within ESLint's flat configuration system (e.g., `eslint.config.js`). It contains a comprehensive set of ESLint rules, suitable for modern ECMAScript (ES2021+ by default) and TypeScript projects.
|
|
69
73
|
|
|
70
|
-
|
|
74
|
+
To use it, import the `createConfig` function from `@anolilab/eslint-config` into your `eslint.config.js` (or `eslint.config.mjs`). This function allows you to generate the configuration, optionally with your own settings.
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
> Note: It can happen that the postinstall script don't run, then you have to add the `.eslintrc.js` manually, or you will use bin command `./node_modules/bin/anolilab-eslint-config` to generate it.
|
|
75
|
-
|
|
76
|
-
> Note: Our default export contains all of our ESLint rules, including ECMAScript 6+. `@anolilab/eslint-config` use the `ecmaVersion`:`2021` as default.
|
|
77
|
-
>
|
|
78
|
-
> To change this configuration, change `env: { es2021: false, then active you needed env }` same for, `parserOptions: { "ecmaVersion": 2021 change the version }`
|
|
76
|
+
Create `eslint.config.mjs` in your project root:
|
|
79
77
|
|
|
80
78
|
```js
|
|
81
|
-
|
|
82
|
-
const { defineConfig } = require('@anolilab/eslint-config/define-config');
|
|
83
|
-
|
|
84
|
-
/// <reference types="@eslint-types/unicorn" />
|
|
85
|
-
/// <reference types="@eslint-types/typescript-eslint" />
|
|
86
|
-
/// <reference types="@eslint-types/jsdoc" />
|
|
87
|
-
/// <reference types="@eslint-types/import" />
|
|
88
|
-
/// <reference types="@eslint-types/deprecation" />
|
|
89
|
-
|
|
90
|
-
module.exports = defineConfig({
|
|
91
|
-
env: {
|
|
92
|
-
// Your environments (which contains several predefined global variables)
|
|
93
|
-
//
|
|
94
|
-
// browser: true,
|
|
95
|
-
// node: true,
|
|
96
|
-
// mocha: true,
|
|
97
|
-
// jest: true,
|
|
98
|
-
// jquery: true
|
|
99
|
-
},
|
|
100
|
-
extends: ["@anolilab/eslint-config"],
|
|
101
|
-
globals: {
|
|
102
|
-
// Your global variables (setting to false means it's not allowed to be reassigned)
|
|
103
|
-
//
|
|
104
|
-
// myGlobal: false
|
|
105
|
-
},
|
|
106
|
-
root: true,
|
|
107
|
-
rules: {
|
|
108
|
-
// Customize your rules
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
For more advanced use cases see the example configurations for Node, TypeScript, React or Prettier.
|
|
114
|
-
|
|
115
|
-
> Note: `@anolilab/eslint-config` will handle the configuration for almost all eslint-plugins / eslint-configs automatically.
|
|
116
|
-
> With this you only need to install the needed plugins/configs for TypeScript or React and you done.
|
|
79
|
+
// eslint.config.mjs
|
|
117
80
|
|
|
118
|
-
|
|
81
|
+
import { createConfig } from "@anolilab/eslint-config";
|
|
119
82
|
|
|
120
|
-
|
|
121
|
-
npm install --save-dev typescript
|
|
83
|
+
export default createConfig();
|
|
122
84
|
```
|
|
123
85
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
parserOptions: {
|
|
129
|
-
project: "./tsconfig.eslint.json",
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
```
|
|
86
|
+
<details>
|
|
87
|
+
<summary>
|
|
88
|
+
Combined with legacy config:
|
|
89
|
+
</summary>
|
|
133
90
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
Extend the `.eslintrc.js` file:
|
|
91
|
+
If you still use some configs from the legacy eslintrc format, you can use the [`@eslint/eslintrc`](https://www.npmjs.com/package/@eslint/eslintrc) package to convert them to the flat config.
|
|
137
92
|
|
|
138
93
|
```js
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
/// <reference types="@eslint-types/unicorn" />
|
|
143
|
-
/// <reference types="@eslint-types/typescript-eslint" />
|
|
144
|
-
/// <reference types="@eslint-types/jsdoc" />
|
|
145
|
-
/// <reference types="@eslint-types/import" />
|
|
146
|
-
/// <reference types="@eslint-types/deprecation" />
|
|
147
|
-
|
|
148
|
-
module.exports = defineConfig({
|
|
149
|
-
env: {
|
|
150
|
-
// Your environments (which contains several predefined global variables)
|
|
151
|
-
//
|
|
152
|
-
// browser: true,
|
|
153
|
-
// node: true,
|
|
154
|
-
// mocha: true,
|
|
155
|
-
// jest: true,
|
|
156
|
-
// jquery: true
|
|
157
|
-
},
|
|
158
|
-
extends: ["@anolilab/eslint-config", "@anolilab/eslint-config/typescript-type-checking"],
|
|
159
|
-
globals: {
|
|
160
|
-
// Your global variables (setting to false means it's not allowed to be reassigned)
|
|
161
|
-
//
|
|
162
|
-
// myGlobal: false
|
|
163
|
-
},
|
|
164
|
-
root: true,
|
|
165
|
-
rules: {
|
|
166
|
-
// Customize your rules
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
> Tip: Run eslint with the TIMING=1 to identify slow rules.
|
|
172
|
-
>
|
|
173
|
-
> `TIMING=1 eslint . --ext .ts,.tsx`
|
|
174
|
-
>
|
|
175
|
-
> This is useful to identify rules that are slow because they require type information.
|
|
176
|
-
|
|
177
|
-
### React
|
|
94
|
+
// eslint.config.mjs
|
|
95
|
+
import { createConfig } from "@anolilab/eslint-config";
|
|
96
|
+
import { FlatCompat } from "@eslint/eslintrc";
|
|
178
97
|
|
|
179
|
-
|
|
98
|
+
const compat = new FlatCompat();
|
|
180
99
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
yarn add -D eslint-plugin-react eslint-plugin-react-hooks
|
|
185
|
-
|
|
186
|
-
pnpm add -D eslint-plugin-react eslint-plugin-react-hooks
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
Or for the use of `TypeScript` in react install "typescript" as a dev dependency.
|
|
190
|
-
|
|
191
|
-
Please extend the `.eslintrc.js` file with the correct `tsconfig.js` path if you have a custom path.
|
|
192
|
-
|
|
193
|
-
```js
|
|
194
|
-
module.exports = {
|
|
195
|
-
parserOptions: {
|
|
196
|
-
project: "./tsconfig.eslint.json",
|
|
100
|
+
export default createConfig(
|
|
101
|
+
{
|
|
102
|
+
ignores: [],
|
|
197
103
|
},
|
|
198
|
-
};
|
|
199
|
-
```
|
|
200
104
|
|
|
201
|
-
|
|
105
|
+
// Legacy config
|
|
106
|
+
...compat.config({
|
|
107
|
+
extends: [
|
|
108
|
+
"eslint:recommended",
|
|
109
|
+
// Other extends...
|
|
110
|
+
],
|
|
111
|
+
})
|
|
202
112
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
yarn add -D babel @babel/plugin-syntax-jsx
|
|
207
|
-
|
|
208
|
-
pnpm add -D babel @babel/plugin-syntax-jsx
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
In your `babel.config.js` file add the plugin.
|
|
212
|
-
|
|
213
|
-
```js
|
|
214
|
-
const babelPluginSyntaxJSX = require("@babel/plugin-syntax-jsx");
|
|
215
|
-
|
|
216
|
-
module.exports = {
|
|
217
|
-
plugins: [
|
|
218
|
-
[
|
|
219
|
-
babelPluginSyntaxJSX,
|
|
220
|
-
{
|
|
221
|
-
pragma: "React.createElement",
|
|
222
|
-
pragmaFrag: "React.Fragment",
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
],
|
|
226
|
-
};
|
|
113
|
+
// Other flat configs...
|
|
114
|
+
);
|
|
227
115
|
```
|
|
228
116
|
|
|
229
|
-
|
|
117
|
+
> Note that `.eslintignore` no longer works in Flat config.
|
|
230
118
|
|
|
231
|
-
|
|
232
|
-
npm install --save-dev eslint eslint-plugin-mdx
|
|
233
|
-
```
|
|
119
|
+
</details>
|
|
234
120
|
|
|
235
|
-
|
|
121
|
+
Or you can configure each integration individually, for example:
|
|
236
122
|
|
|
237
|
-
|
|
123
|
+
```js
|
|
124
|
+
// eslint.config.js
|
|
125
|
+
import { createConfig } from "@anolilab/eslint-config";
|
|
238
126
|
|
|
239
|
-
|
|
127
|
+
export default createConfig({
|
|
128
|
+
// Enable stylistic formatting rules
|
|
129
|
+
// stylistic: true,
|
|
240
130
|
|
|
241
|
-
|
|
131
|
+
// `.eslintignore` is no longer supported in Flat config, use `ignores` instead
|
|
132
|
+
ignores: [
|
|
133
|
+
"**/fixtures",
|
|
134
|
+
// ...globs
|
|
135
|
+
],
|
|
242
136
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
137
|
+
// Disable jsonc and yaml support
|
|
138
|
+
jsonc: false,
|
|
139
|
+
// Or customize the stylistic rules
|
|
140
|
+
stylistic: {
|
|
141
|
+
indent: 2, // 4, or 'tab'
|
|
142
|
+
quotes: "single", // or 'double'
|
|
249
143
|
},
|
|
250
|
-
}
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
#### indent
|
|
254
|
-
|
|
255
|
-
Type: `number`
|
|
256
|
-
|
|
257
|
-
Default: `4`
|
|
258
144
|
|
|
259
|
-
|
|
145
|
+
// TypeScript and Vue are autodetected, you can also explicitly enable them:
|
|
146
|
+
typescript: true,
|
|
147
|
+
vue: true,
|
|
260
148
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
Type: `object` -> key: `string` value: `boolean`
|
|
264
|
-
|
|
265
|
-
Disable a plugin in your package.json config to turn it off globally in your project.
|
|
266
|
-
|
|
267
|
-
Example using package.json:
|
|
268
|
-
|
|
269
|
-
```json
|
|
270
|
-
{
|
|
271
|
-
"anolilab": {
|
|
272
|
-
"eslint-config": {
|
|
273
|
-
"plugin": {
|
|
274
|
-
"unicorn": false
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
149
|
+
yaml: false
|
|
150
|
+
});
|
|
279
151
|
```
|
|
280
152
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
Type: `boolean`
|
|
153
|
+
### Add script for package.json
|
|
284
154
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
To disable the warning, set the value to `false`.
|
|
155
|
+
For example:
|
|
288
156
|
|
|
289
157
|
```json
|
|
290
158
|
{
|
|
291
|
-
"
|
|
292
|
-
"
|
|
293
|
-
|
|
294
|
-
}
|
|
159
|
+
"scripts": {
|
|
160
|
+
"lint": "eslint .",
|
|
161
|
+
"lint:fix": "eslint . --fix"
|
|
295
162
|
}
|
|
296
163
|
}
|
|
297
164
|
```
|
|
298
165
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
Type: `boolean`
|
|
166
|
+
The factory function also accepts any number of arbitrary custom config overrides:
|
|
302
167
|
|
|
303
|
-
|
|
168
|
+
```js
|
|
169
|
+
// eslint.config.js
|
|
170
|
+
import { createConfig } from "@anolilab/eslint-config";
|
|
304
171
|
|
|
305
|
-
|
|
172
|
+
export default createConfig(
|
|
173
|
+
{
|
|
174
|
+
// Configures for anolilab's config
|
|
175
|
+
},
|
|
306
176
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
"
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
177
|
+
// From the second arguments they are ESLint Flat Configs
|
|
178
|
+
// you can have multiple configs
|
|
179
|
+
{
|
|
180
|
+
files: ["**/*.ts"],
|
|
181
|
+
rules: {},
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
rules: {},
|
|
185
|
+
},
|
|
186
|
+
);
|
|
315
187
|
```
|
|
316
188
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
Type: `boolean`
|
|
320
|
-
|
|
321
|
-
Default: `undefined`
|
|
189
|
+
We also provided the `overrides` options in each integration to make it easier:
|
|
322
190
|
|
|
323
|
-
|
|
191
|
+
```js
|
|
192
|
+
// eslint.config.js
|
|
193
|
+
import { createConfig } from "@anolilab/eslint-config";
|
|
324
194
|
|
|
325
|
-
|
|
326
|
-
{
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
195
|
+
export default createConfig({
|
|
196
|
+
typescript: {
|
|
197
|
+
overrides: {
|
|
198
|
+
"ts/consistent-type-definitions": ["error", "interface"],
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
yaml: {
|
|
202
|
+
overrides: {
|
|
203
|
+
// ...
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
});
|
|
333
207
|
```
|
|
334
208
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
Type: `boolean`
|
|
338
|
-
|
|
339
|
-
Default: `undefined`
|
|
340
|
-
|
|
341
|
-
To disable the info, set the value to `false`.
|
|
342
|
-
|
|
343
|
-
```json
|
|
344
|
-
{
|
|
345
|
-
"anolilab": {
|
|
346
|
-
"eslint-config": {
|
|
347
|
-
"info_on_disabling_jsonc_sort_keys_rule": false
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
```
|
|
209
|
+
## IDE Support (auto fix on save)
|
|
352
210
|
|
|
353
|
-
|
|
211
|
+
<details>
|
|
212
|
+
<summary>🟦 VS Code support</summary>
|
|
354
213
|
|
|
355
|
-
|
|
214
|
+
<br>
|
|
356
215
|
|
|
357
|
-
|
|
216
|
+
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
358
217
|
|
|
359
|
-
|
|
218
|
+
Add the following settings to your `.vscode/settings.json`:
|
|
360
219
|
|
|
361
|
-
```
|
|
220
|
+
```jsonc
|
|
362
221
|
{
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
#### info_on_testing_library_framework
|
|
222
|
+
// Disable the default formatter, use eslint instead
|
|
223
|
+
"prettier.enable": false,
|
|
224
|
+
"editor.formatOnSave": false,
|
|
372
225
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
226
|
+
// Auto fix
|
|
227
|
+
"editor.codeActionsOnSave": {
|
|
228
|
+
"source.fixAll.eslint": "explicit",
|
|
229
|
+
"source.organizeImports": "never"
|
|
230
|
+
},
|
|
376
231
|
|
|
377
|
-
|
|
232
|
+
// Silent the stylistic rules in you IDE, but still auto fix them
|
|
233
|
+
"eslint.rules.customizations": [
|
|
234
|
+
{ "rule": "style/*", "severity": "off", "fixable": true },
|
|
235
|
+
{ "rule": "format/*", "severity": "off", "fixable": true },
|
|
236
|
+
{ "rule": "*-indent", "severity": "off", "fixable": true },
|
|
237
|
+
{ "rule": "*-spacing", "severity": "off", "fixable": true },
|
|
238
|
+
{ "rule": "*-spaces", "severity": "off", "fixable": true },
|
|
239
|
+
{ "rule": "*-order", "severity": "off", "fixable": true },
|
|
240
|
+
{ "rule": "*-dangle", "severity": "off", "fixable": true },
|
|
241
|
+
{ "rule": "*-newline", "severity": "off", "fixable": true },
|
|
242
|
+
{ "rule": "*quotes", "severity": "off", "fixable": true },
|
|
243
|
+
{ "rule": "*semi", "severity": "off", "fixable": true }
|
|
244
|
+
],
|
|
378
245
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
"
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
246
|
+
// Enable eslint for all supported languages
|
|
247
|
+
"eslint.validate": [
|
|
248
|
+
"javascript",
|
|
249
|
+
"javascriptreact",
|
|
250
|
+
"typescript",
|
|
251
|
+
"typescriptreact",
|
|
252
|
+
"vue",
|
|
253
|
+
"html",
|
|
254
|
+
"markdown",
|
|
255
|
+
"json",
|
|
256
|
+
"jsonc",
|
|
257
|
+
"yaml",
|
|
258
|
+
"toml",
|
|
259
|
+
"xml",
|
|
260
|
+
"gql",
|
|
261
|
+
"graphql",
|
|
262
|
+
"astro",
|
|
263
|
+
"svelte",
|
|
264
|
+
"css",
|
|
265
|
+
"less",
|
|
266
|
+
"scss",
|
|
267
|
+
"pcss",
|
|
268
|
+
"postcss"
|
|
269
|
+
]
|
|
386
270
|
}
|
|
387
271
|
```
|
|
388
272
|
|
|
389
|
-
|
|
273
|
+
</details>
|
|
390
274
|
|
|
391
|
-
|
|
275
|
+
<details>
|
|
276
|
+
<summary>🟩 Neovim Support</summary>
|
|
392
277
|
|
|
393
|
-
|
|
278
|
+
<br>
|
|
394
279
|
|
|
395
|
-
|
|
280
|
+
Update your configuration to use the following:
|
|
396
281
|
|
|
397
|
-
```
|
|
398
|
-
{
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
282
|
+
```lua
|
|
283
|
+
local customizations = {
|
|
284
|
+
{ rule = 'style/*', severity = 'off', fixable = true },
|
|
285
|
+
{ rule = 'format/*', severity = 'off', fixable = true },
|
|
286
|
+
{ rule = '*-indent', severity = 'off', fixable = true },
|
|
287
|
+
{ rule = '*-spacing', severity = 'off', fixable = true },
|
|
288
|
+
{ rule = '*-spaces', severity = 'off', fixable = true },
|
|
289
|
+
{ rule = '*-order', severity = 'off', fixable = true },
|
|
290
|
+
{ rule = '*-dangle', severity = 'off', fixable = true },
|
|
291
|
+
{ rule = '*-newline', severity = 'off', fixable = true },
|
|
292
|
+
{ rule = '*quotes', severity = 'off', fixable = true },
|
|
293
|
+
{ rule = '*semi', severity = 'off', fixable = true },
|
|
404
294
|
}
|
|
405
|
-
```
|
|
406
295
|
|
|
407
|
-
|
|
296
|
+
local lspconfig = require('lspconfig')
|
|
297
|
+
-- Enable eslint for all supported languages
|
|
298
|
+
lspconfig.eslint.setup(
|
|
299
|
+
{
|
|
300
|
+
filetypes = {
|
|
301
|
+
"javascript",
|
|
302
|
+
"javascriptreact",
|
|
303
|
+
"javascript.jsx",
|
|
304
|
+
"typescript",
|
|
305
|
+
"typescriptreact",
|
|
306
|
+
"typescript.tsx",
|
|
307
|
+
"vue",
|
|
308
|
+
"html",
|
|
309
|
+
"markdown",
|
|
310
|
+
"json",
|
|
311
|
+
"jsonc",
|
|
312
|
+
"yaml",
|
|
313
|
+
"toml",
|
|
314
|
+
"xml",
|
|
315
|
+
"gql",
|
|
316
|
+
"graphql",
|
|
317
|
+
"astro",
|
|
318
|
+
"svelte",
|
|
319
|
+
"css",
|
|
320
|
+
"less",
|
|
321
|
+
"scss",
|
|
322
|
+
"pcss",
|
|
323
|
+
"postcss"
|
|
324
|
+
},
|
|
325
|
+
settings = {
|
|
326
|
+
-- Silent the stylistic rules in you IDE, but still auto fix them
|
|
327
|
+
rulesCustomizations = customizations,
|
|
328
|
+
},
|
|
329
|
+
}
|
|
330
|
+
)
|
|
331
|
+
```
|
|
408
332
|
|
|
409
|
-
|
|
333
|
+
### Neovim format on save
|
|
410
334
|
|
|
411
|
-
|
|
335
|
+
There's few ways you can achieve format on save in neovim:
|
|
412
336
|
|
|
413
|
-
|
|
337
|
+
- `nvim-lspconfig` has a `EslintFixAll` command predefined, you can create a autocmd to call this command after saving file.
|
|
414
338
|
|
|
415
|
-
```
|
|
416
|
-
{
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
339
|
+
```lua
|
|
340
|
+
lspconfig.eslint.setup({
|
|
341
|
+
--- ...
|
|
342
|
+
on_attach = function(client, bufnr)
|
|
343
|
+
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
344
|
+
buffer = bufnr,
|
|
345
|
+
command = "EslintFixAll",
|
|
346
|
+
})
|
|
347
|
+
end,
|
|
348
|
+
})
|
|
423
349
|
```
|
|
424
350
|
|
|
425
|
-
|
|
351
|
+
- Use [conform.nvim](https://github.com/stevearc/conform.nvim).
|
|
352
|
+
- Use [none-ls](https://github.com/nvimtools/none-ls.nvim)
|
|
353
|
+
- Use [nvim-lint](https://github.com/mfussenegger/nvim-lint)
|
|
426
354
|
|
|
427
|
-
|
|
355
|
+
</details>
|
|
428
356
|
|
|
429
|
-
|
|
430
|
-
so we completely removed all Prettier related rules, if `prettier` is found in your `package.json` and use ESLint to check logical errors which it’s good at.
|
|
357
|
+
## Plugins
|
|
431
358
|
|
|
432
|
-
|
|
433
|
-
Of course, we also provide a recommended Prettier [configuration](../prettier-config/README.md) for your reference.
|
|
359
|
+
Our configuration integrates a wide array of ESLint plugins to cover various aspects of code quality, language support, security, and specific libraries/frameworks. Many of these are enabled automatically when relevant dependencies are detected in your project.
|
|
434
360
|
|
|
435
|
-
|
|
361
|
+
### Core & Code Quality
|
|
436
362
|
|
|
437
|
-
|
|
363
|
+
These plugins form the backbone of our linting rules, focusing on best practices, consistency, and potential errors.
|
|
438
364
|
|
|
439
|
-
|
|
365
|
+
- **[@eslint/js](https://www.npmjs.com/package/@eslint/js)**: Core ESLint rules.
|
|
366
|
+
- **[eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn)**: Various awesome ESLint rules.
|
|
367
|
+
- **[eslint-plugin-sonarjs](https://github.com/SonarSource/eslint-plugin-sonarjs)**: Rules to detect bugs and code smells.
|
|
368
|
+
- **[eslint-plugin-promise](https://github.com/eslint-community/eslint-plugin-promise)**: Enforce best practices for JavaScript promises.
|
|
369
|
+
- **[eslint-plugin-es-x](https://github.com/eslint-community/eslint-plugin-es-x)** (formerly `eslint-plugin-es`): Prevent ES6+ syntax from being used in ES5 environments.
|
|
370
|
+
- **[eslint-plugin-antfu](https://github.com/antfu/eslint-config)**: Opinionated linting rules by Anthony Fu.
|
|
371
|
+
- **[eslint-plugin-perfectionist](https://github.com/azat-io/eslint-plugin-perfectionist)**: Rules for sorting and ordering various data structures.
|
|
372
|
+
- **[eslint-plugin-no-for-of-array](https://github.com/smelukov/eslint-plugin-no-for-of-array)**: Disallow `for...of` loops on arrays (promoting array methods).
|
|
373
|
+
- **[eslint-plugin-unused-imports](https://github.com/sweepline/eslint-plugin-unused-imports)**: Find and remove unused ES6 imports.
|
|
440
374
|
|
|
441
|
-
|
|
442
|
-
npm install --save-dev @babel/core
|
|
443
|
-
```
|
|
375
|
+
### Stylistic & Formatting
|
|
444
376
|
|
|
445
|
-
|
|
377
|
+
These plugins help maintain a consistent code style. Note that while these are included, you can also use Prettier for formatting, and our config is designed to be compatible.
|
|
446
378
|
|
|
447
|
-
|
|
379
|
+
- **[@stylistic/eslint-plugin](https://eslint.style/packages/default)** (and `@stylistic/eslint-plugin-ts`): ESLint Stylistic, for all stylistic rules.
|
|
380
|
+
- **[eslint-plugin-simple-import-sort](https://github.com/lydell/eslint-plugin-simple-import-sort)**: Easy import sorting.
|
|
381
|
+
- **[eslint-plugin-format](https://github.com/antfu/eslint-plugin-format)**: Enables formatting of various file types using Prettier or other formatters via ESLint.
|
|
448
382
|
|
|
449
|
-
|
|
383
|
+
### Language Support & Syntax
|
|
450
384
|
|
|
451
|
-
|
|
452
|
-
- [eslint-plugin-antfu](https://github.com/antfu/eslint-config)
|
|
385
|
+
Plugins for specific languages or syntaxes beyond standard JavaScript/TypeScript.
|
|
453
386
|
|
|
454
|
-
|
|
387
|
+
- **[@typescript-eslint/eslint-plugin](https://typescript-eslint.io/)**: The tooling that enables ESLint to lint TypeScript code.
|
|
388
|
+
- **[eslint-plugin-jsonc](https://github.com/ota-meshi/eslint-plugin-jsonc)**: ESLint plugin for JSON, JSONC, and JSON5 files.
|
|
389
|
+
- **[eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml)**: ESLint plugin for YAML files.
|
|
390
|
+
- **[eslint-plugin-toml](https://github.com/ota-meshi/eslint-plugin-toml)**: ESLint plugin for TOML files.
|
|
391
|
+
- **[eslint-plugin-html](https://github.com/BenoitZugmeyer/eslint-plugin-html)**: An ESLint plugin to extract and lint script tags from HTML files.
|
|
392
|
+
- **[@html-eslint/eslint-plugin](https://html-eslint.org/)**: Alternative ESLint plugin for HTML files.
|
|
393
|
+
- **[@eslint/markdown](https://www.npmjs.com/package/@eslint/markdown)**: Lint JavaScript code blocks in Markdown documents.
|
|
394
|
+
- **[eslint-plugin-astro](https://github.com/ota-meshi/eslint-plugin-astro)**: ESLint plugin for Astro components.
|
|
455
395
|
|
|
456
|
-
|
|
396
|
+
### Import & Module System
|
|
457
397
|
|
|
458
|
-
|
|
459
|
-
- [eslint-plugin-jsonc](https://github.com/ota-meshi/eslint-plugin-jsonc)
|
|
460
|
-
- [eslint-plugin-markdown](https://github.com/eslint/eslint-plugin-markdown)
|
|
461
|
-
- [eslint-plugin-mdx](https://github.com/mdx-js/eslint-mdx)
|
|
462
|
-
- [eslint-plugin-toml](https://github.com/ota-meshi/eslint-plugin-toml)
|
|
463
|
-
- [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml)
|
|
398
|
+
Managing imports and module structure.
|
|
464
399
|
|
|
465
|
-
|
|
400
|
+
- **[eslint-plugin-import-x](https://github.com/un-es/eslint-plugin-import-x)** (formerly `eslint-plugin-import`): Linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import names.
|
|
401
|
+
* Uses `eslint-import-resolver-node` and `eslint-import-resolver-typescript`.
|
|
402
|
+
- **[eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n)** (formerly `eslint-plugin-node`): Additional ESLint rules for Node.js.
|
|
466
403
|
|
|
467
|
-
###
|
|
404
|
+
### Security
|
|
468
405
|
|
|
469
|
-
|
|
406
|
+
Plugins focused on identifying potential security vulnerabilities.
|
|
470
407
|
|
|
471
|
-
- [eslint-plugin-
|
|
472
|
-
- [eslint-plugin-
|
|
473
|
-
|
|
474
|
-
- [eslint-plugin-lodash-fp](https://github.com/jfmengels/eslint-plugin-lodash-fp)
|
|
475
|
-
- You need to install `eslint-plugin-lodash-fp` and `lodash` to use this plugin.
|
|
476
|
-
- [eslint-plugin-react-redux](https://github.com/DianaSuvorova/eslint-plugin-react-redux#readme)
|
|
477
|
-
- You need to install `eslint-plugin-react-redux` and `react-redux` to use this plugin.
|
|
478
|
-
- [eslint-plugin-redux-saga](https://github.com/pke/eslint-plugin-redux-saga)
|
|
479
|
-
- You need to install `eslint-plugin-redux-saga` and `redux-saga` to use this plugin.
|
|
408
|
+
- **[eslint-plugin-security](https://github.com/eslint-community/eslint-plugin-security)**: ESLint rules for Node Security.
|
|
409
|
+
- **[eslint-plugin-no-secrets](https://github.com/nickdeis/eslint-plugin-no-secrets)**: An ESLint plugin that detects potential secrets/credentials.
|
|
410
|
+
- **[eslint-plugin-no-unsanitized](https://github.com/mozilla/eslint-plugin-no-unsanitized)**: ESLint plugin for security related rules regarding untrusted input.
|
|
480
411
|
|
|
481
|
-
###
|
|
412
|
+
### Testing
|
|
482
413
|
|
|
483
|
-
|
|
414
|
+
Plugins for various testing frameworks and practices.
|
|
484
415
|
|
|
485
|
-
- [eslint-plugin-
|
|
486
|
-
- [eslint-plugin-
|
|
487
|
-
- [eslint-plugin-
|
|
488
|
-
- [eslint-plugin-no-loops](https://github.com/buildo/eslint-plugin-no-loops)
|
|
489
|
-
- [eslint-plugin-simple-import-sort](https://github.com/lydell/eslint-plugin-simple-import-sort)
|
|
490
|
-
- [eslint-plugin-es-x](https://github.com/eslint-community/eslint-plugin-es-x)
|
|
416
|
+
- **[eslint-plugin-no-only-tests](https://github.com/levibuzolic/eslint-plugin-no-only-tests)**: Disallow `.only` calls in test files.
|
|
417
|
+
- **[eslint-plugin-testing-library](https://github.com/testing-library/eslint-plugin-testing-library)**: ESLint plugin for Testing Library.
|
|
418
|
+
- **[eslint-plugin-playwright](https://github.com/playwright-community/eslint-plugin-playwright)**: ESLint plugin for Playwright.
|
|
491
419
|
|
|
492
|
-
###
|
|
420
|
+
### Frameworks & Libraries
|
|
493
421
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
- [eslint-plugin-no-secrets](https://github.com/nickdeis/eslint-plugin-no-secrets)
|
|
497
|
-
- [eslint-plugin-no-unsanitized](https://github.com/mozilla/eslint-plugin-no-unsanitized)
|
|
498
|
-
- [eslint-plugin-sonarjs](https://github.com/SonarSource/eslint-plugin-sonarjs)
|
|
499
|
-
- [eslint-plugin-security](https://github.com/eslint-community/eslint-plugin-security)
|
|
500
|
-
- [rushstack/eslint-plugin-security](https://www.npmjs.com/package/@rushstack/eslint-plugin-security)
|
|
501
|
-
|
|
502
|
-
### Test Libraries
|
|
503
|
-
|
|
504
|
-
The following test plugins are supported:
|
|
505
|
-
|
|
506
|
-
- [eslint-plugin-ava](https://github.com/avajs/eslint-plugin-ava)
|
|
507
|
-
- You need to install `eslint-plugin-ava` and `ava` to use this plugin.
|
|
508
|
-
- [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest)
|
|
509
|
-
- You need to install `eslint-plugin-jest` and `jest` to use this plugin.
|
|
510
|
-
- [eslint-plugin-jest-async](https://www.npmjs.com/package/eslint-plugin-jest-async)
|
|
511
|
-
- You need to install `eslint-plugin-jest-async` and `jest` to use this plugin.
|
|
512
|
-
- [eslint-plugin-cypress](https://github.com/cypress-io/eslint-plugin-cypress)
|
|
513
|
-
- You need to install `eslint-plugin-cypress` and `cypress` to use this plugin.
|
|
514
|
-
|
|
515
|
-
### List of used plugins
|
|
516
|
-
|
|
517
|
-
- eslint-plugin-security
|
|
518
|
-
- @rushstack/eslint-plugin-security
|
|
519
|
-
- @typescript-eslint/eslint-plugin
|
|
520
|
-
- eslint-plugin-antfu
|
|
521
|
-
- eslint-plugin-compat
|
|
522
|
-
- eslint-plugin-es-x
|
|
523
|
-
- eslint-plugin-eslint-comments
|
|
524
|
-
- eslint-plugin-html
|
|
525
|
-
- eslint-plugin-i
|
|
526
|
-
- eslint-plugin-jsonc
|
|
527
|
-
- eslint-plugin-markdown
|
|
528
|
-
- eslint-plugin-mdx
|
|
529
|
-
- eslint-plugin-no-loops
|
|
530
|
-
- eslint-plugin-no-only-tests
|
|
531
|
-
- eslint-plugin-no-secrets
|
|
532
|
-
- eslint-plugin-no-use-extend-native
|
|
533
|
-
- eslint-plugin-promise
|
|
534
|
-
- eslint-plugin-regexp
|
|
535
|
-
- eslint-plugin-simple-import-sort
|
|
536
|
-
- eslint-plugin-sonarjs
|
|
537
|
-
- eslint-plugin-toml
|
|
538
|
-
- eslint-plugin-typescript-sort-keys
|
|
539
|
-
- eslint-plugin-unicorn
|
|
540
|
-
- eslint-plugin-yml
|
|
541
|
-
|
|
542
|
-
## Troubleshooting
|
|
543
|
-
|
|
544
|
-
### With VSCode
|
|
545
|
-
|
|
546
|
-
ESLint will not lint `.vue`, `.ts` or `.tsx` files in VSCode by default, you need to set your `.vscode/settings.json` like this:
|
|
422
|
+
Support for specific UI frameworks, libraries, and tools.
|
|
547
423
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
424
|
+
- **[@eslint-react/eslint-plugin](https://github.com/AriPerkkio/eslint-react)**: A comprehensive ESLint plugin for React.
|
|
425
|
+
- **[eslint-plugin-react-hooks](https://www.npmjs.com/package/eslint-plugin-react-hooks)**: ESLint rules for React Hooks.
|
|
426
|
+
- **[eslint-plugin-react-refresh](https://www.npmjs.com/package/eslint-plugin-react-refresh)**: Enforces best practices for React Fast Refresh.
|
|
427
|
+
- **[eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y)**: Static AST checker for accessibility rules on JSX elements.
|
|
428
|
+
- **[eslint-plugin-validate-jsx-nesting](https://github.com/TitTat/eslint-plugin-validate-jsx-nesting)**: Validate JSX element nesting.
|
|
429
|
+
- **[eslint-plugin-tailwindcss](https://github.com/francoismassart/eslint-plugin-tailwindcss)**: ESLint plugin for Tailwind CSS.
|
|
430
|
+
- **[eslint-plugin-storybook](https://github.com/storybookjs/eslint-plugin-storybook)**: Best practice rules for Storybook.
|
|
431
|
+
- **[@tanstack/eslint-plugin-query](https://tanstack.com/query/latest/docs/eslint/eslint-plugin-query)**: ESLint rules for TanStack Query.
|
|
432
|
+
- **[@tanstack/eslint-plugin-router](https://tanstack.com/router/latest/docs/eslint/eslint-plugin-router)**: ESLint rules for TanStack Router.
|
|
433
|
+
- **[@unocss/eslint-plugin](https://github.com/unocss/unocss/tree/main/packages/eslint-plugin)**: ESLint plugin for UnoCSS.
|
|
434
|
+
- **[eslint-plugin-zod](https://github.com/IsaacScript/eslint-plugin-zod)**: ESLint rules for Zod schemas.
|
|
435
|
+
- **[eslint-plugin-you-dont-need-lodash-underscore](https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore)**: Encourages use of native JavaScript methods over Lodash/Underscore.
|
|
553
436
|
|
|
554
|
-
|
|
437
|
+
### Documentation & Comments
|
|
555
438
|
|
|
556
|
-
|
|
439
|
+
- **[@eslint-community/eslint-plugin-eslint-comments](https://github.com/eslint-community/eslint-plugin-eslint-comments)** (formerly `eslint-plugin-eslint-comments`): Additional ESLint rules for ESLint directive comments (`/*eslint-...*/`).
|
|
440
|
+
- **[eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc)**: JSDoc specific linting rules.
|
|
441
|
+
- **[eslint-plugin-tsdoc](https://github.com/microsoft/tsdoc/tree/main/eslint-plugin)**: TSDoc specific linting rules.
|
|
557
442
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
}
|
|
566
|
-
```
|
|
443
|
+
### Compatibility & Others
|
|
444
|
+
|
|
445
|
+
- **[eslint-plugin-compat](https://github.com/amilajack/eslint-plugin-compat)**: Lint the browser compatibility of your code.
|
|
446
|
+
- **[eslint-config-flat-gitignore](https://github.com/antfu/eslint-config-flat-gitignore)**: Utility to use .gitignore in flat config.
|
|
447
|
+
- **[eslint-flat-config-utils](https://github.com/antfu/eslint-flat-config-utils)**: Utilities for working with ESLint flat config.
|
|
448
|
+
- **[eslint-merge-processors](https://github.com/eslint/eslint-merge-processors)**: Utility to merge ESLint processors.
|
|
449
|
+
- **[@eslint/compat](https://www.npmjs.com/package/@eslint/compat)**: Utilities for compatibility between ESLint flat config and eslintrc.
|
|
567
450
|
|
|
568
|
-
|
|
451
|
+
---
|
|
569
452
|
|
|
453
|
+
### List of Used Plugins (Condensed)
|
|
454
|
+
|
|
455
|
+
This list is a more condensed version and might not be exhaustive if some plugins are very specific or utility-based. It aims to provide a quick overview of the primary active linting plugins.
|
|
456
|
+
|
|
457
|
+
- `@eslint/js`
|
|
458
|
+
- `@stylistic/eslint-plugin`
|
|
459
|
+
- `@typescript-eslint/eslint-plugin`
|
|
460
|
+
- `@eslint-community/eslint-plugin-eslint-comments`
|
|
461
|
+
- `@eslint-react/eslint-plugin`
|
|
462
|
+
- `@tanstack/eslint-plugin-query`
|
|
463
|
+
- `@tanstack/eslint-plugin-router`
|
|
464
|
+
- `@unocss/eslint-plugin`
|
|
465
|
+
- `eslint-plugin-antfu`
|
|
466
|
+
- `eslint-plugin-astro`
|
|
467
|
+
- `eslint-plugin-compat`
|
|
468
|
+
- `eslint-plugin-es-x`
|
|
469
|
+
- `eslint-plugin-format`
|
|
470
|
+
- `eslint-plugin-html` (or `@html-eslint/eslint-plugin`)
|
|
471
|
+
- `eslint-plugin-import-x`
|
|
472
|
+
- `eslint-plugin-jsdoc`
|
|
473
|
+
- `eslint-plugin-jsonc`
|
|
474
|
+
- `eslint-plugin-jsx-a11y`
|
|
475
|
+
- `eslint-plugin-n`
|
|
476
|
+
- `eslint-plugin-no-only-tests`
|
|
477
|
+
- `eslint-plugin-no-secrets`
|
|
478
|
+
- `eslint-plugin-no-unsanitized`
|
|
479
|
+
- `eslint-plugin-perfectionist`
|
|
480
|
+
- `eslint-plugin-playwright`
|
|
481
|
+
- `eslint-plugin-promise`
|
|
482
|
+
- `eslint-plugin-react-hooks`
|
|
483
|
+
- `eslint-plugin-regexp` (often a dependency of other plugins like SonarJS)
|
|
484
|
+
- `eslint-plugin-security`
|
|
485
|
+
- `eslint-plugin-simple-import-sort`
|
|
486
|
+
- `eslint-plugin-sonarjs`
|
|
487
|
+
- `eslint-plugin-storybook`
|
|
488
|
+
- `eslint-plugin-tailwindcss`
|
|
489
|
+
- `eslint-plugin-testing-library`
|
|
490
|
+
- `eslint-plugin-toml`
|
|
491
|
+
- `eslint-plugin-tsdoc`
|
|
492
|
+
- `eslint-plugin-unicorn`
|
|
493
|
+
- `eslint-plugin-unused-imports`
|
|
494
|
+
- `eslint-plugin-yml`
|
|
495
|
+
- `eslint-plugin-zod`
|
|
496
|
+
- `eslint-plugin-you-dont-need-lodash-underscore`
|
|
497
|
+
|
|
498
|
+
## Our Stance on Formatting
|
|
499
|
+
|
|
500
|
+
This ESLint configuration includes stylistic rules that can format your JavaScript and TypeScript code, promoting consistency.
|
|
501
|
+
|
|
502
|
+
- **ESLint as the Primary Tool:** For JS/TS files, we encourage using ESLint for both linting code quality and enforcing code style. The VSCode settings above are configured to use ESLint as the default formatter for these files.
|
|
503
|
+
- **Working with Prettier:** If you use Prettier in your project, this config is designed to be compatible. It disables ESLint rules that would conflict with Prettier's formatting decisions. You can let Prettier handle formatting for files ESLint doesn't cover (like CSS, HTML, etc.), or even use Prettier for JS/TS formatting and then have ESLint apply further fixes. However, for a streamlined experience with JS/TS, letting ESLint handle all aspects (quality and style) is often simpler.
|
|
504
|
+
|
|
505
|
+
## Lint Staged / Pre-commit Hooks
|
|
506
|
+
|
|
507
|
+
To ensure code is linted and fixed before committing, we recommend integrating with a pre-commit tool like `lint-staged` and `husky`. Our sister package, `@anolilab/lint-staged-config`, is designed to work seamlessly with this ESLint configuration.
|
|
508
|
+
|
|
509
|
+
Example `lint-staged` configuration in your `package.json` (or relevant file):
|
|
570
510
|
```json
|
|
511
|
+
// package.json
|
|
571
512
|
{
|
|
572
|
-
"
|
|
573
|
-
"
|
|
574
|
-
|
|
575
|
-
"[html]": {
|
|
576
|
-
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
577
|
-
},
|
|
578
|
-
"[javascript]": {
|
|
579
|
-
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
580
|
-
},
|
|
581
|
-
"[javascriptreact]": {
|
|
582
|
-
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
583
|
-
},
|
|
584
|
-
"[json]": {
|
|
585
|
-
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
586
|
-
},
|
|
587
|
-
"[markdown]": {
|
|
588
|
-
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
589
|
-
},
|
|
590
|
-
"[typescript]": {
|
|
591
|
-
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
592
|
-
},
|
|
593
|
-
"[typescriptreact]": {
|
|
594
|
-
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
595
|
-
},
|
|
596
|
-
"[yaml]": {
|
|
597
|
-
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
513
|
+
"lint-staged": {
|
|
514
|
+
"*.{js,jsx,ts,tsx}": "eslint --fix"
|
|
515
|
+
// Add other linters for other file types if needed
|
|
598
516
|
}
|
|
599
517
|
}
|
|
600
518
|
```
|
|
519
|
+
Ensure `husky` is set up to run `lint-staged` on pre-commit.
|
|
601
520
|
|
|
602
|
-
|
|
521
|
+
## Versioning Policy
|
|
603
522
|
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
523
|
+
This project aims to follow Semantic Versioning.
|
|
524
|
+
|
|
525
|
+
- **Major versions:** May include breaking changes to ESLint configurations, Node.js version support, or significant plugin changes.
|
|
526
|
+
- **Minor versions:** May introduce new non-breaking rules, enable new plugins by default (if non-breaking), or update existing rules with new options.
|
|
527
|
+
- **Patch versions:** Typically include bug fixes or minor tweaks to rule configurations.
|
|
609
528
|
|
|
610
|
-
|
|
529
|
+
Changes to rule strictness (e.g., changing a 'warn' to an 'error') might occur in minor versions if they reflect evolving best practices. We recommend reviewing changes when updating.
|
|
611
530
|
|
|
612
531
|
## Q & A
|
|
613
532
|
|
|
614
533
|
### Why not standard
|
|
615
534
|
|
|
616
|
-
The standard specification believes that everyone should not waste time in personalized specifications, but the entire community should unify a specification. This statement makes sense, but it runs against the ESLint
|
|
617
|
-
Don
|
|
535
|
+
The standard specification believes that everyone should not waste time in personalized specifications, but the entire community should unify a specification. This statement makes sense, but it runs against the ESLint's design philosophy.
|
|
536
|
+
Don't you remember how ESLint defeated JSHint and became the most popular JS code inspection tool? It's because of the plugin and configuration that ESLint advocates, which meets the individual needs of different technology stacks of different teams.
|
|
618
537
|
|
|
619
538
|
Therefore, `@anolilab/eslint-config` also inherits the philosophy of ESLint. It will not force you to use our config.
|
|
620
539
|
|
|
621
540
|
## Supported Node.js Versions
|
|
622
541
|
|
|
623
542
|
Libraries in this ecosystem make the best effort to track
|
|
624
|
-
[Node.js
|
|
543
|
+
[Node.js' release schedule](https://nodejs.org/en/about/releases/). Here's [a
|
|
625
544
|
post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).
|
|
626
545
|
|
|
627
546
|
## Contributing
|
|
@@ -632,11 +551,12 @@ If you would like to help take a look at the [list of issues](https://github.com
|
|
|
632
551
|
|
|
633
552
|
## Credits
|
|
634
553
|
|
|
635
|
-
-
|
|
636
|
-
-
|
|
637
|
-
-
|
|
638
|
-
-
|
|
639
|
-
-
|
|
554
|
+
- [Daniel Bannert](https://github.com/prisis)
|
|
555
|
+
- [All Contributors](https://github.com/anolilab/javascript-style-guide/graphs/contributors)
|
|
556
|
+
- Inspired by and thankful for the work in configurations like:
|
|
557
|
+
- [eslint-config-airbnb](https://www.npmjs.com/package/eslint-config-airbnb)
|
|
558
|
+
- [eslint-config-canonical](https://github.com/gajus/eslint-config-canonical)
|
|
559
|
+
- [@antfu/eslint-config](https://github.com/antfu/eslint-config) (for its modern approach and clear documentation)
|
|
640
560
|
|
|
641
561
|
## License
|
|
642
562
|
|