-
-
Notifications
You must be signed in to change notification settings - Fork 384
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: prefer-split-limit
#2464
Comments
Could also be: string.split('/', numberVar).at(numberVar) |
Yeah Just a small correction in case anyone starts implementing the rule -- since the second parameter is the length of the returned array instead of the number of splits to do: string.split('/').at(numberVar)
// would be:
string.split('/', numberVar + 1).at(numberVar) |
The rule could potentially also warn for that: s.split('/', 1).at(2);
// Error: This will always be undefined |
prefer-split-limit
Accepted |
Don't think it's safe, since |
Description
Whenever we use
String.prototype.split
with literals like so:We benefit by limiting the search space, this allows split to exit early once it attains the number of splits and to not scan the whole string:
Fail
Pass
Proposed rule name
specify-split-limit or prefer-split-limit
Additional Info
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split#limit
The text was updated successfully, but these errors were encountered: