Saeed Heidarizarei
Saeed Heidarizarei

Reputation: 8916

mongoose Get Unexpected function expression

Why my Code Get: [eslint] Unexpected function expression. (prefer-arrow-callback) ?

Code:

 kitty.save(function (err) {
    if (err) {
      console.log('a');
    }
  });

What is wrong?

Upvotes: 3

Views: 150

Answers (1)

Zlatko
Zlatko

Reputation: 19569

You have eslint configured to take arrow functions when they're inline like that. Try this:

kitty.save((err) => {
  if (err) {
    console.log('a')
  }
});

Alternatively, you can disable this eslint rule, whether inline or in your eslintrc file. E.g.

// eslint-disable prefer-arrow-callback
kitty.save(function (err) {
  if (err) {
    console.log('a');
  }
});

You can read a bit more about arrow functions here. And about eslint rules here.

Upvotes: 1

Related Questions