@ncontiero/eslint-config 5.1.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/LICENSE +21 -0
- package/README.md +231 -0
- package/dist/index.d.ts +13304 -0
- package/dist/index.js +1 -0
- package/package.json +111 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-PRESENT Nicolas Contiero <https://github.com/ncontiero>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# @dkshs/eslint-config
|
|
2
|
+
|
|
3
|
+
Nicolas's ESLint config preset for JavaScript, TypeScript, and Prettier.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@dkshs/eslint-config)
|
|
6
|
+
[](https://github.com/ncontiero/eslint-config/blob/master/LICENSE)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- Double quotes, with semi.
|
|
11
|
+
- Format with Prettier.
|
|
12
|
+
- Sort imports, `package.json`, `tsconfig.json`...
|
|
13
|
+
- Reasonable defaults, best practices, only one line of config.
|
|
14
|
+
- Designed to work with TypeScript out-of-box.
|
|
15
|
+
- Support JSON(5), YAML, TOML, Markdown...
|
|
16
|
+
- [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
|
|
17
|
+
- Ignores common files like `dist`, `node_modules`, `coverage`, and files in `.gitignore`.
|
|
18
|
+
- Optional [React](https://react.dev/), [NextJs](https://nextjs.org/), [TailwindCSS](https://tailwindcss.com/), [TanStack Query](https://tanstack.com/query/) support.
|
|
19
|
+
- Requires ESLint v9.20.0+.
|
|
20
|
+
|
|
21
|
+
> [!IMPORTANT]
|
|
22
|
+
> Since v2.2.0, this config is rewritten to the new [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), check the [release note](https://github.com/ncontiero/eslint-config/releases/tag/v2.2.0) for more details.
|
|
23
|
+
>
|
|
24
|
+
> Since v3.0.0, ESLint v9.5.0+ is now required.
|
|
25
|
+
>
|
|
26
|
+
> Since v4.2.0, ESLint v9.20.0+ is now required.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
1. Install the dependencies:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm i -D eslint @dkshs/eslint-config
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
> Require Node.js >= 18.18, and ESLint >= 9.20.0.
|
|
37
|
+
|
|
38
|
+
2. Create `eslint.config.mjs` in your project root:
|
|
39
|
+
|
|
40
|
+
```mjs
|
|
41
|
+
// eslint.config.mjs
|
|
42
|
+
import { ncontiero } from "@dkshs/eslint-config";
|
|
43
|
+
|
|
44
|
+
export default ncontiero(
|
|
45
|
+
// Features: it'll detect installed dependency and enable necessary features automatically
|
|
46
|
+
{
|
|
47
|
+
prettier: true,
|
|
48
|
+
markdown: true,
|
|
49
|
+
react: true, // auto detection
|
|
50
|
+
nextjs: false, // auto detection
|
|
51
|
+
tailwindcss: false, // auto detection
|
|
52
|
+
reactQuery: false, // auto detection
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
/* your custom config */
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
3. Add script for package.json:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"scripts": {
|
|
65
|
+
"lint": "eslint .",
|
|
66
|
+
"lint:fix": "eslint . --fix"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## VS Code support (auto fix on save)
|
|
72
|
+
|
|
73
|
+
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
74
|
+
|
|
75
|
+
Add the following settings to your `.vscode/settings.json`:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
// Disable the default formatter, use eslint instead
|
|
80
|
+
"prettier.enable": false,
|
|
81
|
+
"editor.formatOnSave": false,
|
|
82
|
+
|
|
83
|
+
// Auto fix
|
|
84
|
+
"editor.codeActionsOnSave": {
|
|
85
|
+
"source.fixAll.eslint": "explicit",
|
|
86
|
+
"source.organizeImports": "never"
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
// Enable eslint for all supported languages
|
|
90
|
+
"eslint.validate": [
|
|
91
|
+
"javascript",
|
|
92
|
+
"javascriptreact",
|
|
93
|
+
"typescript",
|
|
94
|
+
"typescriptreact",
|
|
95
|
+
"html",
|
|
96
|
+
"markdown",
|
|
97
|
+
"json",
|
|
98
|
+
"jsonc",
|
|
99
|
+
"yaml",
|
|
100
|
+
"toml",
|
|
101
|
+
"gql",
|
|
102
|
+
"graphql",
|
|
103
|
+
"css",
|
|
104
|
+
"less",
|
|
105
|
+
"scss",
|
|
106
|
+
"pcss",
|
|
107
|
+
"postcss"
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Customization
|
|
113
|
+
|
|
114
|
+
Since v2.2, we migrated to [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new). It provides much better organization and composition.
|
|
115
|
+
|
|
116
|
+
Normally you only need to import the `dkshs` preset:
|
|
117
|
+
|
|
118
|
+
```js
|
|
119
|
+
// eslint.config.js
|
|
120
|
+
import { ncontiero } from "@dkshs/eslint-config";
|
|
121
|
+
|
|
122
|
+
export default ncontiero();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
And that's it! Or you can configure each integration individually, for example:
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
// eslint.config.js
|
|
129
|
+
import { ncontiero } from "@dkshs/eslint-config";
|
|
130
|
+
|
|
131
|
+
export default ncontiero({
|
|
132
|
+
// TypeScript, React, NextJs, TailwindCSS and TanStack Query are auto-detected,
|
|
133
|
+
// you can also explicitly enable them:
|
|
134
|
+
typescript: true,
|
|
135
|
+
react: true,
|
|
136
|
+
nextjs: true,
|
|
137
|
+
tailwindcss: true,
|
|
138
|
+
reactQuery: true,
|
|
139
|
+
|
|
140
|
+
// Disable jsonc, yaml and toml support
|
|
141
|
+
jsonc: false,
|
|
142
|
+
yaml: false,
|
|
143
|
+
toml: false,
|
|
144
|
+
|
|
145
|
+
// `.eslintignore` is no longer supported in Flat config, use `ignores` instead
|
|
146
|
+
ignores: [
|
|
147
|
+
"**/fixtures",
|
|
148
|
+
// ...globs
|
|
149
|
+
],
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The `dkshs` factory function also accepts any number of arbitrary custom config overrides:
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
// eslint.config.js
|
|
157
|
+
import { ncontiero } from "@dkshs/eslint-config";
|
|
158
|
+
|
|
159
|
+
export default ncontiero(
|
|
160
|
+
{
|
|
161
|
+
// Configures for ncontiero's config
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
// From the second arguments they are ESLint Flat Configs
|
|
165
|
+
// you can have multiple configs
|
|
166
|
+
{
|
|
167
|
+
files: ["**/*.ts"],
|
|
168
|
+
rules: {},
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
rules: {},
|
|
172
|
+
},
|
|
173
|
+
);
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Rules Overrides
|
|
177
|
+
|
|
178
|
+
Certain rules would only be enabled in specific files, for example, `ts/*` rules would only be enabled in `.ts`. We also provided the overrides options in each integration to make it easier:
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
// eslint.config.js
|
|
182
|
+
import { ncontiero } from "@dkshs/eslint-config";
|
|
183
|
+
|
|
184
|
+
export default ncontiero({
|
|
185
|
+
typescript: {
|
|
186
|
+
overrides: {
|
|
187
|
+
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
yaml: {
|
|
191
|
+
overrides: {
|
|
192
|
+
// ...
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Optional Configs
|
|
199
|
+
|
|
200
|
+
We provide some optional configs for specific use cases, that we don't include their dependencies by default.
|
|
201
|
+
> React, Next.js and Tailwind CSS have their dependencies by default.
|
|
202
|
+
|
|
203
|
+
#### TanStack Query
|
|
204
|
+
|
|
205
|
+
To enable TanStack Query support, you need to have the package installed or explicitly enable it:
|
|
206
|
+
|
|
207
|
+
```js
|
|
208
|
+
// eslint.config.js
|
|
209
|
+
import { ncontiero } from "@dkshs/eslint-config";
|
|
210
|
+
|
|
211
|
+
export default ncontiero({
|
|
212
|
+
reactQuery: true,
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
To work, the [`@tanstack/eslint-plugin-query`](https://tanstack.com/query/latest/docs/eslint/eslint-plugin-query) package must be installed:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
npm i -D @tanstack/eslint-plugin-query
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
> Require @tanstack/eslint-plugin-query >= 5.50.0
|
|
223
|
+
|
|
224
|
+
## References and inspirations
|
|
225
|
+
|
|
226
|
+
- [@antfu/eslint-config](https://github.com/antfu/eslint-config) - Anthony's ESLint config preset.
|
|
227
|
+
- [@sxzz/eslint-config](https://github.com/sxzz/eslint-config) - A opinionated ESLint config preset.
|
|
228
|
+
|
|
229
|
+
## License
|
|
230
|
+
|
|
231
|
+
This project is licensed under the **MIT** License - see the [LICENSE](./LICENSE) file for details
|