Rule Suggestion: Prefer Arrow Callback
See original GitHub issueA rule for ES6 to recommend use of arrow functions in callback
Warnings when Arrow function is preferred
func( function () {...} )
setTimeout(function () {...}, 3000);
Not Warnings when Arrow function is preferred
func( () => {...} )
setTimeout( () => {...}, 3000);
Warnings when standard es5 function is preferred
func( () => {...} )
setTimeout( () => {...}, 3000);
Not Warnings when standard es5 function is preferred
func( function () {...} )
setTimeout(function () {...}, 3000);
Rule Example
"prefer-arrow-callback": [2, "always"]
or rule could alternatively look like:
"callback-style": [2, "arrow"]
ref conversation in #3113
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
prefer-arrow-callback - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >eslint-browser/prefer-arrow-callback.md at master - GitHub
This rule is aimed to flag usage of function expressions in an argument list. The following patterns are considered problems: /*eslint prefer-arrow-callback: " ......
Read more >prefer-arrow-callback - ESLint Config
This rule locates function expressions used as callbacks or function arguments. An error will be produced for any that could be replaced by...
Read more >es-lint rule to force arrow functions as callbacks - Reddit
prefer -arrow-callback doesn't seem to do the trick. Interestingly I found this https://github.com/sindresorhus/eslint-plugin-unicorn that ...
Read more >ESLINT: functionseslint(prefer-arrow/prefer-arrow-functions) in ...
Can anyone suggest a solution? I have seen some ideas here: https://eslint.org/docs/rules/prefer-arrow-callback but I am not sure I know how ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think it would be a good idea to add an option to this to only enforce arrow functions for single expressions (i.e., like lambdas in Python).
With that option set, these would be considered warnings:
and these would be okay:
@mysticatea I don’t think so. Let’s hold of on opposite style until somebody requests it.