An arrow function expression is a compact alternative to anonymous function.
(c) MDN
Install
npm i @putout/plugin-convert-to-arrow-function
Rule
{
"rules": {
"convert-to-arrow-function": "on"
}
}
❌ Example of incorrect code
module.exports = function(a, b) {};
function x() {
return function(a) {
return b;
};
}
call(function() {
return 'world';
});
✅ Example of correct code
module.exports = (a, b) => {};
function x() {
return (a) => {
return b;
};
}
call(() => {
return 'world';
});
Comparison
Linter | Rule | Fix |
---|---|---|
convert-to-arrow-function |
||
⏣ ESLint | prefer-arrow-callback |
License
MIT