UNPKG

@persagy2/eslint-plugin

Version:

一个适用于 vue3.x、typescript 项目的通用eslint预设插件

104 lines (98 loc) 3.15 kB
import { ESLint, Linter } from 'eslint' import { rules } from './rules' import { parser } from './parser' import { basic } from './config/basic' import { style } from './config/style' import { deprecated } from './config/deprecated' import { comment } from './config/comment' import { complexity } from './config/complexity' import { normal } from './config/normal' import { strict } from './config/strict' /** @persagy2/eslint-plugin 规则预设 */ export default <ESLint.Plugin>{ /** 特定后缀的文件处理器 */ processors: { '.d.ts': require('@typescript-eslint/parser'), '.vue': require('eslint-plugin-vue/lib/processor') }, /** 框架内置的自定义规则 (规则扩展) */ rules, /** 可选规则模板 */ configs: { /** 解析器配置 */ parser, /** 语义语法、编码安全性检查 (一般不需要启用, 包含完整的语法语义规则校验, 可能会拖慢lint速度) */ basic, /** 编码风格检查 */ style, /** 废弃语法特性检查 (vue3.x) */ deprecated, /** 注释完善性检查 */ comment, /** 编码复杂度检查 */ complexity, /** 标准(完整)规则 * * @包含 * 1. 语义语法、编码安全性检查 * 2. 废弃语法特性检查 (vue3.x) * 3. 编码风格检查 * 4. 编码复杂度 */ normal, /** * 严格(完整)规则 * * @description 在标准规则的基础上, 增加编码复杂度、注释规范检查 */ strict } } export interface ICreateConfig { /** * 校验策略 * * @default basic */ strategy?: | 'basic' // 校验是否存在编码错误, 安全性问题 | 'style' // 仅校验编码风格 | 'normal' // 完整校验 | 'strict' // 严格校验 /** * 是否禁用 eslint检查 * * @description 开发阶段, 可以通过这个属性禁用 eslint 检查 */ disable?: boolean /** 是否处于本地开发阶段 (本地开发时, 仅包含编码风格检查) */ dev?: boolean } /** 创建 eslint校验规则配置 */ export const createEslintConfig = (options: ICreateConfig): Linter.Config => { const { strategy, disable, dev } = options if (disable) { return { root: true, extends: ['plugin:@persagy2/parser'] } } else if (strategy === 'style' || dev) { return { root: true, /** 配置规则等级 */ extends: ['plugin:@persagy2/style'] } } else if (strategy === 'normal') { return { root: true, /** 配置规则等级 */ extends: ['plugin:@persagy2/normal'] } } else if (strategy === 'strict') { return { root: true, /** 配置规则等级 */ extends: ['plugin:@persagy2/strict'] } } }