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

feat: ban new Array #209

Merged
merged 1 commit into from Jul 4, 2023
Merged

feat: ban new Array #209

merged 1 commit into from Jul 4, 2023

Conversation

zanminkian
Copy link
Contributor

Description

The parameter of Array constructor is the design mistake which is ambiguous and hard to use. Banning this will be convenient for code review. Because some time I will forget:

new Array(5) // An array with 5 items? Or one item in an array?

Linked Issues

Additional context

@zanminkian
Copy link
Contributor Author

@zanminkian
Copy link
Contributor Author

We have enable no-new-wrappers to ban new Number and new String etc. So it reasonable to ban new Array too.

@antfu
Copy link
Owner

antfu commented Jul 3, 2023

I never used new Array and did even know it worked - I am ok having it, but I am also ok with not having it because it makes no difference at all. This leads me thinking what's the performance cost of checking a syntax that no one uses?

@zanminkian
Copy link
Contributor Author

I don't know how much time it would take to add one rules. But eslint is quite slow. For performance, eslint is not a good solution, but Rome is.

Although you don't use new Array, other developer may use it and submit a PR to your project. 😆

Maybe we should re-think what's the case this preset use for. For linting on pre-commit git hooks only? What about linting on CI/CD? I hope this preset is all-inclusive to kill the shit code.

@zanminkian
Copy link
Contributor Author

I believe no body use with statement in js, but this preset ban it. From my humble opinion, we should accept all the reasonable rule and ignore the performance reason.

@antfu antfu merged commit be5bc80 into antfu:main Jul 4, 2023
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.

None yet

2 participants