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

Rule proposal: no-magic-array-flat-depth #1920

Closed
fisker opened this issue Sep 30, 2022 · 3 comments · Fixed by #2335
Closed

Rule proposal: no-magic-array-flat-depth #1920

fisker opened this issue Sep 30, 2022 · 3 comments · Fixed by #2335
Assignees
Labels

Comments

@fisker
Copy link
Collaborator

fisker commented Sep 30, 2022

Description

A special case of no-magic-numbers rule.

When calling Array#flat(depth) with depth. Normally the depth should be 1/Number.POSITIVE_INFINITY. Otherwise it should be reported, but I don't want this rule to get annoying, so

  • If it's not a number literal, we assume user know the max depth.
  • If there is a comment before the number, we assume the number is explained.

Fail

array.flat(2);
array.flat(99);

Pass

array.flat();
array.flat(Number.POSITIVE_INFINITY);
array.flat(depth);
array.flat(/* The depth is always 2 */ 2);

Additional Info

This rule should only be useful for users don't want to enable no-magic-numbers, otherwise the failed cases shold already covered.

@sindresorhus
Copy link
Owner

Are there other APIs with a depth parameter? Otherwise, I would name it more explicitly: no-magic-array-flat-depth.

@fisker fisker changed the title Rule proposal: no-magic-depth Rule proposal: no-magic-array-flat-depth Sep 30, 2022
@fisker
Copy link
Collaborator Author

fisker commented Sep 30, 2022

Can't think another one.

@fisker
Copy link
Collaborator Author

fisker commented May 7, 2024

Accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants