1、Unexpected space before function parentheses
问题:函数参数前不希望有空格
解决:.eslintrc文件中,加入配置
rules: {
'space-before-function-paren': ['error', {
anonymous: 'always',
named: 'always',
asyncArrow:'always'
}],
},
2、Unary operator ‘++‘ used
解决:将i++替换为i+=1
3、The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype。
问题:避免for-in遍历原型属性
解决:加if判断
let val = { numArr: [1, 2, 3] };
for (let item in val) {
if (val.hasOwnProperty(item)) {
console.log(item);
}
}
4、for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.
问题:避免for-in遍历原型链
解决:使用Object.{keys,values,entries}
5、Trailing spaces not allowed
解决:删除标签后的空格