简体   繁体   中英

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?

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.

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

Use a for..of loop instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM