prefer-arrow-callback
eslint
Safe autofix
eslint.config.js
export default [
{
rules: {
"prefer-arrow-callback": "error",
},
},
];foo(function(a) { return a; }); // ERROR
// prefer: foo(a => a)
foo(function() { return this.a; }.bind(this)); // ERROR
// prefer: foo(() => this.a)foo(function bar(a: string) { a; });
test('foo', function (this: any) {});// arrow function callback
foo(a => a); // OK
// generator as callback
foo(function*() { yield; }); // OK
// function expression not used as callback or function argument
const foo = function foo(a) { return a; }; // OK
// unbound function expression callback
foo(function() { return this.a; }); // OK
// recursive named function callback
foo(function bar(n) { return n && n + bar(n - 1); }); // OKfoo((a: string) => a);
const foo = function foo(bar: any) {};Examples from the ESLint documentation.
prefer-arrow-callback
eslint
export default [
{
rules: {
"prefer-arrow-callback": "error",
},
},
];prefer-arrow-callback
eslint plugin · style
{
"rules": {
"prefer-arrow-callback": "error"
}
}complexity/useArrowFunction
complexity · since 1.0.0
{
"linter": {
"rules": {
"complexity": {
"useArrowFunction": "error"
}
}
}
}Disallow unnecessary constructors
Enforce the use of the radix argument when using parseInt()
Disallow the use of variables before they are defined
Disallow ternary operators when simpler alternatives exist
Disallow use of the RegExp constructor in favor of regular expression literals