【发布时间】:2017-10-13 04:16:56
【问题描述】:
我收到 ESLint 警告:
期望在箭头函数的末尾返回一个值(一致返回)
errors.details.forEach((error) => {
const errorExists = find(errObj, (item) => { // <== ESLint warning
if (item && item.field === error.path && item.location === location) {
item.messages.push(error.message);
item.types.push(error.type);
return item;
}
});
if (!errorExists) {
errObj.push({
field: error.path,
location: error.location,
messages: [error.message],
types: [error.type]
});
}
});
但是如果我插入一个返回
const errorExists = find(errObj, (item) => { // <== ESLint warning
if (item && item.field === error.path && item.location === location) {
item.messages.push(error.message);
item.types.push(error.type);
return item;
}
return; // <== inserted return
});
然后这一行不再有警告,但是我在插入的 return 上收到 2 个警告...
箭头函数期望返回值(一致返回) 不必要的返回语句(no-useless-return) 我不知道如何正确解决这个问题.. 欢迎任何反馈
【问题讨论】:
-
find回调应该总是返回一个布尔值。item和undefined都不是。
标签: ecmascript-6 eslint