-
Notifications
You must be signed in to change notification settings - Fork 65
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
Suggest to replace indexOf(..., '') === 0 with _.startsWith #11
Comments
Sounds good. Anyone's free to submit a PR, or we'll get to it eventually. |
How about usages of |
Sorry, the issue is nonsensical: It should have been detect _.indexOf in this situation, not indexOf string prototype. Simply because lodash prefer rule will ask to use the latter form anyway.
|
Ah, ok, thanks for the clarification! Somehow I missed this. |
So, I've done some tests and read the docs, and learned some interesting things about this rule: I had worries about not being able to tell if the first argument is a string or an array, but it looks like, counterintuitively, |
I don't see where it says in the docs that the rule only works with arrays. Are you referring to the signature of the function?
In this sense, Array and String are interchangeable. It is an error in the docs. It should say To prove that string is simply an object that implements iterable interaface: for (i of 'test') {
console.log('i', i);
}
> i t
> i e
> i s
> i t |
I have opened an issue with LoDash regarding the signature of the |
I agree that _.indexOf('abcd', 'bc') It would return -1. |
Using |
Since usage of _.indexOf() with strings as the |
Implemented the rule in v0.4.1 |
can be replaced with
_.startsWith(action.type, '@@')
.Detecting
_.endsWith
is more tricky given that there are quite a few ways to do it, http://stackoverflow.com/questions/280634/endswith-in-javascript.The text was updated successfully, but these errors were encountered: