V
V
Vinyard Rip2017-10-26 23:37:51
Linter
Vinyard Rip, 2017-10-26 23:37:51

What is eslint complaining about?

59f246361e3ba697376742.jpeg
"extends": [
"airbnb-base",
"prettier"
]
what's wrong with the arrow function? tried various varis guided by this https://github.com/leonidlebedev/javascript-airbnb - can't figure it out

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Leonid, 2017-10-31
@vinyardrip

Hey!
arrow-body-style - a rule that describes how the function body of arrow functions should look like. It can contain a familiar block in curly braces () => {...}, or it can contain an expression that is implicitly returned from a function () => ....
In the Airbnb guide , the following parameters are set :

'arrow-body-style': ['error', 'as-needed', {
  requireReturnForObjectLiteral: false,
}],

This means that you must replace the function body with curly braces with an expression. A few examples from the official eslint documentation:
// неправильно
let foo = () => {
    return 0;
};
// правильно
let foo = () => 0;

// неправильно
let foo = () => {
    return {
       bar: {
            foo: 1,
            bar: 2,
        }
    };
};
// правильно
let foo = () => ({
    bar: {
        foo: 1,
        bar: 2,
    }
});

// здесь фигурные скобки необходимы
let foo = (retv, name) => {
    retv[name] = true;
    return retv;
};

If we talk about your code, then you need to omit the curly braces and return the object implicitly.
notify.onError(err => ({
  title: 'Build Html task',
  message: err.message,
})

Rule on eslint: https://eslint.org/docs/rules/arrow-body-style
Airbnb configuration options: https://github.com/airbnb/javascript/blob/7ff63035...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question