@persagy2/eslint-plugin
Version:
一个适用于 vue3.x、typescript 项目的通用eslint预设插件
42 lines (38 loc) • 2.62 kB
text/typescript
/** eslint-disable max-len */
import { Linter } from 'eslint'
import { createConfig } from '../utils/create-config'
/**
* 标准规则
*
* @description 应用于对代码质量要求较严格的项目
*/
export const normal: Linter.Config = createConfig()
//
.extends('plugin:@persagy2/parser')
.extends('plugin:@persagy2/basic')
.extends('plugin:@persagy2/deprecated')
.extends('plugin:@persagy2/style')
.level('warn')
/** 避免容易混淆的语法 */
.rule('no-empty') // 避免出现没有任何内容的代码块 (允许填充注释)
.rule('no-empty-pattern') // 避免出现空的解构式
.rule('no-empty-function') // 避免出现空方法 (方法内无任何逻辑, 注释)
.rule('no-loop-func') // 避免在循环中定义方法
.rule('@typescript-eslint/no-loop-func') // 避免在循环中定义方法
.rule('no-case-declarations') // 避免在 case 子句中, 声明新的变量(方法)
.rule('default-case', { commentPattern: 'skip' }) // switch 语句建议包含 `default`
.rule('no-warning-comments', { terms: ['todo', 'TODO'], location: 'anywhere' }) // 当存在 todo 关键字时, 会产生一个警告. 用来提示存在未完成的功能
.rule('vue/no-ref-as-operand') // (fix) 禁止致谢修改 ref 代理的对象, 需要使用 `.value` 进行修改
.rule('vue/prop-name-casing') // 要求组件的props定义命名格式为 camecase
.rule('@typescript-eslint/no-misused-promises', { checksVoidReturn: false }) // 避免滥用 Promise (async)
.rule('@typescript-eslint/no-misused-new') // 避免滥用 new, 警告明显尝试为接口或new类定义构造函数.
.rule('no-promise-executor-return') // 避免在 Promise 块中, 使用 return <value> 语句
.rule('no-unreachable') // 避免出现无法访问的代码, bad: 在return、throw、continue和break语句之后出现无法访问的代码
.rule('no-unused-vars') // 避免出现未使用的变量定义
.rule('@typescript-eslint/no-unused-vars') // 避免出现未使用的变量定义
.rule('vue/no-unused-vars') // 避免出现未使用的变量定义
.rule('no-unused-private-class-members') // 避免出现未使用的私有类成员变量
.rule('@typescript-eslint/no-empty-function') // 避免出现空方法 (方法内无任何逻辑)
.rule('vue/eqeqeq') // 要求使用更安全地 `===` , `!==` 进行判断
.rule('no-async-promise-executor') // 避免在 Promise 块中使用 async/await函数, 因为异步异常会出现无法被捕获的情况
.config()