Antoni Kępiński
Antoni Kępiński

Reputation: 446

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

Upvotes: 0

Views: 1041

Answers (2)

T.J. Crowder
T.J. Crowder

Reputation: 1074445

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.

Upvotes: 3

lilezek
lilezek

Reputation: 7344

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.

Upvotes: 0

Related Questions