@persagy2/eslint-plugin
Version:
一个适用于 vue3.x、typescript 项目的通用eslint预设插件
40 lines (34 loc) • 1.8 kB
text/typescript
/** eslint-disable max-len */
import { Linter } from 'eslint'
import { createConfig } from '../utils/create-config'
/**
* 编码复杂度校验策略
*
* 规则包含:
* 1. 强制性语义语法校验
* 2. 编码范式
* 3. 注释完善性
*/
export const complexity: Linter.Config = createConfig()
.extends('plugin:@persagy2/parser')
.level('warn')
/* 要求代码质量的限定阈值 */
/** (建议) 单行代码, 最多包含3条逻辑 */
.rule('max-statements-per-line', { max: 6 })
/** (建议) 回调函数(callback)层级不超过3层 */
.rule('max-nested-callbacks', { max: 4 })
/** (建议) if-else-if 复杂度不超过 12 层 */
.rule('complexity', { max: 12 })
/** (建议) 条件判断嵌套深度不超过6层 */
.rule('max-depth', { max: 6 })
/** (建议) 方法参数个数不超过6个, 超过应合并对象 */
.rule('max-params', { max: 6 })
.rule('no-sequences') // 避免使用逗号运算符(,)简写语句, 会增加理解难度. bad: return (a = a + b), a
.rule('no-array-constructor') // 禁止使用 Array 构造函数创建数组, bad: new Array(1,2,3,4...)
.rule('no-cond-assign') // 禁止在 if, for, while,do ... while 语句中使用赋值语句, 因为这样会增加理解难度, bad: if (user.jobTitle = "manager")
.rule('no-multi-assign') // 禁止多重赋值, bad: a = b = 1
.rule('no-return-assign') // 禁止在return语句中使用赋值运算符, bad: return foo = bar + 2;
// vue 特性
.rule('vue/no-use-computed-property-like-method') // 避免将计算属性的结果作为方法使用
.rule('vue/no-side-effects-in-computed-properties') // 避免在计算属性中, 修改 vue 对象本身属性
.config()