T.Koomen
T.Koomen

Reputation: 70

Eslint: remove keyword function

I was wondering if there is a rule or a way to flag function declarations as an error in favor of arrow functions. As an example:

// error
 function foo() {
   return "bar"
 }

//acceptable
 const foo = () => "bar"

its pretty simple, but I haven't been able to find any rules or packages.

Upvotes: 1

Views: 659

Answers (1)

Michał Perłakowski
Michał Perłakowski

Reputation: 92521

There's a prefer-arrow-callback rule, but it applies only to callbacks. If you want to disallow regular functions entirely, you can use the eslint-plugin-prefer-arrow npm package.

Remember though that sometimes you might need a regular function, for example as a callback to addEventListener.

Upvotes: 2

Related Questions