@kirklin/eslint-config 1.0.1 → 1.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 +1 -1
- package/README.md +230 -50
- package/README.zh-cn.md +589 -407
- package/bin/index.js +2 -0
- package/dist/cli.cjs +290 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +261 -0
- package/dist/index.cjs +828 -329
- package/dist/index.d.cts +347 -85
- package/dist/index.d.ts +347 -85
- package/dist/index.js +820 -316
- package/package.json +102 -48
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2019-PRESENT
|
|
3
|
+
Copyright (c) 2019-PRESENT Anthony Fu<https://github.com/kirklin>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
# @kirklin/eslint-config
|
|
2
2
|
|
|
3
|
-
[![npm]
|
|
4
|
-
|
|
5
|
-
[
|
|
6
|
-
[
|
|
7
|
-
[
|
|
8
|
-
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![JSDocs][jsdocs-src]][jsdocs-href]
|
|
6
|
+
[![License][license-src]][license-href]
|
|
7
|
+
[![javascript_code style][code-style-image]][code-style-url]
|
|
8
|
+
|
|
9
|
+
<!-- Badges -->
|
|
10
|
+
|
|
11
|
+
[npm-version-src]: https://img.shields.io/npm/v/@kirklin/eslint-config?style=flat&colorA=080f12&colorB=3491fa
|
|
12
|
+
[npm-version-href]: https://npmjs.com/package/@kirklin/eslint-config
|
|
13
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@kirklin/eslint-config?style=flat&colorA=080f12&colorB=3491fa
|
|
14
|
+
[npm-downloads-href]: https://npmjs.com/package/@kirklin/eslint-config
|
|
15
|
+
[license-src]: https://img.shields.io/github/license/kirklin/eslint-config.svg?style=flat&colorA=080f12&colorB=3491fa
|
|
16
|
+
[license-href]: https://github.com/kirklin/eslint-config/blob/main/LICENSE
|
|
17
|
+
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=3491fa
|
|
18
|
+
[jsdocs-href]: https://www.jsdocs.io/package/@kirklin/eslint-config
|
|
19
|
+
[code-style-image]: https://img.shields.io/badge/code__style-%40kirklin%2Feslint--config-3491fa?style=flat&colorA=080f12&colorB=3491fa
|
|
20
|
+
[code-style-url]: https://github.com/kirklin/eslint-config/
|
|
9
21
|
|
|
10
22
|
<div align='left'>
|
|
11
23
|
<b>English</b> | <a href="README.zh-cn.md">简体中文</a>
|
|
@@ -16,13 +28,16 @@
|
|
|
16
28
|
|
|
17
29
|
- "double quotes", must semi;
|
|
18
30
|
- Auto fix for formatting (aimed to be used standalone **without** Prettier)
|
|
19
|
-
- Designed to work with TypeScript, JSX, Vue out-of-box
|
|
20
|
-
- Lints also for json, yaml, markdown
|
|
21
31
|
- Sorted imports, dangling commas
|
|
22
|
-
- Reasonable defaults, best practices, only one
|
|
23
|
-
-
|
|
32
|
+
- Reasonable defaults, best practices, only one line of config
|
|
33
|
+
- Designed to work with TypeScript, JSX, Vue out-of-box
|
|
34
|
+
- Lints also for json, yaml, toml, markdown
|
|
35
|
+
- Opinionated, but [very customizable](#customization)
|
|
24
36
|
- [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
|
|
25
37
|
- Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
|
|
38
|
+
- Respects `.gitignore` by default
|
|
39
|
+
- Optional [React](#react), [Svelte](#svelte), [UnoCSS](#unocss) support
|
|
40
|
+
- Optional [formatters](#formatters) support for CSS, HTML, etc.
|
|
26
41
|
- **Style principle**: Minimal for reading, stable for diff, consistent
|
|
27
42
|
|
|
28
43
|
> [!IMPORTANT]
|
|
@@ -56,6 +71,35 @@ const kirklin = require("@kirklin/eslint-config").default;
|
|
|
56
71
|
module.exports = kirklin();
|
|
57
72
|
```
|
|
58
73
|
|
|
74
|
+
> [!TIP]
|
|
75
|
+
> ESLint only detects `eslint.config.js` as the flat config entry, meaning you need to put `type: module` in your `package.json` or you have to use CJS in `eslint.config.js`. If you want explicit extension like `.mjs` or `.cjs`, or even `eslint.config.ts`, you can install [`eslint-ts-patch`](https://github.com/antfu/eslint-ts-patch) to fix it.
|
|
76
|
+
|
|
77
|
+
Combined with legacy config:
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
// eslint.config.js
|
|
81
|
+
const kirklin = require("@kirklin/eslint-config").default;
|
|
82
|
+
const { FlatCompat } = require("@eslint/eslintrc");
|
|
83
|
+
|
|
84
|
+
const compat = new FlatCompat();
|
|
85
|
+
|
|
86
|
+
module.exports = kirklin(
|
|
87
|
+
{
|
|
88
|
+
ignores: [],
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
// Legacy config
|
|
92
|
+
...compat.config({
|
|
93
|
+
extends: [
|
|
94
|
+
"eslint:recommended",
|
|
95
|
+
// Other extends...
|
|
96
|
+
],
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// Other flat configs...
|
|
100
|
+
);
|
|
101
|
+
```
|
|
102
|
+
|
|
59
103
|
> Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
|
|
60
104
|
|
|
61
105
|
### Add script for package.json
|
|
@@ -71,6 +115,16 @@ For example:
|
|
|
71
115
|
}
|
|
72
116
|
```
|
|
73
117
|
|
|
118
|
+
### Migration
|
|
119
|
+
|
|
120
|
+
We provided an experimental CLI tool to help you migrate from the legacy config to the new flat config.
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npx @kirklin/eslint-config@latest
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Before running the migration, make sure to commit your unsaved changes first.
|
|
127
|
+
|
|
74
128
|
## VS Code support (auto fix)
|
|
75
129
|
|
|
76
130
|
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
@@ -95,6 +149,7 @@ Add the following settings to your `.vscode/settings.json`:
|
|
|
95
149
|
// Silent the stylistic rules in you IDE, but still auto fix them
|
|
96
150
|
"eslint.rules.customizations": [
|
|
97
151
|
{ "rule": "style/*", "severity": "off" },
|
|
152
|
+
{ "rule": "format/*", "severity": "off" },
|
|
98
153
|
{ "rule": "*-indent", "severity": "off" },
|
|
99
154
|
{ "rule": "*-spacing", "severity": "off" },
|
|
100
155
|
{ "rule": "*-spaces", "severity": "off" },
|
|
@@ -116,7 +171,8 @@ Add the following settings to your `.vscode/settings.json`:
|
|
|
116
171
|
"markdown",
|
|
117
172
|
"json",
|
|
118
173
|
"jsonc",
|
|
119
|
-
"yaml"
|
|
174
|
+
"yaml",
|
|
175
|
+
"toml"
|
|
120
176
|
]
|
|
121
177
|
}
|
|
122
178
|
```
|
|
@@ -194,11 +250,12 @@ Going more advanced, you can also import fine-grained configs and compose them a
|
|
|
194
250
|
<details>
|
|
195
251
|
<summary>Advanced Example</summary>
|
|
196
252
|
|
|
197
|
-
We
|
|
253
|
+
We wouldn't recommend using this style in general unless you know exactly what they are doing, as there are shared options between configs and might need extra care to make them consistent.
|
|
198
254
|
|
|
199
255
|
```js
|
|
200
256
|
// eslint.config.js
|
|
201
257
|
import {
|
|
258
|
+
combine,
|
|
202
259
|
comments,
|
|
203
260
|
ignores,
|
|
204
261
|
imports,
|
|
@@ -210,27 +267,29 @@ import {
|
|
|
210
267
|
sortPackageJson,
|
|
211
268
|
sortTsconfig,
|
|
212
269
|
stylistic,
|
|
270
|
+
toml,
|
|
213
271
|
typescript,
|
|
214
272
|
unicorn,
|
|
215
273
|
vue,
|
|
216
274
|
yaml,
|
|
217
275
|
} from "@kirklin/eslint-config";
|
|
218
276
|
|
|
219
|
-
export default
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
277
|
+
export default combine(
|
|
278
|
+
ignores(),
|
|
279
|
+
javascript(/* Options */),
|
|
280
|
+
comments(),
|
|
281
|
+
node(),
|
|
282
|
+
jsdoc(),
|
|
283
|
+
imports(),
|
|
284
|
+
unicorn(),
|
|
285
|
+
typescript(/* Options */),
|
|
286
|
+
stylistic(),
|
|
287
|
+
vue(),
|
|
288
|
+
jsonc(),
|
|
289
|
+
yaml(),
|
|
290
|
+
toml(),
|
|
291
|
+
markdown(),
|
|
292
|
+
);
|
|
234
293
|
```
|
|
235
294
|
|
|
236
295
|
</details>
|
|
@@ -241,17 +300,17 @@ Check out the [configs](https://github.com/kirklin/eslint-config/blob/main/src/c
|
|
|
241
300
|
|
|
242
301
|
### Plugins Renaming
|
|
243
302
|
|
|
244
|
-
Since flat config requires us to explicitly provide the plugin names (instead of mandatory convention from npm package name), we renamed some plugins to make overall scope more consistent and easier to write.
|
|
303
|
+
Since flat config requires us to explicitly provide the plugin names (instead of the mandatory convention from npm package name), we renamed some plugins to make the overall scope more consistent and easier to write.
|
|
245
304
|
|
|
246
|
-
| New Prefix | Original Prefix
|
|
247
|
-
|
|
|
248
|
-
| `import/*` | `i/*`
|
|
249
|
-
| `node/*`
|
|
250
|
-
| `yaml/*`
|
|
251
|
-
| `ts/*`
|
|
252
|
-
| `style/*`
|
|
253
|
-
| `test/*`
|
|
254
|
-
| `test/*`
|
|
305
|
+
| New Prefix | Original Prefix | Source Plugin |
|
|
306
|
+
| ---------- | ---------------------- | ------------------------------------------------------------------------------------------ |
|
|
307
|
+
| `import/*` | `i/*` | [eslint-plugin-i](https://github.com/un-es/eslint-plugin-i) |
|
|
308
|
+
| `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
|
|
309
|
+
| `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
|
|
310
|
+
| `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
|
|
311
|
+
| `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
|
|
312
|
+
| `test/*` | `vitest/*` | [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest) |
|
|
313
|
+
| `test/*` | `no-only-tests/*` | [eslint-plugin-no-only-tests](https://github.com/levibuzolic/eslint-plugin-no-only-tests) |
|
|
255
314
|
|
|
256
315
|
When you want to override rules, or disable them inline, you need to update to the new prefix:
|
|
257
316
|
|
|
@@ -270,7 +329,10 @@ Certain rules would only be enabled in specific files, for example, `ts/*` rules
|
|
|
270
329
|
import kirklin from "@kirklin/eslint-config";
|
|
271
330
|
|
|
272
331
|
export default kirklin(
|
|
273
|
-
{
|
|
332
|
+
{
|
|
333
|
+
vue: true,
|
|
334
|
+
typescript: true
|
|
335
|
+
},
|
|
274
336
|
{
|
|
275
337
|
// Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
|
|
276
338
|
files: ["**/*.vue"],
|
|
@@ -287,35 +349,140 @@ export default kirklin(
|
|
|
287
349
|
);
|
|
288
350
|
```
|
|
289
351
|
|
|
290
|
-
We also provided
|
|
352
|
+
We also provided a `overrides` options in each integration to make it easier:
|
|
291
353
|
|
|
292
354
|
```js
|
|
293
355
|
// eslint.config.js
|
|
294
356
|
import kirklin from "@kirklin/eslint-config";
|
|
295
357
|
|
|
296
358
|
export default kirklin({
|
|
297
|
-
|
|
298
|
-
|
|
359
|
+
vue: {
|
|
360
|
+
overrides: {
|
|
299
361
|
"vue/operator-linebreak": ["error", "before"],
|
|
300
362
|
},
|
|
301
|
-
|
|
363
|
+
},
|
|
364
|
+
typescript: {
|
|
365
|
+
overrides: {
|
|
302
366
|
"ts/consistent-type-definitions": ["error", "interface"],
|
|
303
367
|
},
|
|
304
|
-
|
|
305
|
-
|
|
368
|
+
},
|
|
369
|
+
yaml: {
|
|
370
|
+
overrides: {
|
|
371
|
+
// ...
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
});
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### Optional Configs
|
|
378
|
+
|
|
379
|
+
We provide some optional configs for specific use cases, that we don't include their dependencies by default.
|
|
380
|
+
|
|
381
|
+
#### Formatters
|
|
382
|
+
|
|
383
|
+
> [!WARNING]
|
|
384
|
+
> Experimental feature, changes might not follow semver.
|
|
385
|
+
|
|
386
|
+
Use external formatters to format files that ESLint cannot handle yet (`.css`, `.html`, etc). Powered by [`eslint-plugin-format`](https://github.com/kirklin/eslint-plugin-format).
|
|
387
|
+
|
|
388
|
+
```js
|
|
389
|
+
// eslint.config.js
|
|
390
|
+
import kirklin from "@kirklin/eslint-config";
|
|
391
|
+
|
|
392
|
+
export default kirklin({
|
|
393
|
+
formatters: {
|
|
394
|
+
/**
|
|
395
|
+
* Format CSS, LESS, SCSS files, also the `<style>` blocks in Vue
|
|
396
|
+
* By default uses Prettier
|
|
397
|
+
*/
|
|
398
|
+
css: true,
|
|
399
|
+
/**
|
|
400
|
+
* Format HTML files
|
|
401
|
+
* By default uses Prettier
|
|
402
|
+
*/
|
|
403
|
+
html: true,
|
|
404
|
+
/**
|
|
405
|
+
* Format Markdown files
|
|
406
|
+
* Supports Prettier and dprint
|
|
407
|
+
* By default uses Prettier
|
|
408
|
+
*/
|
|
409
|
+
markdown: "prettier"
|
|
306
410
|
}
|
|
307
411
|
});
|
|
308
412
|
```
|
|
309
413
|
|
|
414
|
+
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
415
|
+
|
|
416
|
+
```bash
|
|
417
|
+
npm i -D eslint-plugin-format
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
#### React
|
|
421
|
+
|
|
422
|
+
To enable React support, you need to explicitly turn it on:
|
|
423
|
+
|
|
424
|
+
```js
|
|
425
|
+
// eslint.config.js
|
|
426
|
+
import kirklin from "@kirklin/eslint-config";
|
|
427
|
+
|
|
428
|
+
export default kirklin({
|
|
429
|
+
react: true,
|
|
430
|
+
});
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
434
|
+
|
|
435
|
+
```bash
|
|
436
|
+
npm i -D eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-refresh
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
#### Svelte
|
|
440
|
+
|
|
441
|
+
To enable svelte support, you need to explicitly turn it on:
|
|
442
|
+
|
|
443
|
+
```js
|
|
444
|
+
// eslint.config.js
|
|
445
|
+
import kirklin from "@kirklin/eslint-config";
|
|
446
|
+
|
|
447
|
+
export default kirklin({
|
|
448
|
+
svelte: true,
|
|
449
|
+
});
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
453
|
+
|
|
454
|
+
```bash
|
|
455
|
+
npm i -D eslint-plugin-svelte
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
#### UnoCSS
|
|
459
|
+
|
|
460
|
+
To enable UnoCSS support, you need to explicitly turn it on:
|
|
461
|
+
|
|
462
|
+
```js
|
|
463
|
+
// eslint.config.js
|
|
464
|
+
import kirklin from "@kirklin/eslint-config";
|
|
465
|
+
|
|
466
|
+
export default kirklin({
|
|
467
|
+
unocss: true,
|
|
468
|
+
});
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
472
|
+
|
|
473
|
+
```bash
|
|
474
|
+
npm i -D @unocss/eslint-plugin
|
|
475
|
+
```
|
|
476
|
+
|
|
310
477
|
### Optional Rules
|
|
311
478
|
|
|
312
|
-
This config also provides some optional plugins/rules for extended
|
|
479
|
+
This config also provides some optional plugins/rules for extended usage.
|
|
313
480
|
|
|
314
481
|
#### `perfectionist` (sorting)
|
|
315
482
|
|
|
316
483
|
This plugin [`eslint-plugin-perfectionist`](https://github.com/azat-io/eslint-plugin-perfectionist) allows you to sorted object keys, imports, etc, with auto-fix.
|
|
317
484
|
|
|
318
|
-
The plugin is installed but no rules are enabled by default.
|
|
485
|
+
The plugin is installed but no rules are enabled by default.
|
|
319
486
|
|
|
320
487
|
It's recommended to opt-in on each file individually using [configuration comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1).
|
|
321
488
|
|
|
@@ -363,11 +530,24 @@ and then
|
|
|
363
530
|
|
|
364
531
|
```bash
|
|
365
532
|
npm i -D lint-staged simple-git-hooks
|
|
533
|
+
|
|
534
|
+
// to active the hooks
|
|
535
|
+
npx simple-git-hooks
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
## View what rules are enabled
|
|
539
|
+
|
|
540
|
+
I built a visual tool to help you view what rules are enabled in your project and apply them to what files, [eslint-flat-config-viewer](https://github.com/kirklin/eslint-flat-config-viewer)
|
|
541
|
+
|
|
542
|
+
Go to your project root that contains `eslint.config.js` and run:
|
|
543
|
+
|
|
544
|
+
```bash
|
|
545
|
+
npx eslint-flat-config-viewer
|
|
366
546
|
```
|
|
367
547
|
|
|
368
548
|
## Versioning Policy
|
|
369
549
|
|
|
370
|
-
This project follows [Semantic Versioning](https://semver.org/) for releases. However, since this is just a config and
|
|
550
|
+
This project follows [Semantic Versioning](https://semver.org/) for releases. However, since this is just a config and involves opinions and many moving parts, we don't treat rules changes as breaking changes.
|
|
371
551
|
|
|
372
552
|
### Changes Considered as Breaking Changes
|
|
373
553
|
|
|
@@ -387,13 +567,13 @@ This project follows [Semantic Versioning](https://semver.org/) for releases. Ho
|
|
|
387
567
|
Use this in one of your projects? Include one of these badges in your readme to
|
|
388
568
|
let people know that your code is using the Kirk Lin style.
|
|
389
569
|
|
|
390
|
-
[](https://github.com/kirklin/eslint-config/)
|
|
391
571
|
|
|
392
572
|
```markdown
|
|
393
|
-
[](https://github.com/kirklin/eslint-config/)
|
|
394
574
|
```
|
|
395
575
|
|
|
396
|
-
[code-style-image]: https://img.shields.io/badge/code__style-%40kirklin%2Feslint--config-
|
|
576
|
+
[code-style-image]: https://img.shields.io/badge/code__style-%40kirklin%2Feslint--config-3491fa?style=flat&colorA=080f12&colorB=3491fa
|
|
397
577
|
[code-style-url]: https://github.com/kirklin/eslint-config/
|
|
398
578
|
|
|
399
579
|
## Thanks
|