预期 return 箭头函数中的值。 (xo代码风格)

Expected to return a value in arrow function. (xo code style)

我的 CLI Node.js 项目正在使用 XO Code Style,我遇到了 1 个错误的问题。这是我 运行 "xo" 命令时的输出:

×  31:15  Expected to return a value in arrow function. 

这是代码:

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 `)}`);
        }
    });

如果需要,您还可以查看完整文件HERE

我正在搜索 eslint 规则,但我找不到 :( 我应该如何处理 ignore/fix 这个错误?

您忘记 return .map 的箭头函数中的一个值,除非您想要一个 undefined 的数组,否则这不是预期的。

改用 for..of 循环。

XO 代码风格指出您的 map 回调从来没有 returns 值,但 map 期望回调这样做。

What should i do to ignore/fix this error?

使用正确的工具来完成工作。如果您不 将条目映射 到新数组中,请不要使用 map; use forEach (or any of the many other ways to loop through an array)。 map 的目的是创建一个新数组,其中的条目是某种原始数组条目的转换。