@lincy/eslint-config 3.3.1 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -24
- package/dist/chunk-YG22WGT3.js +40 -0
- package/dist/index.cjs +7076 -203
- package/dist/index.d.cts +20 -9
- package/dist/index.d.ts +20 -9
- package/dist/index.js +6963 -162
- package/dist/main-4FJS3AFB.js +1563 -0
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
- 单引号,无结尾分号
|
|
6
6
|
- 自动格式化
|
|
7
7
|
- 专为与 TypeScript、Vue(2/3) 一起使用而设计,开箱即用
|
|
8
|
-
-
|
|
8
|
+
- 也适用于 json、yaml、markdown、react
|
|
9
9
|
- import导入排序, 对象字⾯量项尾逗号
|
|
10
10
|
- 合理的默认值,最佳实践,只需一行配置
|
|
11
11
|
- [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new)
|
|
@@ -52,20 +52,20 @@ For example:
|
|
|
52
52
|
|
|
53
53
|
```jsonc
|
|
54
54
|
{
|
|
55
|
-
//
|
|
55
|
+
// 开启eslint扁平化配置
|
|
56
56
|
"eslint.experimental.useFlatConfig": true,
|
|
57
57
|
|
|
58
|
-
//
|
|
58
|
+
// 禁用默认的格式化
|
|
59
59
|
"prettier.enable": false,
|
|
60
60
|
"editor.formatOnSave": false,
|
|
61
61
|
|
|
62
|
-
//
|
|
62
|
+
// 开启自动修复
|
|
63
63
|
"editor.codeActionsOnSave": {
|
|
64
64
|
"source.fixAll.eslint": true,
|
|
65
65
|
"source.organizeImports": false
|
|
66
66
|
},
|
|
67
67
|
|
|
68
|
-
//
|
|
68
|
+
// 在 IDE 中静默样式规则,但仍会自动修复它们
|
|
69
69
|
"eslint.rules.customizations": [
|
|
70
70
|
{ "rule": "@stylistic/*", "severity": "off" },
|
|
71
71
|
{ "rule": "*-indent", "severity": "off" },
|
|
@@ -78,10 +78,7 @@ For example:
|
|
|
78
78
|
{ "rule": "*semi", "severity": "off" }
|
|
79
79
|
],
|
|
80
80
|
|
|
81
|
-
//
|
|
82
|
-
// It's better to put under project setting `.vscode/settings.json`
|
|
83
|
-
// to avoid conflicts with working with different eslint configs
|
|
84
|
-
// that does not support all formats.
|
|
81
|
+
// 为所有支持的语言启用 eslint
|
|
85
82
|
"eslint.validate": [
|
|
86
83
|
"javascript",
|
|
87
84
|
"javascriptreact",
|
|
@@ -102,6 +99,8 @@ For example:
|
|
|
102
99
|
通常你只需要导入 `lincy` 预设:
|
|
103
100
|
|
|
104
101
|
#### esm
|
|
102
|
+
如果 package.json 中开启了`"type": "module",`
|
|
103
|
+
|
|
105
104
|
```js
|
|
106
105
|
// eslint.config.js
|
|
107
106
|
import lincy from '@lincy/eslint-config'
|
|
@@ -113,6 +112,8 @@ export default lincy()
|
|
|
113
112
|
```
|
|
114
113
|
|
|
115
114
|
#### cjs
|
|
115
|
+
如果 package.json 中没有开启`"type": "module",`
|
|
116
|
+
|
|
116
117
|
```js
|
|
117
118
|
// eslint.config.js
|
|
118
119
|
const lincy = require('@lincy/eslint-config').lincy
|
|
@@ -128,25 +129,25 @@ import lincy from '@lincy/eslint-config'
|
|
|
128
129
|
|
|
129
130
|
export default lincy({
|
|
130
131
|
// 是否启用 stylistic 格式化规则
|
|
131
|
-
stylistic: true, // 默认值: true
|
|
132
|
+
stylistic: true, // 默认值: true, 可选: false | { indent: number | 'tab', quotes: 'single' | 'double'}
|
|
132
133
|
// 是否启用 typescript 规则
|
|
133
|
-
typescript: true, // 默认值: 检测是否安装typescript
|
|
134
|
+
typescript: true, // 默认值: 检测是否安装typescript依赖, 可选: false
|
|
134
135
|
// 是否启用 vue 规则
|
|
135
|
-
vue: true, // 默认值: 检测是否安装vue
|
|
136
|
+
vue: true, // 默认值: 检测是否安装vue依赖, 可选: false
|
|
136
137
|
// 是否启用 jsonc 规则
|
|
137
|
-
jsonc: false, // 默认值:
|
|
138
|
+
jsonc: false, // 默认值: true, 可选: false
|
|
138
139
|
// 是否启用 yaml 规则
|
|
139
|
-
yaml: false, // 默认值: true
|
|
140
|
+
yaml: false, // 默认值: true, 可选: false
|
|
140
141
|
// 是否启用 .gitignore 文件
|
|
141
|
-
gitignore: false, // 默认值: true
|
|
142
|
+
gitignore: false, // 默认值: true, 可选: false
|
|
142
143
|
// 是否启用 test 规则
|
|
143
|
-
test: false, // 默认值: true
|
|
144
|
+
test: false, // 默认值: true, 可选: false
|
|
144
145
|
// 是否启用 markdown 规则
|
|
145
|
-
markdown: false, // 默认值: true
|
|
146
|
+
markdown: false, // 默认值: true, 可选: false
|
|
146
147
|
// 覆盖规则
|
|
147
148
|
overrides: {},
|
|
148
149
|
|
|
149
|
-
//
|
|
150
|
+
// 工厂函数第一个参数默认为各规则的开关, 但是也可以作为追加规则使用, 当包含以下键名将会自动整合到一个规则里
|
|
150
151
|
files: [],
|
|
151
152
|
ignores: [],
|
|
152
153
|
languageOptions: {},
|
|
@@ -172,7 +173,7 @@ const autoImport = JSON.parse(
|
|
|
172
173
|
|
|
173
174
|
export default lincy(
|
|
174
175
|
{
|
|
175
|
-
|
|
176
|
+
// 配置, 参考上一个代码块
|
|
176
177
|
},
|
|
177
178
|
// 启用 unocss
|
|
178
179
|
{
|
|
@@ -242,13 +243,13 @@ export default [
|
|
|
242
243
|
]
|
|
243
244
|
```
|
|
244
245
|
|
|
245
|
-
查看 [configs](https://github.com/lincenying/eslint-config/blob/main/src/configs) 和 [factory](https://github.com/lincenying/eslint-config/blob/
|
|
246
|
+
查看 [configs](https://github.com/lincenying/eslint-config/blob/main/src/configs) 和 [factory](https://github.com/lincenying/eslint-config/blob/main/src/factory.ts)了解更多详细信息。
|
|
246
247
|
|
|
247
|
-
> Thanks to [sxzz/eslint-config](https://github.com/sxzz/eslint-config) for the inspiration and reference.
|
|
248
|
+
> Thanks to [sxzz/eslint-config](https://github.com/sxzz/eslint-config) and [antfu/eslint-config](https://github.com/antfu/eslint-config) for the inspiration and reference.
|
|
248
249
|
|
|
249
250
|
## Plugins Renaming
|
|
250
251
|
|
|
251
|
-
|
|
252
|
+
由于扁平化配置支持显式提供了插件名称,因此我们重命名了一些插件以使它们更加一致并隐藏实现细节。
|
|
252
253
|
|
|
253
254
|
| New Prefix | Original Prefix | Source Plugin |
|
|
254
255
|
| --- | --- | --- |
|
|
@@ -310,6 +311,9 @@ export default lincy(
|
|
|
310
311
|
import lincy from '@lincy/eslint-config'
|
|
311
312
|
|
|
312
313
|
export default lincy({
|
|
314
|
+
stylistic: {
|
|
315
|
+
indent: 4
|
|
316
|
+
},
|
|
313
317
|
overrides: {
|
|
314
318
|
// 重写vue规则
|
|
315
319
|
vue: {
|
|
@@ -322,7 +326,7 @@ export default lincy({
|
|
|
322
326
|
// 重写js规则
|
|
323
327
|
javascript: {},
|
|
324
328
|
stylistic: {
|
|
325
|
-
'
|
|
329
|
+
'antfu/consistent-list-newline': 'error',
|
|
326
330
|
},
|
|
327
331
|
yaml: {},
|
|
328
332
|
jsonc: {},
|
|
@@ -334,7 +338,7 @@ export default lincy({
|
|
|
334
338
|
'**/assets',
|
|
335
339
|
'**/static',
|
|
336
340
|
]
|
|
337
|
-
|
|
341
|
+
// ...
|
|
338
342
|
}
|
|
339
343
|
})
|
|
340
344
|
```
|
|
@@ -354,6 +358,68 @@ export default lincy({
|
|
|
354
358
|
})
|
|
355
359
|
```
|
|
356
360
|
|
|
361
|
+
### React
|
|
362
|
+
react拓展规则
|
|
363
|
+
|
|
364
|
+
安装react插件
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
npm i -D eslint-plugin-react eslint-plugin-react-hooks
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
```js
|
|
371
|
+
// eslint.config.js
|
|
372
|
+
import lincy from '@lincy/eslint-config'
|
|
373
|
+
import pluginReact from 'eslint-plugin-react'
|
|
374
|
+
import pluginReactHooks from 'eslint-plugin-react-hooks'
|
|
375
|
+
|
|
376
|
+
export default lincy(
|
|
377
|
+
{
|
|
378
|
+
vue: false,
|
|
379
|
+
},
|
|
380
|
+
// react 相关规则
|
|
381
|
+
{
|
|
382
|
+
files: ['**/*.{jsx,tsx}'],
|
|
383
|
+
settings: {
|
|
384
|
+
react: {
|
|
385
|
+
version: '17.0',
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
plugins: {
|
|
389
|
+
'react': pluginReact,
|
|
390
|
+
'react-hooks': pluginReactHooks,
|
|
391
|
+
},
|
|
392
|
+
languageOptions: {
|
|
393
|
+
parserOptions: {
|
|
394
|
+
ecmaFeatures: {
|
|
395
|
+
jsx: true,
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
rules: {
|
|
400
|
+
...pluginReact.configs.all.rules,
|
|
401
|
+
...pluginReactHooks.configs.recommended.rules,
|
|
402
|
+
'react/jsx-filename-extension': 'off', // 禁止可能包含 JSX 文件扩展名
|
|
403
|
+
'react/jsx-first-prop-new-line': 'off', // 强制 JSX 中第一个属性的正确位置
|
|
404
|
+
'react/jsx-no-bind': 'off', // .bind()JSX 属性中禁止使用箭头函数
|
|
405
|
+
'react/forbid-component-props': 'off', // 禁止组件上使用某些 props
|
|
406
|
+
'react/jsx-max-props-per-line': ['error', { maximum: 4 }], // 在 JSX 中的单行上强制执行最多 props 数量
|
|
407
|
+
'react/jsx-no-literals': 'off', // 禁止在 JSX 中使用字符串文字
|
|
408
|
+
'react/jsx-one-expression-per-line': 'off', // 每行一个 JSX 元素
|
|
409
|
+
'react/no-danger': 'off', // 禁止使用 dangerouslySetInnerHTML
|
|
410
|
+
'react/jsx-max-depth': 'off', // 强制 JSX 最大深度
|
|
411
|
+
'react/jsx-newline': 'off', // 在 jsx 元素和表达式之后换行
|
|
412
|
+
'react/require-default-props': 'off', // 为每个非必需 prop 强制执行 defaultProps 定义
|
|
413
|
+
'react/jsx-props-no-spreading': 'off', // 强制任何 JSX 属性都不会传播
|
|
414
|
+
'react/no-unsafe': 'off', // 禁止使用不安全的生命周期方法
|
|
415
|
+
'jsx-quotes': ['error', 'prefer-double'], // 强制在 JSX 属性中一致使用双引号或单引号
|
|
416
|
+
'react/react-in-jsx-scope': 'off', // 使用 JSX 时需要引入 React
|
|
417
|
+
'react/hook-use-state': 'off', // useState 钩子值和 setter 变量的解构和对称命名
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
)
|
|
421
|
+
```
|
|
422
|
+
|
|
357
423
|
### Lint Staged
|
|
358
424
|
|
|
359
425
|
如果你想在每次提交之前应用 lint 和自动修复,你可以将以下内容添加到你的 `package.json` 中:
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
var __accessCheck = (obj, member, msg) => {
|
|
8
|
+
if (!member.has(obj))
|
|
9
|
+
throw TypeError("Cannot " + msg);
|
|
10
|
+
};
|
|
11
|
+
var __privateGet = (obj, member, getter) => {
|
|
12
|
+
__accessCheck(obj, member, "read from private field");
|
|
13
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
14
|
+
};
|
|
15
|
+
var __privateAdd = (obj, member, value) => {
|
|
16
|
+
if (member.has(obj))
|
|
17
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
18
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
19
|
+
};
|
|
20
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
21
|
+
__accessCheck(obj, member, "write to private field");
|
|
22
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
26
|
+
set _(value) {
|
|
27
|
+
__privateSet(obj, member, value, setter);
|
|
28
|
+
},
|
|
29
|
+
get _() {
|
|
30
|
+
return __privateGet(obj, member, getter);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
__publicField,
|
|
36
|
+
__privateGet,
|
|
37
|
+
__privateAdd,
|
|
38
|
+
__privateSet,
|
|
39
|
+
__privateWrapper
|
|
40
|
+
};
|