-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheslint.config.js
More file actions
149 lines (134 loc) · 5.43 KB
/
eslint.config.js
File metadata and controls
149 lines (134 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import antfu from '@antfu/eslint-config'
import {
docComment,
forceTernary,
reactVIf,
} from '@jl-org/eslint-plugins'
export default antfu({
/**
* Style
*/
stylistic: {
indent: 2,
quotes: 'single',
semi: false,
overrides: {
'no-console': 'off', // 使用 console 时发出警告
'no-empty': 'warn', // 空代码块时发出警告
'unused-imports/no-unused-vars': 'warn', // 未使用的变量或导入时发出警告
'no-async-promise-executor': 'off', // 允许在 Promise 构造函数中使用 async 函数
'node/prefer-global/process': 'off', // 不强制使用全局的 process 对象
'eqeqeq': 'off', // 不强制使用 === 和 !==
'no-sequences': 'off', // 允许使用逗号操作符
'no-extend-native': 'off', // 允许扩展原生对象的原型
'ts/ban-ts-comment': 'off', // 允许使用 @ts-ignore 等 TypeScript 注释
'unicorn/no-new-array': 'off', // 允许使用 new Array()
'ts/no-unsafe-function-type': 'off', // 允许不安全的函数类型
'eslint-comments/no-unlimited-disable': 'off', // 允许无限禁用 ESLint 规则
'prefer-promise-reject-errors': 'off', // 允许 Promise.reject() 不传参数
'no-useless-return': 'off', // 允许无用的 return 语句
'style/no-mixed-operators': 'off', // 允许混合使用不同的操作符
'operator-linebreak': ['off', 'after', { /** 操作符换行时放在行尾 */
overrides: {
'||': 'after', // 逻辑或操作符放在行尾
'&&': 'after', // 逻辑与操作符放在行尾
'?': 'before', // 三元操作符的问号放在行首
':': 'before', // 三元操作符的冒号放在行首
},
}],
'ts/no-use-before-define': 'off', // 允许在定义前使用变量
'ts/consistent-type-definitions': 'off', // 允许使用 interface 和 type 定义类型
'no-new': 'off',
'style/max-statements-per-line': 'off', // 允许每行语句数量不超过 1
'no-case-declarations': 'off', // 允许 switch case 语句中出现变量声明
'accessor-pairs': 'off', // 允许在 getter 和 setter 中使用 accessor pairs
'no-alert': 'off', // 允许使用 alert()
'no-new-func': 'off', // 允许使用 new Function()
'node/prefer-global/buffer': 'off', // 允许使用全局 Buffer
'no-cond-assign': 'off', // 允许在条件语句中赋值
'antfu/no-top-level-await': 'off',
/**
* 这个配置没用,还是删除换行,几十年了也不修复
* 给个错误的配置关掉它
*/
/**
* 'no-multiple-empty-lines': ['error', { max: 3, maxBOF: 0, maxEOF: 0 }],
* 'no-multiple-empty-lines': {},
*/
},
},
/**
* Language config
*/
jsonc: false,
regexp: false,
unocss: false,
typescript: true,
markdown: false,
/**
* eslint-config 只对 Vue 和 TypeScript 有天然的支持
* 如果你需要对第三方框架进行支持,需要自行开启
* 开启后 运行 npx eslint 会提示你缺少的插件
* 如 React Svelte Astro Solid UnoCSS
*/
react: {
overrides: {
/** JSX 表达式中花括号中添加空格 */
'style/jsx-curly-spacing': [
'error',
{ when: 'always' }, // 总是在花括号内添加空格
],
/** return JSX 时不换行加上括号 */
'style/jsx-wrap-multilines': [
'error',
{
declaration: false, // 允许声明时不换行
assignment: false, // 允许赋值时不换行
return: false, // 允许 return 时不换行
arrow: false, // 允许箭头函数时不换行
condition: false, // 允许条件表达式时不换行
logical: false, // 允许逻辑表达式时不换行
prop: false, // 允许属性时不换行
},
],
'style/jsx-closing-tag-location': 'off', // 关闭 JSX 闭合标签位置检查
'style/jsx-closing-bracket-location': 'off', // 关闭 JSX 闭合括号位置检查
'react/no-unstable-default-props': 'off', // 关闭不稳定的默认 props 检查
'react-web-api/no-leaked-timeout': 'off', // 允许 setTimeout 后没有 clearTimeout
'react-dom/no-missing-button-type': 'off', // 允许 button 元素没有 type 属性
'react-refresh/only-export-components': 'off', // 允许导出 * type
'react/no-clone-element': 'off', // 允许 cloneElement
'react/no-children-to-array': 'off', // 允许 Children.toArray
'react/no-create-ref': 'off', // 允许 createRef
'react/no-forward-ref': 'off', // 允许 react19 forwardRef
'react-dom/no-flush-sync': 'off', // 允许 flushSync
'react/no-context-provider': 'off', // 允许 Context.Provider
},
},
ignores: [
'dist',
'public',
'node_modules',
'**/*.json',
'**/*.jsonc',
'**/*.json5',
'**/*.d.ts',
],
/**
* 自定义插件
*/
plugins: {
forceTernary, // 自定义插件:三目运算分为三行
docComment, // 自定义插件:将注释转换为文档注释
reactVIf, // 自定义插件:v-if 转 JSX
},
/**
* 自定义规则
*/
rules: {
'forceTernary/forceTernary': 'warn', // 三目运算分为三行
/** 将 中文 或者 NOTE: 开头的注释转换为文档注释 */
'docComment/docComment': ['warn', { pattern: '^(?:[\\u4E00-\\u9FA5\\u3000-\\u303F\\uFF00-\\uFFEF]|NOTE:)' }],
'reactVIf/reactVIf': 'error', // v-if 转 JSX
},
})