@moso/eslint-config 0.3.5 → 1.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/LICENSE +21 -21
- package/README.md +498 -0
- package/dist/index.d.ts +15652 -0
- package/dist/index.js +1873 -0
- package/package.json +112 -36
- package/index.js +0 -6
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 - present Morten Sørensen (https://github.com/moso)
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 - present Morten Sørensen (https://github.com/moso)
|
|
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,498 @@
|
|
|
1
|
+
# @moso/eslint-config
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/@moso/eslint-config)
|
|
4
|
+
|
|
5
|
+
Flat ESLint config for JavaScript, TypeScript, Vue, React, and more.
|
|
6
|
+
|
|
7
|
+
[Legacy Version](https://github.com/moso/eslint-config/tree/legacy).
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new) with reasonable but opinionated defaults
|
|
12
|
+
- Single quotes, semi enabled, sorted imports, dangling commas,
|
|
13
|
+
- Aimed to be used without Prettier
|
|
14
|
+
- Designed to work with JSX, TypeScript, Vue, and React out of the box
|
|
15
|
+
- [Stylistic](https://eslint.style) rules implemented by default
|
|
16
|
+
- Lints for json and yaml
|
|
17
|
+
- Respects `.gitignore` by default
|
|
18
|
+
- Requires ESLint v9.5.0+
|
|
19
|
+
|
|
20
|
+
> [!NOTE]
|
|
21
|
+
> Since v1.0.0, this config is rewritten for the new [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new) format.
|
|
22
|
+
>
|
|
23
|
+
> ESLint v9.5.0+ is now required.
|
|
24
|
+
|
|
25
|
+
> [!WARNING]
|
|
26
|
+
> While I'm very appreciative with every single install of this config, please keep in mind that this config is still a **personal**, opinionated config. How I like things set up might not fit everyone, or every usecase.
|
|
27
|
+
>
|
|
28
|
+
> If you're using this config directly, I suggest you review the changes with every update. Or if you want more control over the very core of this config, feel free to fork it. Thanks!
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### Install
|
|
33
|
+
|
|
34
|
+
> I like to use [Bun](https://bun.sh) because it's hella fast. Thus all the install instructions are with Bun. If you use something else, check the syntax with your favorite package manager.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
bun add -dev eslint @moso/eslint-config
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Create `eslint.config.js` in the root of your project:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
// eslint.config.js
|
|
44
|
+
import moso from '@moso/eslint-config';
|
|
45
|
+
|
|
46
|
+
export default moso();
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
<details>
|
|
50
|
+
<summary>
|
|
51
|
+
Combine with legacy config:
|
|
52
|
+
</summary>
|
|
53
|
+
|
|
54
|
+
If you still use some configs from the legacy `eslintrc` format, you can use the [`@eslint/eslintrc`](https://npmjs.com/package/@eslint/eslintrc) package to convert them to the flat config.
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
// eslint.config.js
|
|
58
|
+
import moso from '@moso/eslint-config';
|
|
59
|
+
import { FlatCompat } from '@eslint/eslintrc';
|
|
60
|
+
|
|
61
|
+
const compat = new FlatCompat()
|
|
62
|
+
|
|
63
|
+
export default moso(
|
|
64
|
+
{
|
|
65
|
+
ignores: [],
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
// Legacy config
|
|
69
|
+
...compat.config({
|
|
70
|
+
extends: [
|
|
71
|
+
'eslint:recommended',
|
|
72
|
+
// Other extends...
|
|
73
|
+
],
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
// Other flat configs...
|
|
77
|
+
);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
> Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
|
|
81
|
+
|
|
82
|
+
</details>
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
### Add script for package.json
|
|
86
|
+
|
|
87
|
+
For example:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"scripts": {
|
|
92
|
+
"lint": "eslint",
|
|
93
|
+
"lint:fix": "eslint --fix"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## VS Code support (auto fix)
|
|
99
|
+
|
|
100
|
+
<details>
|
|
101
|
+
<summary>Details</summary>
|
|
102
|
+
|
|
103
|
+
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
104
|
+
|
|
105
|
+
Add the following settings to your `.vscode/settings.json`:
|
|
106
|
+
|
|
107
|
+
```jsonc
|
|
108
|
+
{
|
|
109
|
+
// Disable the default formatter, use eslint instead
|
|
110
|
+
"prettier.enable": false,
|
|
111
|
+
"editor.formatOnSave": false,
|
|
112
|
+
|
|
113
|
+
// Auto fix
|
|
114
|
+
"editor.codeActionsOnSave": {
|
|
115
|
+
"source.fixAll.eslint": "explicit",
|
|
116
|
+
"source.organizeImports": "never"
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
// You can silent specific rules in you IDE, but still auto fix them
|
|
120
|
+
"eslint.rules.customizations": [
|
|
121
|
+
{ "rule": "@stylistic/*", "severity": "off", "fixable": true },
|
|
122
|
+
{ "rule": "*-indent", "severity": "off", "fixable": true },
|
|
123
|
+
{ "rule": "*-spacing", "severity": "off", "fixable": true },
|
|
124
|
+
{ "rule": "*-spaces", "severity": "off", "fixable": true },
|
|
125
|
+
{ "rule": "*-order", "severity": "off", "fixable": true },
|
|
126
|
+
{ "rule": "*-dangle", "severity": "off", "fixable": true },
|
|
127
|
+
{ "rule": "*-newline", "severity": "off", "fixable": true },
|
|
128
|
+
{ "rule": "*quotes", "severity": "off", "fixable": true },
|
|
129
|
+
{ "rule": "*semi", "severity": "off", "fixable": true }
|
|
130
|
+
],
|
|
131
|
+
|
|
132
|
+
// Enable eslint for all supported languages
|
|
133
|
+
"eslint.validate": [
|
|
134
|
+
"javascript",
|
|
135
|
+
"javascriptreact",
|
|
136
|
+
"typescript",
|
|
137
|
+
"typescriptreact",
|
|
138
|
+
"vue",
|
|
139
|
+
"json",
|
|
140
|
+
"jsonc",
|
|
141
|
+
"yaml"
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
</details>
|
|
147
|
+
|
|
148
|
+
## Customization
|
|
149
|
+
|
|
150
|
+
Since v1.0, this config has been migrated to [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new). It provides much better organization and composition. And speed!
|
|
151
|
+
|
|
152
|
+
Normally you only need to import the `moso` preset:
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
// eslint.config.js
|
|
156
|
+
import moso from '@moso/eslint-config';
|
|
157
|
+
|
|
158
|
+
export default moso();
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
If you want more control, you can configure each intetegration, like so:
|
|
162
|
+
|
|
163
|
+
```js
|
|
164
|
+
// eslint.config.js
|
|
165
|
+
import moso from '@moso/eslint-config';
|
|
166
|
+
|
|
167
|
+
export default moso({
|
|
168
|
+
// Disable stylistic formatting rules
|
|
169
|
+
stylistic: false,
|
|
170
|
+
|
|
171
|
+
// Or customize the stylistic rules
|
|
172
|
+
stylistic: {
|
|
173
|
+
indent: 2, // 4, or 'tab'
|
|
174
|
+
quotes: 'single', // or 'double'
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
// TypeScript, Vue, and React are auto-detected, you can also explicitly enable them:
|
|
178
|
+
typescript: true,
|
|
179
|
+
react: true,
|
|
180
|
+
vue: true,
|
|
181
|
+
|
|
182
|
+
// Disable jsonc and yaml support
|
|
183
|
+
jsonc: false,
|
|
184
|
+
yaml: false,
|
|
185
|
+
|
|
186
|
+
// `.eslintignore` is no longer supported in Flat config, use `ignores` instead
|
|
187
|
+
ignores: [
|
|
188
|
+
'**/dist',
|
|
189
|
+
// ...globs
|
|
190
|
+
],
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Rules overrides
|
|
195
|
+
|
|
196
|
+
The `moso` configurator function accepts any number of custom config overrides. And certain rules will only be enabled for specific file types. Example, `vue/*` rules are only applied on `.vue`-files. If you want to override the rules, you need to specify the file extension:
|
|
197
|
+
|
|
198
|
+
```js
|
|
199
|
+
// eslint.config.js
|
|
200
|
+
import moso from '@moso/eslint-config';
|
|
201
|
+
|
|
202
|
+
export default moso(
|
|
203
|
+
{
|
|
204
|
+
// First argument are configurations for moso's config
|
|
205
|
+
vue: true,
|
|
206
|
+
typescript: true,
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
// Second argument and beyond are ESLint Flat Configs
|
|
210
|
+
// You can have as many as you want here.
|
|
211
|
+
|
|
212
|
+
// Example of overriding vue/* rules on `.vue`-files using the Vue file glob:
|
|
213
|
+
files: ['**/*.vue'],
|
|
214
|
+
rules: {
|
|
215
|
+
'vue/multi-word-component-names': ['error', { ignores: [] }],
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
rules: {},
|
|
220
|
+
},
|
|
221
|
+
);
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Since v1.0.0, the configurator function returns a `FlatConfigComposer`-object from [antfu](https://github.com/antfu)'s [`eslint-flat-config-utils`](https://github.com/antfu/eslint-flat-config-utils#composer), which gives you even more flexibility when composing the config, as you can `dot` your way through:
|
|
225
|
+
|
|
226
|
+
```js
|
|
227
|
+
// eslint.config.js
|
|
228
|
+
import moso from '@moso/eslint-config';
|
|
229
|
+
|
|
230
|
+
export default moso()
|
|
231
|
+
.prepend(
|
|
232
|
+
// Configs before the main config
|
|
233
|
+
)
|
|
234
|
+
.override(
|
|
235
|
+
// Override any named config
|
|
236
|
+
'moso/javascript/rules',
|
|
237
|
+
{
|
|
238
|
+
rules: {
|
|
239
|
+
'no-var': 'off',
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
)
|
|
243
|
+
// You can also remove rules entirely
|
|
244
|
+
.removeRules(
|
|
245
|
+
// ...
|
|
246
|
+
);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
<details>
|
|
250
|
+
<summary>Advanced example</summary>
|
|
251
|
+
|
|
252
|
+
You can import fine-grained configs and compose them as you want. Don't do this unless you know exactly what you're doing.
|
|
253
|
+
|
|
254
|
+
```js
|
|
255
|
+
import {
|
|
256
|
+
combine,
|
|
257
|
+
comments,
|
|
258
|
+
ignores,
|
|
259
|
+
imports,
|
|
260
|
+
javascript,
|
|
261
|
+
jsdoc,
|
|
262
|
+
jsonc,
|
|
263
|
+
node,
|
|
264
|
+
sortPackageJson,
|
|
265
|
+
sortTsconfig,
|
|
266
|
+
stylistic,
|
|
267
|
+
typescript,
|
|
268
|
+
unicorn,
|
|
269
|
+
vue,
|
|
270
|
+
yaml,
|
|
271
|
+
} from '@moso/eslint-config';
|
|
272
|
+
|
|
273
|
+
export default combine(
|
|
274
|
+
ignores(),
|
|
275
|
+
javascript(/* options */),
|
|
276
|
+
comments(),
|
|
277
|
+
node(),
|
|
278
|
+
jsdoc(),
|
|
279
|
+
imports(),
|
|
280
|
+
unicorn(),
|
|
281
|
+
typescript(/* options */),
|
|
282
|
+
stylistic(),
|
|
283
|
+
vue(/* options */),
|
|
284
|
+
jsonc(),
|
|
285
|
+
yaml(),
|
|
286
|
+
);
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
</details>
|
|
290
|
+
|
|
291
|
+
## Optional configs
|
|
292
|
+
|
|
293
|
+
There are multiple configs that are deemed "optional". Most of them are set to `true` (enabled), some are `auto-detect`. An example of auto-detection, TypeScript, Vue, and React are set to `auto-detect`, as there are checks in those configs and enable them if their packages are present. But should you want to enable/disable these explicitly, or if my check doesn't auto-detect it, this is how it's done:
|
|
294
|
+
|
|
295
|
+
```js
|
|
296
|
+
// eslint.config.js
|
|
297
|
+
import moso from '@moso/eslint-config';
|
|
298
|
+
|
|
299
|
+
export default moso({
|
|
300
|
+
// Enable TypeScript
|
|
301
|
+
typescript: true,
|
|
302
|
+
|
|
303
|
+
// Enable Vue
|
|
304
|
+
vue: true,
|
|
305
|
+
|
|
306
|
+
// Enable React
|
|
307
|
+
react: true,
|
|
308
|
+
});
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**Note**: Since Vue 2 has [reached EOL](https://v2.vuejs.org/eol), this config does not support Vue 2. If you need to support for Vue 2, you'll need to disable the imported configs from Vue 3, and replace them with the Vue 2 ones. You can see an inspiring example on [`eslint-plugin-vue`](https://eslint.vuejs.org/user-guide/#usage). I recommend upgrading to Vue 3 if possible.
|
|
312
|
+
|
|
313
|
+
## Optional rules
|
|
314
|
+
|
|
315
|
+
This config also provides some optional plugins/rules for extended usage.
|
|
316
|
+
|
|
317
|
+
### Perfectionist
|
|
318
|
+
|
|
319
|
+
The plugin [`eslint-plugin-perfectionist`](https://perfectionist.dev) allows you to sort object keys, imports, types, enums and JSX props with auto fix. I love it, and encourage everyone to use it. It gives you a lot more consistency across projects and developers. The plugin is installed and enabled by default, but only rules for sorting imports are activated.
|
|
320
|
+
|
|
321
|
+
If you wish to override or extend it, you can by overriding the `perfectionist` integration, or adding to your own `rules`.
|
|
322
|
+
|
|
323
|
+
```js
|
|
324
|
+
// eslint.config.js
|
|
325
|
+
import moso from '@moso/eslint-config';
|
|
326
|
+
|
|
327
|
+
export default moso(
|
|
328
|
+
{
|
|
329
|
+
// Overriding the sort-imports
|
|
330
|
+
perfectionist: {
|
|
331
|
+
overrides: {
|
|
332
|
+
'perfectionist/sort-imports': 'off',
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
// Or adding your own rules
|
|
338
|
+
rules: {
|
|
339
|
+
'perfectionist/sort-enums': ['error', { type: 'natural', order: 'asc', locales: 'da-DK' }],
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
);
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
However, you can also opt-in to a rule in each file individually using [configuration comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1).
|
|
346
|
+
|
|
347
|
+
```js
|
|
348
|
+
/* eslint perfectionist/sort-objects: 'error' */
|
|
349
|
+
const objectWantedToSort = {
|
|
350
|
+
a: 2,
|
|
351
|
+
b: 1,
|
|
352
|
+
c: 3,
|
|
353
|
+
};
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
**Note**: If you want to disable it, you can do it in two ways.
|
|
357
|
+
|
|
358
|
+
#### Individually
|
|
359
|
+
|
|
360
|
+
```js
|
|
361
|
+
// eslint.config.js
|
|
362
|
+
import moso from '@moso/eslint-config';
|
|
363
|
+
|
|
364
|
+
export default moso({
|
|
365
|
+
// Disable Perfectionist
|
|
366
|
+
perfectionist: false,
|
|
367
|
+
});
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
#### Part of `lessOpinionated`
|
|
371
|
+
|
|
372
|
+
There's an option to actually make this config "less opinionated". This will also strip most of the [`@stylistic`](https://eslint.style) rules, but more about that at the [Less Opnionated](#i-want-it-less-opnionated)-section.
|
|
373
|
+
|
|
374
|
+
```js
|
|
375
|
+
// eslint.config.js
|
|
376
|
+
import moso from '@moso/eslint-config';
|
|
377
|
+
|
|
378
|
+
export default moso({
|
|
379
|
+
// Less opnionated
|
|
380
|
+
lessOpnionated: true,
|
|
381
|
+
});
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### Type-aware rules
|
|
385
|
+
|
|
386
|
+
You can also optionally enable the [type-aware rules](https://typescript-eslint.io/linting/typed-linting) by passing the path of your `tsconfig.json` to the `typescript` config.
|
|
387
|
+
|
|
388
|
+
This enables for much deeper insight into your code.
|
|
389
|
+
|
|
390
|
+
```js
|
|
391
|
+
// eslint.config.js
|
|
392
|
+
import moso from '@moso/eslint-config';
|
|
393
|
+
|
|
394
|
+
export default moso({
|
|
395
|
+
typescript: {
|
|
396
|
+
tsconfigPath: 'tsconfig.json',
|
|
397
|
+
},
|
|
398
|
+
});
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### Editor specific non-fixes
|
|
402
|
+
|
|
403
|
+
Some rules are deemed as 'non-fixable' when inside your editor with ESLint integration:
|
|
404
|
+
|
|
405
|
+
- [`prefer-const`](https://eslint.org/docs/rules/prefer-const)
|
|
406
|
+
- [`unused-imports/no-unused-imports`](https://github.com/sweepline/eslint-plugin-unused-imports)
|
|
407
|
+
- [`vitest/no-only-tests`](https://github.com/levibuzolic/eslint-plugin-no-only-tests)
|
|
408
|
+
|
|
409
|
+
This is to prevent unused imports from getting removed by your editor when refactoring to get a better developer experience. However, the rules will still be applied when you run ESLint from your terminal. You can disable this behavior like so:
|
|
410
|
+
|
|
411
|
+
```js
|
|
412
|
+
// eslint.config.js
|
|
413
|
+
import moso from '@moso/eslint-config';
|
|
414
|
+
|
|
415
|
+
export default moso({
|
|
416
|
+
isInEditor: false,
|
|
417
|
+
});
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
### Lint Staged
|
|
421
|
+
|
|
422
|
+
Linting and auto-fixing before every commit is easy, you just add the following to your `package.json`:
|
|
423
|
+
|
|
424
|
+
```json
|
|
425
|
+
{
|
|
426
|
+
"simple-git-hooks": {
|
|
427
|
+
"pre-commit": "bunx lint-staged"
|
|
428
|
+
},
|
|
429
|
+
"lint-staged": {
|
|
430
|
+
"*": "eslint --fix"
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
and then
|
|
436
|
+
|
|
437
|
+
```bash
|
|
438
|
+
bun add -dev lint-staged simple-git-hooks
|
|
439
|
+
|
|
440
|
+
# to activate the hooks
|
|
441
|
+
bunx simple-git-hooks
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
## View which rules are enabled
|
|
445
|
+
|
|
446
|
+
[Antfu](https://github.com/antfu) built a visual tool that can help you view what rules are enabled in your project: [@eslint/config-inspector](https://github.com/eslint/config-inspector).
|
|
447
|
+
|
|
448
|
+
To view it in action, navigate to the root of your project that contains your `eslint.config.js` and run:
|
|
449
|
+
|
|
450
|
+
```bash
|
|
451
|
+
bunx @eslint/config-inspector
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
## FAQ
|
|
455
|
+
|
|
456
|
+
### I want it less opnionated
|
|
457
|
+
|
|
458
|
+
No problem. I've extracted the things that I've deemed *very opinionated* in each integration, and made a setting that helps you disable all of it in one go.
|
|
459
|
+
|
|
460
|
+
```js
|
|
461
|
+
// eslint.config.js
|
|
462
|
+
import moso from '@moso/eslint-config';
|
|
463
|
+
|
|
464
|
+
export default moso({
|
|
465
|
+
lessOpinionated: true,
|
|
466
|
+
});
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### Prettier? dprint?
|
|
470
|
+
|
|
471
|
+
You can still use these to format files that aren't linted with this config, however, I strongly recommend you only format your code with ESLint, as Pretter and other AST-reading-then-reprint projects tend to ignore stuff like the original line breaks and might also cause inconsistent diffs when commiting code.
|
|
472
|
+
|
|
473
|
+
### How to format CSS?
|
|
474
|
+
|
|
475
|
+
You will need to install and configure [`stylelint`](https://stylelint.io) yourself, unfortunately.
|
|
476
|
+
|
|
477
|
+
### I prefer `this` or `that` rule
|
|
478
|
+
|
|
479
|
+
Fine, you can always override the rules locally in your project to fit your needs. If that doesn't cut it, you're welcome to fork this project and maintain your own config.
|
|
480
|
+
|
|
481
|
+
## Inspiration
|
|
482
|
+
|
|
483
|
+
This eslint-config takes inspiration from (and uses some of) [`@antfu/eslint-config`](https://github.com/antfu/eslint-config) and [`@rubiin/eslint-config`](https://github.com/rubiin/eslint-config) respectively. Thank you to everyone who contributed to these configs.
|
|
484
|
+
|
|
485
|
+
*Most* of the rules are the same, however, there are some differences:
|
|
486
|
+
|
|
487
|
+
- Opinionated rules
|
|
488
|
+
- Enables Stylistic per default
|
|
489
|
+
- React detection, no need to enable it
|
|
490
|
+
- Includes dependencies rather than asking you to install them
|
|
491
|
+
- Deprecated Vue 2 support
|
|
492
|
+
- Simplification in some areas
|
|
493
|
+
- Less clutter, shipping with less "smart" features
|
|
494
|
+
- No dangerous plugin renaming, except for `eslint-plugin-n` which is renamed to `node` for readability
|
|
495
|
+
|
|
496
|
+
## License
|
|
497
|
+
|
|
498
|
+
[MIT](./LICENSE) License
|