eslint 的规则都是自己定义的,需要什么样的规则就添加定义什么样的规则。动手前应该先看看项目中已经定义了那些规则,规则是怎么样的。
-
'Icon' is defined but never used no-unused-vars
定义了但是没有使用(可以看看那些暗色的,就是定义了但没有使用的,删除即可)
-
Expected indentation of 10 space characters but found 12 react/jsx-indent-props
空格问题。后面的 12 可能为任一数字,只要把空格数变成前一个数字即可。(该例子需要把 12 个空格改成 10 个空格)
-
Missing space before value for key 'color' key-spacing
定义对象的时候,key 后面跟的冒号(:),冒号后面要有空格将 value 的值隔开。
-
Parentheses around JSX should be on separate lines react/jsx-wrap-multilines
我把整个放在一行解决了这个问题。例如
return (<div><p>Hello</p></div>);了解更多 -
Expected closing tag to match indentation of opening react/jsx-closing-tag-location
我把整个放在一行解决了这个问题。(同上,查看更多,将能很好的理解这个问题,以及解决方法) 了解更多
-
Missing semicolon semi
缺少了分号。语句结束后需要添加分号(;)
-
Unnecessary 'else' after 'return' no-else-return
else 前面禁止有return 语句。需要调整 if-else 结构,尽管你的代码逻辑可能没有问题。参考规范
-
A space is required before closing bracket react/jsx-tag-spacing
闭合标签
/>前面需要有个空格。比如:<Hello />而不能是<Hello/>。更多参考 -
A space is required after ',' bracket comma-spacing
或者
A space is required before '}' object-curly-spacing逗号(,)后面需要添加一个空格 更多参考(这个是可以设置是在逗号需要加空格还是在逗号后)
或}前需要添加一个空格。 -
'eventStyle' is never reassigned. Use 'const' instead prefer-const
建议使用
const。(因为本例中的eventStyle没有再在任何地方被修改) -
Operator ':' must be spaced space-infix-ops
在符号(infix operators) 前后留有间距/空格更易阅读。比如
a?b:c应该改成a ? b : c。示例中需要在冒号(:)前后有间距/空格。 -
Expected blank line between class members lines-between-class-members
class的成员之间需要有一行空格隔开,对于块更容易理解。了解更多 -
Expected property shorthand object-shorthand
es6中的语法。用于定义对象文字方法和属性的简明形式,此语法可以使定义复杂的对象文字更加清晰。例如:
// properties var foo = { x: x, y: y, z: z, }; // methods var foo = { a: function() {}, b: function() {} };es6 等价与如下:
/*eslint-env es6*/ // properties var foo = {x, y, z}; // methods var foo = { a() {}, b() {} }; -
Trailing spaces not allowed
存在多余空格…… -
Unexpected tab character 使用了制表符
-
Unnecessary use of conditional expression for default assignment no-unneeded-ternary 禁止可以表达为更简单结构的三元操作符 (no-unneeded-ternary) 具体可参考: eslint.cn/docs/rules/…