0

My CLI Node.js project is using the XO Code Style and i've got a problem with 1 error. Here is the output when i run "xo" command:

×  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?

2 Answers2

3

XO Code Style is pointing out that your map callback never returns a value, but map expects the callback to do so.

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; use forEach (or any of the many other ways to loop through an array). 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.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
0

You forgot to return a value in the .map's arrow function, which is not intended unless you want an array of undefineds.

Use a for..of loop instead.

lilezek
  • 6,976
  • 1
  • 27
  • 45