1.0.0 • Published 7 months ago
eslint-config-enn v1.0.0
规则介绍
这套规则是用于规范新奥数能团队开发习惯的一套基于eslint-config-airbnb拓展的一套eslint规则
安装(搭配prettier插件)
│ index.js ----------规则入口
│ package-lock.json
│ package.json
│ readme.md
│ tree.txt
│
└─rules
best-pratices.js ----------最佳实践规则
error.js ----------possible error 规则
es6.js ----------
import.js ----------导入规则
strict.js ----------严格规则
styles.js ----------代码样式风格规则
variables.js ----------变量规则
npm i @shuneng/eslint-config-enn -D --registry=https://registry-npm.ennew.com/
// prettier.config.js 具体需要个性化配置的请自行去官网查看[官网地址](https://prettier.io/docs/en/options.html#arrow-function-parentheses)
module.exports = {
printWidth: 300,
useTabs: false, // 是否使用t
singleQuote: true, // 使用单引号(默认false)
bracketSpacing: true, // 对象字面量的大括号间使用空格(默认true)
arrowParens: 'avoid', // 尽可能减少箭头函数括号
trailingComma: 'all', // 拖尾逗号
};
/**
* 内置了如下的全局变量
* require: 0,
Vue: 0,
'$': 0,
globalThis: 0,
Element: 0,
Vant: 0,
module: 0
*
*/
本规则囊括了默认规则以及eslint-config-airbnb,覆盖了官网的大部分规则
规则详情如需查看可访问 eslint 进行查阅
已启用规则
规则名称 | 规则介绍 | 预警级别 | 是否可以fix |
---|---|---|---|
for-direction | 强制 “for” 循环中更新子句的计数器朝着正确的方向移动 | error | 否 |
getter-return | 强制 getter 函数中出现 return 语句 | error | 否 |
no-async-promise-executor | 禁止使用异步函数作为执行函数 | error | 否 |
no-await-in-loop | 禁止在循环中出现 await | error | 否 |
no-compare-neg-zero | 禁止与 -0 进行比较 | error | 否 |
no-cond-assign | 禁止条件表达式中出现赋值操作符 | warn | 否 |
no-console | 禁用 console | warn | 否 |
no-constant-condition | 禁止在条件中使用常量表达式 | error | 否 |
no-control-regex | 禁止在正则表达式中使用控制字符 | warn | 否 |
no-debugger | 禁用 debugger | warn | 否 |
no-dupe-args | 禁止 function 定义中出现重名参数 | error | 否 |
no-dupe-else-if | 禁止重复的eles if 语句 | error | 否 |
no-dupe-keys | 禁止对象字面量中出现重复的key | error | 否 |
no-duplicate-case | 禁止出现重复的 case 标签 | error | 否 |
no-empty | 禁止出现空语句块 | warn | 否 |
no-empty-character-class | 禁止在正则表达式中使用空字符集 | error | 否 |
no-ex-assign | 禁止对 catch 子句的参数重新赋值 | error | 否 |
no-extra-boolean-cast | 禁止不必要的布尔转换 | warn | 是 |
no-extra-parens | 禁止不必要的括号 | off | 是 |
no-extra-semi | 禁止不必要的分号 | error | 是 |
no-func-assign | 禁止对 function 声明重新赋值 | error | 否 |
no-import-assign | 禁止对导入模块重新赋值 | error | 否 |
no-inner-declarations | 禁止在嵌套的块中出现变量声明或 function 声明 | error | 否 |
no-invalid-regexp | 禁止 RegExp 构造函数中存在无效的正则表达式字符串 | error | 否 |
no-irregular-whitespace | 禁止不规则的空白 | warn | 否 |
no-loss-of-precision | 禁止丢失精度的数字文字 | off | 否 |
no-misleading-character-class | 不允许在字符类语法中出现由多个代码点组成的字符 | error | 否 |
no-promise-executor-return | 禁止promise 返回值 | error | 否 |
no-obj-calls | 禁止把全局对象作为函数调用 | error | 否 |
no-prototype-builtins | 禁止直接调用 Object.prototypes 的内置属性 | warn | 否 |
no-regex-spaces | 禁止正则表达式字面量中出现多个空格 | error | 是 |
no-setter-return | 禁止setter 返回值 | off | 否 |
no-sparse-arrays | 禁用稀疏数组 | error | 否 |
no-template-curly-in-string | 禁止在常规字符串中使用模板文字占位符语法 | error | 否 |
no-unreachable | 禁止在 return、throw、continue 和 break 语句之后出现不可达代码 | error | 否 |
no-unreachable-loop | 禁止循环体中只执行一次迭代 | off | 否 |
no-unsafe-finally | 禁止在 finally 语句块中出现控制流语句 | error | 否 |
no-unsafe-negation | 禁止对关系运算符的左操作数使用否定操作符 | off | 否 |
no-useless-backreference | 禁止在正则表达式中使用无用的反向引用 | off | 否 |
no-negated-in-lhs | 不允许对 in 表达式的左操作数取反 | off | 否 |
require-atomic-updates | 禁止由于 await 或 yield的使用而可能导致出现竞态条件的赋值 | off | 否 |
use-isnan | 禁止与值 NaN 进行比较 | warn | 否 |
valid-jsdoc | 确保 JSDoc 注释有效 | off | 否 |
valid-typeof | 确保将 typeof 的结果与有效字符串进行比较 | error | 否 |
arrow-body-style | 要求箭头函数体使用大括号 | warn | 是 |
arrow-parens | 要求箭头函数的参数使用圆括号 | warn | 是 |
arrow-spacing | 箭头函数的箭头前后使用一致的空格 | warn | 是 |
constructor-super | 要求在构造函数中有 super() 的调用 | error | 否 |
generator-star-spacing | 强制 generator 函数中 * 号周围使用一致的空格 | warn | 是 |
no-class-assign | 禁止修改类声明的变量 | error | 否 |
no-confusing-arrow | 禁止在可能与比较操作符相混淆的地方使用箭头函数 | warn | 是 |
no-const-assign | 禁止修改 const 声明的变量 | error | 否 |
no-dupe-class-members | 禁止类成员中出现重复的名称 | error | 否 |
no-duplicate-imports | 禁止重复模块导入 | warn | 否 |
no-new-symbol | 禁止 Symbolnew 操作符和 new 一起使用 | error | 否 |
no-restricted-exports | 禁止导出中的指定名称 | off | 否 |
no-restricted-imports | 禁止导入中的指定名称 | off | 否 |
no-this-before-super | 禁止在构造函数中,在调用 super() 之前使用 this 或 super | error | 否 |
no-useless-computed-key | 禁止在对象中使用不必要的计算属性 | warn | 是 |
no-useless-constructor | 禁用不必要的构造函数 | warn | 否 |
no-useless-rename | 禁止在 import 和 export 和解构赋值时将引用重命名为相同的名字 | error | 是 |
no-var | 要求使用 let 或 const 而不是 var | error | 是 |
object-shorthand | 要求或禁止对象字面量中方法和属性使用简写语法 | warn | 是 |
prefer-arrow-callback | 要求回调函数使用箭头函数 | off | 是 |
prefer-const | 要求使用 const 声明那些声明后不再被修改的变量 | warn | 是 |
prefer-destructuring | 优先使用数组和对象解构 | off | 是 |
prefer-numeric-literals | 禁用 parseInt() 和 Number.parseInt(),使用二进制,八进制和十六进制字面量 | off | 是 |
prefer-reflect | 优先使用Reflect | off | 否 |
prefer-rest-params | 要求使用剩余参数而不是 arguments | warn | 否 |
prefer-spread | 要求使用扩展运算符而非 .apply() | off | 否 |
prefer-template | 要求使用模板字面量而非字符串连接 | warn | 是 |
require-yield | 要求 generator 函数内有 yield | off | 否 |
rest-spread-spacing | 强制剩余和扩展运算符及其表达式之间有空格 | off | 是 |
sort-imports | 强制模块内的 import 排序 | off | 是 |
symbol-description | 要求 symbol 描述 | warn | 否 |
template-curly-spacing | 要求或禁止模板字符串中的嵌入表达式周围空格的使用 | warn | 是 |
yield-star-spacing | 强制在 yield 表达式中 周围使用空格 | warn | 是 |
init-declarations | 要求或禁止声明中的初始化 | off | 否 |
no-delete-var | 禁止删除变量 | error | 否 |
no-label-var | 不允许标签与变量同名 | error | 否 |
no-shadow | 禁止变量声明与外层作用域的变量同名 | off | 否 |
no-shadow-restricted-names | 禁止将标识符定义为受限的名字 | error | 否 |
no-undef | 禁用未声明的变量,除非它们在 /global / 注释中被提到 | error | 否 |
no-undef-init | 禁止将变量初始化为 undefined | off | 是 |
no-undefined | 禁止将 undefined 作为标识符 | off | 否 |
no-unused-vars | 禁止出现未使用过的变量 | warn | 否 |
no-use-before-define | 禁止在变量定义之前使用它们 | error | 否 |
array-bracket-newline | 在数组开括号后和闭括号前强制换行 | off | 是 |
array-element-newline | 强制数组元素间出现换行 | warn | 是 |
array-bracket-spacing | 禁止或强制在括号内使用空格 | warn | 是 |
block-spacing | 禁止或强制在代码块中开括号前和闭括号后有空格 | warn | 是 |
brace-style | 强制在代码块中使用一致的大括号风格 | warn | 是 |
camelcase | 强制使用骆驼拼写法命名约定 | off | 否 |
capitalized-comments | 强制或禁止对注释的第一个字母大写 | off | 是 |
comma-dangle | 要求或禁止末尾逗号 | warn | 是 |
comma-spacing | 强制在逗号前后使用一致的空格 | warn | 是 |
comma-style | 强制使用一致的逗号风格 | warn | 是 |
computed-property-spacing | 强制在计算的属性的方括号中使用一致的空格 | warn | 是 |
consistent-this | 当获取当前执行环境的上下文时,强制使用一致的命名 | off | 否 |
eol-last | 要求或禁止文件末尾存在空行 | off | 是 |
func-call-spacing | 要求或禁止在函数标识符和其调用之间有空格 | warn | 是 |
func-names | 要求或禁止使用命名的 function 表达式 | off | 否 |
func-style | 强制使用函数声明或表达式 | off | 否 |
function-paren-newline | 强制在函数括号内使用一致的换行 | warn | 是 |
id-blacklist | 将某些标识符列入黑名单以防止它们被使用 | off | 否 |
id-denylist | 禁止指定标识符 | off | 否 |
implicit-arrow-linebreak | 强制隐式返回的箭头函数体的位置 | warn | 是 |
indent | 强制使用一致的缩进 | warn | 是 |
jsx-quotes | 强制在 JSX 属性中一致地使用双引号或单引号 | off | 是 |
key-spacing | 强制在对象字面量的属性中键和值之间使用一致的间距 | warn | 是 |
line-comment-position | 强制行注释的位置 | off | 否 |
linebreak-style | 强制使用一致的换行风格 | off | 是 |
lines-between-class-members | 要求或禁止类成员之间出现空行 | warn | 否 |
lines-around-comment | 要求在注释周围有空行 | off | 否 |
lines-around-directive | 要求或禁止在指令周围换行 | warn | 是 |
max-len | 强制一行的最大长度 | off | 否 |
max-depth | 强制可嵌套的块的最大深度 | off | 否 |
max-lines | 强制最大行数 | off | 否 |
max-lines-per-function | 强制函数最大代码行数 | off | 否 |
max-nested-callbacks | 强制回调函数最大嵌套深度 | off | 否 |
max-params | 强制函数定义中最多允许的参数数量 | off | 否 |
max-statements | 强制函数块最多允许的的语句数量 | off | 否 |
max-statements-per-line | 强制每一行中所允许的最大语句数量 | off | 否 |
multiline-comment-style | 强制对多行注释使用特定风格 | off | 是 |
multiline-ternary | 要求或禁止在三元操作数中间换行 | off | 否 |
new-cap | 要求构造函数首字母大写 | error | 否 |
new-parens | 强制或禁止调用无参构造函数时有圆括号 | off | 是 |
newline-after-var | 定义后留一空行 | off | 是 |
newline-before-return | reaturn前留一空行 | off | 是 |
newline-per-chained-call | 要求方法链中每个调用都有一个换行符 | warn | 是 |
no-array-constructor | 禁用 Array 构造函数 | error | 否 |
no-bitwise | 禁用按位运算符 | off | 否 |
no-continue | 禁用 continue 语句 | off | 否 |
no-inline-comments | 禁止在代码后使用内联注释 | off | 否 |
no-lonely-if | 禁止 if 作为唯一的语句出现在 else 语句中 | warn | 否 |
no-mixed-operators | 禁止混合使用不同的操作符 | off | 否 |
no-mixed-spaces-and-tabs | 禁止空格和 tab 的混合缩进 | error | 是 |
no-multi-assign | 禁止连续赋值 | warn | 否 |
no-multiple-empty-lines | 禁止出现多行空行 | warn | 是 |
no-negated-condition | 禁用否定的表达式 | off | 否 |
no-nested-ternary | 禁用嵌套的三元表达式 | off | 否 |
no-new-object | 禁用object构造函数 | off | 否 |
no-plusplus | 禁止使用一元运算符 | off | 否 |
no-restricted-syntax | 禁用特殊语法 | off | 否 |
no-spaced-func | 禁止函数标识符和应用程序之间的空间 | warn | 否 |
no-tabs | 禁用tab | off | 否 |
no-ternary | 禁用三元操作符 | off | 否 |
no-trailing-spaces | 禁用行尾空格 | off | 是 |
no-underscore-dangle | 禁止标识符中有悬空下划线 | off | 否 |
no-unneeded-ternary | 禁止可以在有更简单的可替代的表达式时使用三元操作符 | warn | 否 |
no-whitespace-before-property | 禁止属性前有空白 | warn | 是 |
nonblock-statement-body-position | 强制单个语句的位置 | warn | 是 |
object-curly-spacing | 强制在大括号中使用一致的空格 | warn | 是 |
object-curly-newline | 强制大括号内换行符的一致性 | warn | 是 |
object-property-newline | 强制将对象的属性放在不同的行上 | warn | 是 |
one-var | 强制函数中的变量要么一起声明要么分开声明 | off | 是 |
one-var-declaration-per-line | 要求或禁止在变量声明周围换行 | off | 是 |
operator-assignment | 要求或禁止在可能的情况下使用简化的赋值操作符 | warn | 是 |
operator-linebreak | 强制操作符使用一致的换行符 | warn | 是 |
padded-blocks | 要求或禁止块内填充 | warn | 否 |
padding-line-between-statements | 要求或禁止在语句间填充空行 | off | 是 |
prefer-exponentiation-operator | 禁止使用 Math.pow 来支持 ** 运算符 | off | 否 |
prefer-object-spread | 禁止使用以对象字面量作为第一个参数的 Object.assign,优先使用对象扩展 | off | 是 |
quote-props | 要求对象字面量属性名称用引号括起来 | warn | 是 |
quotes | 强制使用一致的反勾号、双引号或单引号 | off | 是 |
require-jsdoc | 不需要jsdoc | off | 否 |
semi | 要求或禁止使用分号代替 | warn | 是 |
semi-spacing | 强制分号之前和之后使用一致的空格 | warn | 是 |
semi-style | 强制分号的位置 | warn | 是 |
sort-keys | 要求对象属性按序排列 | off | 否 |
sort-vars | 要求同一个声明块中的变量按顺序排列 | off | 是 |
space-before-blocks | 强制在块之前使用一致的空格 | warn | 是 |
space-before-function-paren | 强制在 function的左括号之前使用一致的空格 | warn | 是 |
space-in-parens | 强制在圆括号内使用一致的空格 | warn | 是 |
space-infix-ops | 要求操作符周围有空格 | warn | 是 |
space-unary-ops | 强制在一元操作符前后使用一致的空格 | warn | 是 |
spaced-comment | 强制在注释中 // 或 /* 使用一致的空格 | off | 否是 |
switch-colon-spacing | 强制在 switch 的冒号左右有空格 | warn | 是 |
template-tag-spacing | 要求或禁止在模板标记和它们的字面量之间有空格 | off | 是 |
unicode-bom | 要求或禁止 Unicode 字节顺序标记 | off | 是 |
wrap-regex | 要求正则表达式被括号括起来 | off | 是 |
accessor-pairs | 强制getter/setter成对出现 | off | 否 |
array-callback-return | 在数组方法的回调中强制执行 return 语句 | off | 否 |
block-scoped-var | 强制把变量的使用限制在其定义的作用域范围内 | warn | 否 |
complexity | 指定程序中允许的最大环路复杂度 | off | 否 |
class-methods-use-this | 强制类方法使用 this | off | 否 |
consistent-return | 要求 return 语句要么总是指定返回的值,要么不指定 | off | 否 |
curly | 强制所有控制语句使用一致的括号风格 | warn | 是 |
default-case | 要求 switch 语句中有 default 分支 | warn | 否 |
dot-notation | 强制尽可能地使用点号 | warn | 否 |
dot-location | 强制在点号之前和之后一致的换行 | warn | 是 |
eqeqeq | 要求使用 === 和 !== | error | 是 |
guard-for-in | 要求 for-in 循环中有一个 if 语句 | warn | 否 |
max-classes-per-file | 强制每个文件中包含的的类的最大数量 | error | 否 |
no-alert | 禁用 alert、confirm 和 prompt | warn | 否 |
no-caller | 禁用 arguments.caller 或 arguments.callee | error | 否 |
no-case-declarations | 不允许在 case 子句中使用词法声明 | off | 否 |
no-else-return | 禁止 if 语句中 return 语句之后有 else 块 | warn | 是 |
no-empty-function | 禁止出现空函数 | warn | 否 |
no-empty-pattern | 禁止使用空解构模式 | warn | 否 |
no-eq-null | 禁止在没有类型检查操作符的情况下与 null 进行比较 | off | 否 |
no-eval | 禁用 eval() | error | 否 |
no-extend-native | 禁止扩展原生类型 | error | 否 |
no-extra-bind | 禁止不必要的 .bind() 调用 | warn | 是 |
no-extra-label | 禁用不必要的标签 | error | 是 |
no-fallthrough | 禁止 case 语句落空 | warn | 否 |
no-floating-decimal | 禁止数字字面量中使用前导和末尾小数点 | off | 否 |
no-global-assign | 禁止对原生对象或只读的全局对象进行赋值 | error | 否 |
no-implicit-coercion | 禁止使用短符号进行类型转换 | off | 否 |
no-implicit-globals | 禁止在全局范围内使用变量声明和 function 声明 | off | 否 |
no-implied-eval | 禁止使用类似 eval() 的方法 | error | 否 |
no-invalid-this | 禁止在类或类对象之外使用 this 关键字 | off | 否 |
no-iterator | 禁用 iterator 属性 | error | 否 |
no-labels | 禁用标签语句 | error | 否 |
no-lone-blocks | 禁用不必要的嵌套块 | warn | 否 |
no-loop-func | 禁止在循环语句中出现包含不安全引用的函数声明 | off | 否 |
no-magic-numbers | 禁用魔术数字 | off | 否 |
no-multi-spaces | 禁止使用多个空格 | warn | 是 |
no-multi-str | 禁止使用多行字符串 | off | 否 |
no-new | 禁止使用new | off | 否 |
no-new-func | 禁用Function构造函数 | off | 否 |
no-new-wrappers | 禁止对 String,Number 和 Boolean 使用 new 操作符 | error | 否 |
no-octal | 禁用八进制字面量 | error | 否 |
no-octal-escape | 禁止在字符串中使用八进制转义序列 | error | 否 |
no-param-reassign | 禁止对 function 的参数进行重新赋值 | off | 否 |
no-proto | 禁用 proto 属性 | error | 否 |
no-redeclare | 禁止多次声明同一变量 | error | 否 |
no-restricted-properties | 禁止使用对象的某些属性 | error | 否 |
no-return-assign | 禁止在 return 语句中使用赋值 | off | 否 |
no-return-await | 禁用不必要的 return await | warn | 否 |
no-script-url | 禁止使用 javascript: url | error | 否 |
no-self-assign | 禁止自我赋值 | warn | 否 |
no-self-compare | 禁止自身比较 | warn | 否 |
no-sequences | 禁用逗号操作符 | warn | 否 |
no-throw-literal | 禁止抛出异常字面量 | off | 否 |
no-unmodified-loop-condition | 禁用一成不变的循环条件 | error | 否 |
no-unused-expressions | 强制 | off | 否 |
no-useless-call | 禁止不必要的 .call() 和 .apply() | warn | 否 |
no-useless-catch | 禁止不必要的 catch 子句 | warn | 否 |
no-useless-concat | 禁止不必要的字符串字面量或模板字面量的连接 | warn | 否 |
no-useless-escape | 禁用不必要的转义字符 | error | 否 |
no-useless-return | 禁止多余的 return 语句 | warn | 是 |
no-void | 禁用void操作符 | error否 | |
no-warning-comments | 禁止在注释中使用特定的警告术语 | off | 否 |
no-with | 禁用 with 语句 | off | 否 |
prefer-promise-reject-errors | 要求使用 Error 对象作为 Promise 拒绝的原因 | warn | 否 |
prefer-named-capture-group | 建议在正则表达式中使用命名捕获组 | off | 否 |
radix | 强制在 parseInt() 使用基数参数 | off | 否 |
require-await | 禁止使用不带 await 表达式的 async 函数 | warn | 否 |
vars-on-top | 要求所有的 var 声明出现在它们所在的作用域顶部 | off | 否 |
wrap-iife | 要求 IIFE 使用括号括起来 | warn | 否 |
yoda | 要求或禁止 “Yoda” 条件 | error | 否 |
1.0.0
7 months ago