Skip to content

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

@fisker

Description

@fisker

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.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions