ESlint报错解决方案

Unary operator ‘++’ used

ESLint 不允许++ 运算比如

1
2
3
4
5
6
7
8
9
10
11
for (let i = 0; i < 3; i ++) {
// ...
}
for (let i = 0; i < 3; i += 1) {
// ...
}

temp++

var temp = 0;
temp += 1;

Missing radix parameter 缺少基数参数

ESLint parseInt()方法必须传入第二参数radix

1
2
3
4
parseInt(string, radix)
parseInt('123', 0)
radix 取值范围2~36代表数字基数
不传或传0代表10进制

–传入0可解决
parseInt(‘123’, 0)

Unexpected string concatenation 意外的字符串连接

不允许字符串拼接

1
'0' + month ======》`0${month}`;

Expected to return a value in arrow function 箭头函数期望有返回值

使用map时Eslint希望有返回值

1
2
3
columns.map(item => {
item.name='xx'
});

1:用Object.keys(this.props.ntn).forEach去替换.map,因为ESLint array-callback-return这个警告是因为在使用map, filter , reduce 没有去返回一个值。

2:当然也可以使用map,在react中用jsx的方式,直接把{}改成()即可。

扩展
map:和forEach非常相似,都是用来遍历数组中的每一项值的,用来遍历数组中的每一项;
区别:map的回调函数中支持return返回值;return的是啥,相当于把数组中的这一项变为啥(并不影响原来的数组,只是相当于把原数组克隆一份,把克隆的这一份的数组中的对应项改变了);
不管是forEach还是map 都支持第二个参数值,第二个参数的意思是把匿名回调函数中的this进行修改。

JSX props should not use .bind() JSX语法中不能使用.bind()

ERROR

1
<form onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}>

SUCCESS
Option 1:
Use arrow functions (with babel-plugins) PS:- Experimental feature

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class MyComponent extends Component {
handleClick = (args) => () => {
// access args here;
// handle the click event
}

render() {
return (
<div onClick={this.handleClick(args)}>
.....
</div>
)
}
}

Option 2: Not recommended

Define arrow functions in render

1
2
3
4
5
6
7
8
9
10
11
12
class MyComponent extends Component {
render() {
const handleClick = () => {
// handle the click event
}
return (
<div onClick={handleClick}>
.....
</div>
)
}
}

Option 3:

Use binding in constructor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class MyComponent extends Component {
constructor() {
super();
this.handleClick = this.handleClick.bind(this);
}

handleClick() {
// handle click
}

render() {

return (
<div onClick={this.handleClick}>
.....
</div>
)
}
}

You forgot to set the qrcode for Alipay. Please set it in _config.yml.
You forgot to set the qrcode for Wechat. Please set it in _config.yml.
You forgot to set the business and currency_code for Paypal. Please set it in _config.yml.
You forgot to set the url Patreon. Please set it in _config.yml.
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×