[英]Expected to return a value in arrow function. (xo code style)
My CLI Node.js project is using the XO Code Style and i've got a problem with 1 error. 我的CLI Node.js项目正在使用XO代码样式 ,但出现1个错误的问题。 Here is the output when i run "xo" command:
这是我运行“ xo”命令时的输出:
× 31:15 Expected to return a value in arrow function.
Here is the code : 这是代码:
to.map(item => {
if (currencies[item]) {
loading.succeed(`${chalk.green(money.convert(amount, {from, to: item}).toFixed(2))} ${`(${item})`} ${currencies[item]}`);
} else {
loading.warn(`${chalk.yellow(` The ${item} currency not found `)}`);
}
});
If you want, you can also view the full file HERE . 如果需要,还可以在此处查看完整文件。
I was searching for a eslint rule, but i couldn't find one :( What should i do to ignore/fix this error? 我正在寻找一种拖延规则,但我找不到一个:(我应该怎么做才能忽略/修复此错误?
XO Code Style is pointing out that your map
callback never returns a value, but map
expects the callback to do so. XO代码样式指出,您的
map
回调永远不会返回值,但map
希望回调能够这样做。
What should i do to ignore/fix this error?
我应该怎么做才能忽略/修复此错误?
Use the right tool for the job. 使用正确的工具完成工作。 If you're not mapping the entries into a new array, don't use
map
; 如果您没有将条目映射到新数组中,请不要使用
map
; use forEach
(or any of the many other ways to loop through an array ). 使用
forEach
(或通过数组循环的许多其他方式中的任何一种 )。 The purpose of map
is to create a new array with entries that are a transformation of some kind of the original array's entries. map
的目的是创建带有条目的新数组,这些条目是对原始数组条目的某种转换。
You forgot to return a value in the .map
's arrow function, which is not intended unless you want an array of undefined
s. 您忘了在
.map
的arrow函数中返回一个值,除非想要一个undefined
数组,否则不要使用该值。
Use a for..of
loop instead. 请使用
for..of
循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.