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

Improve no-new-array #1534

Closed
fisker opened this issue Sep 28, 2021 · 1 comment · Fixed by #1648
Closed

Improve no-new-array #1534

fisker opened this issue Sep 28, 2021 · 1 comment · Fixed by #1648

Comments

@fisker
Copy link
Collaborator

fisker commented Sep 28, 2021

Currently, when we know the argument is a number, we can auto fix the problem.

But only work for simple cases, we should also smart enough to know cases like new Array(Math.min(unkown1, unknown2)) is calling with a number.

The following are numbers:

  • all Math method calls, and Math properties
  • Number(unkown)
  • Number.parseInt / Number.parseFloat (global parseInt already checked by unicorn/prefer-number-properties)
  • BinaryExpressions (-, * , /, %), but NOT + operator, it could be string
  • AssignmentOperators (-=, *=, /=, %=)
  • unknown ++, unknown --, ++ unknown, -- unknown
  • UnaryOperators (+unknown, -unknown, ~unknown)
  • Bitwise operators
  • Else ?

This will also make other rules like no-new-buffer auto-fix more cases.

@sindresorhus
Copy link
Owner

This is now accepted.

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

Successfully merging a pull request may close this issue.

2 participants