javascript - ESLint prefer-arrow-callback error -


i've got problem eslint

here function:

$productitem.filter(function (i, el) {         return el.getboundingclientrect().top < evt.clienty     }).last()     .after($productitemfull) 

and here eslint tell me:

warning  missing function expression name  func-names error    unexpected function expression    prefer-arrow-callback 

how solve error?

it saying use arrow function syntax in filter callback function.

$productitem.filter((i, el) => el.getboundingclientrect().top < evt.clienty)     //              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^     .last()     .after($productitemfull); 

here's eslint documentation prefer-arrow-callback says

arrow functions suited callbacks, because:

  • this keywords in arrow functions bind upper scope’s.

  • the notation of arrow function shorter function expression’s.

and, in following cases error thrown

/*eslint prefer-arrow-callback: "error"*/  foo(function(a) { return a; }); foo(function() { return this.a; }.bind(this)); 

your code same same first snippet. so, error prefer-arrow-callback shown eslint.

to solve error, can

  1. use arrow function syntax(as shown above)
  2. suppress error using options , named function

    /*eslint prefer-arrow-callback: ["error", { "allownamedfunctions": true }]*/  foo(function bar() {}); 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -