@lincy/eslint-config 3.7.0 → 4.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/README.md CHANGED
@@ -6,8 +6,8 @@
6
6
 
7
7
  - 单引号,无结尾分号
8
8
  - 自动格式化
9
- - 专为与 TypeScript、Vue(2/3) 一起使用而设计,开箱即用
10
- - 也适用于 json、yaml、markdown、react
9
+ - 专为与 TypeScript、Vue(2/3)、React 一起使用而设计,开箱即用
10
+ - 也适用于 json、yaml、markdown
11
11
  - import导入排序, 对象字⾯量项尾逗号
12
12
  - 合理的默认值,最佳实践,只需一行配置
13
13
  - [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new)
@@ -131,23 +131,45 @@ import lincy from '@lincy/eslint-config'
131
131
 
132
132
  export default lincy({
133
133
  // 是否启用 stylistic 格式化规则
134
- stylistic: true, // 默认值: true, 可选: false | { indent: number | 'tab', quotes: 'single' | 'double', jsx: boolean}
134
+ // 默认值: true
135
+ // 可选: false | { indent: number | 'tab', quotes: 'single' | 'double', jsx: boolean}
136
+ stylistic: true,
135
137
  // 是否启用 typescript 规则
136
- typescript: true, // 默认值: 检测是否安装typescript依赖, 可选: false | true
138
+ // 默认值: 检测是否安装typescript依赖,
139
+ // 可选: false | true | { parserOptions: {} }
140
+ typescript: true,
137
141
  // 是否启用 vue 规则
138
- vue: true, // 默认值: 检测是否安装vue依赖, 可选: false | true
142
+ // 默认值: 检测是否安装vue依赖,
143
+ // 可选: false | true
144
+ vue: true,
139
145
  // 是否启用 jsx 规则
140
- jsx: true, // 默认值: true, 可选: false
146
+ // 默认值: true,
147
+ // 可选: false
148
+ jsx: true,
149
+ // 是否启用 react 规则
150
+ // 默认值: 检测是否安装react依赖,
151
+ // 可选: false | true | { jsx: boolean, version: string }
152
+ react: true,
141
153
  // 是否启用 jsonc 规则
142
- jsonc: false, // 默认值: true, 可选: false
154
+ // 默认值: true,
155
+ // 可选: false
156
+ jsonc: false,
143
157
  // 是否启用 yaml 规则
144
- yaml: false, // 默认值: true, 可选: false
158
+ // 默认值: true,
159
+ // 可选: false
160
+ yaml: false,
145
161
  // 是否启用 .gitignore 文件
146
- gitignore: false, // 默认值: true, 可选: false
162
+ // 默认值: true,
163
+ // 可选: false | { ignores: string[] }
164
+ gitignore: false,
147
165
  // 是否启用 test 规则
148
- test: false, // 默认值: true, 可选: false
166
+ // 默认值: true,
167
+ // 可选: false
168
+ test: false,
149
169
  // 是否启用 markdown 规则
150
- markdown: false, // 默认值: true, 可选: false
170
+ // 默认值: true,
171
+ // 可选: false
172
+ markdown: false,
151
173
  // 覆盖规则
152
174
  overrides: {},
153
175
 
@@ -208,11 +230,12 @@ export default lincy(
208
230
  )
209
231
  ```
210
232
 
211
- 更高级的是,您还可以导入非常细粒度的配置并根据需要组合它们:
233
+ 您还可以导入非常细粒度的配置并根据需要组合它们:
212
234
 
213
235
  ```js
214
236
  // eslint.config.js
215
237
  import {
238
+ combine,
216
239
  comments,
217
240
  ignores,
218
241
  imports,
@@ -222,6 +245,7 @@ import {
222
245
  markdown,
223
246
  node,
224
247
  perfectionist,
248
+ react,
225
249
  sortPackageJson,
226
250
  sortTsconfig,
227
251
  stylistic,
@@ -231,22 +255,23 @@ import {
231
255
  yaml,
232
256
  } from '@lincy/eslint-config'
233
257
 
234
- export default [
235
- ...ignores(),
236
- ...javascript(/* Options */),
237
- ...comments(),
238
- ...node(),
239
- ...jsdoc(),
240
- ...imports(),
241
- ...unicorn(),
242
- ...perfectionist(),
243
- ...typescript(/* Options */),
244
- ...stylistic(),
245
- ...vue(),
246
- ...jsonc(),
247
- ...yaml(),
248
- ...markdown(),
249
- ]
258
+ export default combine(
259
+ ignores(),
260
+ javascript(/* Options */),
261
+ comments(),
262
+ node(),
263
+ jsdoc(),
264
+ imports(),
265
+ unicorn(),
266
+ perfectionist(),
267
+ typescript(/* Options */),
268
+ stylistic(/* Options */),
269
+ vue(),
270
+ react(/* Options */),
271
+ jsonc(),
272
+ yaml(),
273
+ markdown(),
274
+ )
250
275
  ```
251
276
 
252
277
  查看 [configs](https://github.com/lincenying/eslint-config/blob/main/src/configs) 和 [factory](https://github.com/lincenying/eslint-config/blob/main/src/factory.ts)了解更多详细信息。
@@ -285,6 +310,7 @@ export default lincy(
285
310
  isInEditor: true,
286
311
  vue: true,
287
312
  jsx: true,
313
+ react: true,
288
314
  typescript: true,
289
315
  stylistic: true,
290
316
  gitignore: true,
@@ -321,16 +347,23 @@ export default lincy({
321
347
  indent: 4
322
348
  },
323
349
  overrides: {
324
- // 重写vue规则
350
+ // 覆盖 vue 规则
325
351
  vue: {
326
352
  'vue/operator-linebreak': ['error', 'before'],
327
353
  },
328
- // 重写ts规则
354
+ // 覆盖 react 规则
355
+ react: {
356
+ 'react/forbid-component-props': 'error',
357
+ },
358
+ // 覆盖 ts 规则
329
359
  typescript: {
330
360
  'ts/consistent-type-definitions': ['error', 'interface'],
331
361
  },
332
- // 重写js规则
333
- javascript: {},
362
+ // 覆盖 js 规则
363
+ javascript: {
364
+ 'no-undef': 'off',
365
+ },
366
+ // 覆盖 stylistic 规则
334
367
  stylistic: {
335
368
  'antfu/consistent-list-newline': 'error',
336
369
  },
@@ -383,70 +416,6 @@ export default lincy({
383
416
  })
384
417
  ```
385
418
 
386
- ### React
387
- react拓展规则
388
-
389
- 安装react插件
390
-
391
- ```bash
392
- npm i -D eslint-plugin-react eslint-plugin-react-hooks
393
- ```
394
-
395
- ```js
396
- // eslint.config.js
397
- import lincy from '@lincy/eslint-config'
398
- import pluginReact from 'eslint-plugin-react'
399
- import pluginReactHooks from 'eslint-plugin-react-hooks'
400
-
401
- export default lincy(
402
- {
403
- vue: false,
404
- // 关闭stylistic提供的jsx规则, 直接使用eslint-plugin-react
405
- jsx: false,
406
- },
407
- // react 相关规则
408
- {
409
- files: ['**/*.{jsx,tsx}'],
410
- settings: {
411
- react: {
412
- version: '17.0',
413
- },
414
- },
415
- plugins: {
416
- 'react': pluginReact,
417
- 'react-hooks': pluginReactHooks,
418
- },
419
- languageOptions: {
420
- parserOptions: {
421
- ecmaFeatures: {
422
- jsx: true,
423
- },
424
- },
425
- },
426
- rules: {
427
- ...pluginReact.configs.all.rules,
428
- ...pluginReactHooks.configs.recommended.rules,
429
- 'react/jsx-filename-extension': 'off', // 禁止可能包含 JSX 文件扩展名
430
- 'react/jsx-first-prop-new-line': 'off', // 强制 JSX 中第一个属性的正确位置
431
- 'react/jsx-no-bind': 'off', // .bind()JSX 属性中禁止使用箭头函数
432
- 'react/forbid-component-props': 'off', // 禁止组件上使用某些 props
433
- 'react/jsx-max-props-per-line': ['error', { maximum: 4 }], // 在 JSX 中的单行上强制执行最多 props 数量
434
- 'react/jsx-no-literals': 'off', // 禁止在 JSX 中使用字符串文字
435
- 'react/jsx-one-expression-per-line': 'off', // 每行一个 JSX 元素
436
- 'react/no-danger': 'off', // 禁止使用 dangerouslySetInnerHTML
437
- 'react/jsx-max-depth': 'off', // 强制 JSX 最大深度
438
- 'react/jsx-newline': 'off', // 在 jsx 元素和表达式之后换行
439
- 'react/require-default-props': 'off', // 为每个非必需 prop 强制执行 defaultProps 定义
440
- 'react/jsx-props-no-spreading': 'off', // 强制任何 JSX 属性都不会传播
441
- 'react/no-unsafe': 'off', // 禁止使用不安全的生命周期方法
442
- 'jsx-quotes': ['error', 'prefer-double'], // 强制在 JSX 属性中一致使用双引号或单引号
443
- 'react/react-in-jsx-scope': 'off', // 使用 JSX 时需要引入 React
444
- 'react/hook-use-state': 'off', // useState 钩子值和 setter 变量的解构和对称命名
445
- },
446
- },
447
- )
448
- ```
449
-
450
419
  ### Lint Staged
451
420
 
452
421
  如果你想在每次提交之前应用 lint 和自动修复,你可以将以下内容添加到你的 `package.json` 中: