Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 733
Saeed Heidarizarei Avatar asked May 13 '26 07:05

Saeed Heidarizarei


1 Answers

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.

like image 120
Zlatko Avatar answered May 14 '26 21:05

Zlatko