Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[no-assign-mutated-array] doesn't account for flatMap #69

Open
Samuel-Therrien-Beslogic opened this issue Mar 21, 2024 · 0 comments
Open

Comments

@Samuel-Therrien-Beslogic

The rule will accept sorting a mapped array, but not a flatMapped one.
I suppose the rule checks for known function names, flatMap is common enough is should probably be excluded.

OK (but unicorn/prefer-array-flat-map)

const biggestQuantity = entityFilters
  .map(category => category.items.map(item => item.quantity))
  .flat(1)
  .sort((quantity1, quantity2) => quantity2 - quantity1)

OK (invalid code, just for linting demonstration purposes)

const biggestQuantity = entityFilters
  .map(category => category.items.map(item => item.quantity))
  .sort((quantity1, quantity2) => quantity2[0] - quantity1[0])

Fails no-assign-mutated-array

const biggestQuantity = entityFilters
  .flatMap(category => category.items.map(item => item.quantity))
  .sort((quantity1, quantity2) => quantity2 - quantity1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant