Reputation: 70
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
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