question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-unnecessary-mapfilter

See original GitHub issue

Please 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
silverwindcommented, Feb 28, 2020
1reaction
silverwindcommented, Oct 16, 2019

Yes. I will after checking if there if there are any more methods that could benefit, not strictly limited to Array.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found