eslintrc.js中各规则对应的解释

各规则的开关

"off" or 0 - 关闭规则
"warn" or 1 - 将规则视为一个警告
"error" or 2 - 将规则视为一个错误

rules中的各规则

  • semi
    • 是否使用分号
  • radix
    • 使用parseInt()函数时是否要填写基数
    • 基数即括号中的第二个参数
      • var num = parseInt("071"); // 57
      • var num = parseInt("071", 10); // 71
  • no-param-reassign
    • 是否能对函数参数中的变量进行赋值
    • props: true or false
    • 若设置{ "props": false },则能使用下列写法
/*eslint no-param-reassign: ["error", { "props": false }]*/

function foo(bar) {
    bar.prop = "value";
}

function foo(bar) {
    delete bar.aaa;
}

function foo(bar) {
    bar.aaa++;
}
  • no-unused-vars
    • 是否禁止未使用过的变量存在
    • var
      • all: 检测所有变量,包括全局环境中的变量,这是默认值
      • local: 仅仅检测本作用域中声明的变量是否使用,允许不使用全局环境中的变量
    • args
      • after-used : 最后一个参数必须使用
      • all: 所有命名参数必须使用
      • none: 不检查参数
  • no-underscore-dangle
    • 是否允许以下划线开头命名变量
  • no-mixed-operators
    • 是否禁止混合使用不同的操作符
    • allowSamePrecedence: 是否指定允许使用混合的两个操作符,前提是它们有同样的优先级
      • true: var foo = a + b - c 可以使用
      • false: var foo = a + b - c 不可以使用
  • consistent-return
    • 是否要求使用一致的 return 语句
    • treatUndefinedAsUnspecified:
      • false: (默认) 总是指定返回值或隐式返回 undefined
      • true: 总是指定返回值或返回 undefined 无论是隐式或显式。
  • max-len
    • 是否指定一行中的最大长度
    • { 1, 120, 4 }代表{ warn, 最大长度, 下一行与上一行的tab间隔 }
    • ignoreComments: true 忽略所有拖尾注释和行内注释
    • ignoreTemplateLiterals: true 忽略包含模板字面量的行
  • indent
    • 是否强制使用一致的缩进
    • 默认为4
  • comma-dangle
    • 是否要求或禁止使用拖尾逗号
    • never: (默认) 禁用拖尾逗号
  • no-unused-expressions
    • 是否禁止未使用过的表达式
    • allowShortCircuit: 是否允许你在表达式中使用逻辑短路求值
      • 如 a() || (b = c)
    • allowTernary: 是否允许你在表达式中使用类似逻辑短路求值的三元运算符
      • 如 a ? (b = c) : d()
  • no-use-before-define
    • 是否禁止定义前使用
    • functions: 是否要检测函数的声明
  • no-plusplus
    • 是否禁止使用一元操作符 ++ 和 - -
      • 因为一元操作符 ++ 和 - - 会自动添加分号,不同的空白可能会改变源代码的语义
var i = 10;
var j = 20;

i ++
j
// i = 11, j = 20
* allowForLoopAfterthoughts: true 允许在 for 循环的最后一个表达式中使用 ++ 和 - - 
  • class-methods-use-this
    • 是否校验class中使用过this
    • 若无使用,则可以转换成static函数
  • camelcase
    • 是否要求对变量使用驼峰命名法
  • no-nested-ternary
    • 是否禁止使用嵌套的三元表达式
  • import/prefer-default-export
    • 当模块只输出一个变量时,是否需要添加default
  • eact/jsx-filename-extension
    • 是否检测jsx文件的结尾
  • react/prefer-stateless-function
    • 是否检测stateless-function类型的react文件使用正确
    • ignorePureComponents: true 忽略React.PureComponent
  • react/no-did-update-set-state
    • 是否允许在componentDidUpdate中使用setState
  • react/jsx-indent
    • 是否检测jsx的缩进
  • react/prop-types
    • 是否检测react文件有无属性验证
  • react/sort-comp
    • 是否检测组件中的function书写顺序
  • jsx-a11y/no-static-element-interactions
    • 是否强制验证空元素使用属性
  • jsx-a11y/anchor-has-content
    • 是否强制验证锚点处有内容

你可能感兴趣的:(eslintrc.js中各规则对应的解释)