no-unnecessary-mapfilter
See original GitHub issuePlease describe what the rule should do: reports on unnecessary use of .filter and .map on arrays. could be split into 2 rules, one for unnecessary use of .filter and one for unnecessary use of .map
What category of rule is this? (place an “X” next to just one item)
[x] Warns about a potential error (problem) [ ] Suggests an alternate way of doing something (suggestion) [ ] Enforces code style (layout) [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
const myArr = [1,2,3];
myArr.filter(x => true) // filter isn't filtering any items
const myArr = [];
myArr.filter(x => 1) // filter isn't filtering any items
const myArr = [];
myArr.map(x => x) // map isn't mapping to something new, unless a shallow copy is the goal which in case one should go for .slice(0)
Why should this rule be included in ESLint (instead of a plugin)? it’s simple enough to be a part of eslint, maybe too simple to be a part of eslint? ❓
Are you willing to submit a pull request to implement this rule? yes
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:14 (12 by maintainers)
Top Results From Across the Web
How to Use Map, Filter, and Reduce in JavaScript - Code
A Map From List to List; Filter Out the Noise; The Reduce Method ... it sounds like: It takes an array and filters...
Read more >Simplify your JavaScript – Use .map(), .reduce(), and .filter()
Simplify the way you write your JavaScript by using .map(), .reduce() and .filter() instead of for() and forEach() loops.
Read more >Mapping, Filtering, and Reducing Things in an Array - KIRUPA
That's why map, filter, and reduce were introduced. You get all the flexibility of using a for loop without the unwanted side effects...
Read more >map(), filter() and reduce() in JavaScript. - codeburst
map () executes the provided callback at each element of an array and returns the new value to the resultant array. When thisValue...
Read more >How to filter and map array such that false values of visible are ...
You need to first filter the overall array before splitting the remaining objects into pieces: const massaged = data .filter(item ...
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
Proposal at https://github.com/eslint/eslint/issues/12980.
Yes. I will after checking if there if there are any more methods that could benefit, not strictly limited to Array.