Rule proposal: No `this` argument in array methods when using arrow functions
See original GitHub issuePrevent specifying the this
argument to array methods when using an arrow function, since it has no effect.
Applies to the following instance methods:
map
filter
some
find
forEach
findIndex
every
And also Array.from
.
Only Array.from
can be safely auto-fixed. The others should use suggestions.
Fail
array.filter(x => x === 1, this);
Pass
array.filter(x => x === 1);
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:16 (9 by maintainers)
Top Results From Across the Web
Arrow function expressions - JavaScript - MDN Web Docs
An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate ...
Read more >Javascript Arrays And Arrow Functions - w Blog
Since Arrow functions lack of the prototype property, they cannot be used as constructors. Depending on how functions have been declared, they ...
Read more >3 Scenarios Where You Shouldn't Use Arrow Functions | by Tom
Here are 3 scenarios where arrow functions should not be used. ... Since the arrow function has a short syntax, it's inviting to...
Read more >Arrow Functions · Styleguide JavaScript
If the function body consists of a single statement returning an expression without side effects, omit the braces and use the implicit return....
Read more >Why shouldn't JSX props use arrow functions or bind?
Using an inline arrow function will cause PureComponent s, and components that use shallowCompare in the shouldComponentUpdate method to rerender anyway. Since ...
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
A more generic solution, enfore array method arguments length, takes a number or range.
This rule may not only work for array, we can also make it work for any method.
For example:
How about
no-array-method-this-argument
?