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

Add prefer-array-flat rule #1126

Merged
merged 16 commits into from
Feb 24, 2021
Merged

Conversation

fisker
Copy link
Collaborator

@fisker fisker commented Feb 22, 2021

Fixes #975

@fisker fisker marked this pull request as ready for review February 22, 2021 17:07
@fisker
Copy link
Collaborator Author

fisker commented Feb 22, 2021

Half code in this rule just esquery selector. 😄

@@ -0,0 +1,53 @@
# Prefer `Array#flat()` over legacy techniques to flatten arrays

ES2019 introduced a new method [`Array#flat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) that flattens arrays, and there's a [`depth` parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat#parameters), so you can flatten deep nesting arrays with it.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the depth parameter is relevant. People can read about it when they click the MDN link.

index.js Outdated
@@ -84,6 +84,9 @@ module.exports = {
'unicorn/prefer-add-event-listener': 'error',
'unicorn/prefer-array-find': 'error',
// TODO: Enable this by default when targeting Node.js 12.
// TODO[@fisker]: Set to `off` before merge
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget this.

@fisker
Copy link
Collaborator Author

fisker commented Feb 23, 2021

Added a functions option, I think it can be useful 43e5380

@fisker
Copy link
Collaborator Author

fisker commented Feb 23, 2021

CI failure should not related, I'll look into it.

@sindresorhus sindresorhus merged commit 2397d94 into sindresorhus:main Feb 24, 2021
@fisker fisker deleted the prefer-array-flat branch February 24, 2021 06:48
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

Successfully merging this pull request may close these issues.

Rule proposal: prefer-array-flat
2 participants