{"action":"created","issue":{"url":"https://api.github.com/repos/wix/eslint-plugin-lodash3/issues/11","labels_url":"https://api.github.com/repos/wix/eslint-plugin-lodash3/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/wix/eslint-plugin-lodash3/issues/11/comments","events_url":"https://api.github.com/repos/wix/eslint-plugin-lodash3/issues/11/events","html_url":"https://github.com/wix/eslint-plugin-lodash3/issues/11","id":122552806,"number":11,"title":"Suggest to replace indexOf(..., '') === 0 with _.startsWith","user":{"login":"gajus","id":973543,"avatar_url":"https://avatars.githubusercontent.com/u/973543?v=3","gravatar_id":"","url":"https://api.github.com/users/gajus","html_url":"https://github.com/gajus","followers_url":"https://api.github.com/users/gajus/followers","following_url":"https://api.github.com/users/gajus/following{/other_user}","gists_url":"https://api.github.com/users/gajus/gists{/gist_id}","starred_url":"https://api.github.com/users/gajus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gajus/subscriptions","organizations_url":"https://api.github.com/users/gajus/orgs","repos_url":"https://api.github.com/users/gajus/repos","events_url":"https://api.github.com/users/gajus/events{/privacy}","received_events_url":"https://api.github.com/users/gajus/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/wix/eslint-plugin-lodash3/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/wix/eslint-plugin-lodash3/labels/help%20wanted","name":"help wanted","color":"159818"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-12-16T16:57:24Z","updated_at":"2015-12-18T10:49:37Z","closed_at":null,"body":"```js\r\n_.indexOf(action.type, '@@') === 0\r\n```\r\n\r\ncan be replaced with `_.startsWith(action.type, '@@')`.\r\n\r\nDetecting `_.endsWith` is more tricky given that there are quite a few ways to do it, http://stackoverflow.com/questions/280634/endswith-in-javascript."},"comment":{"url":"https://api.github.com/repos/wix/eslint-plugin-lodash3/issues/comments/165745824","html_url":"https://github.com/wix/eslint-plugin-lodash3/issues/11#issuecomment-165745824","issue_url":"https://api.github.com/repos/wix/eslint-plugin-lodash3/issues/11","id":165745824,"user":{"login":"ganimomer","id":8225721,"avatar_url":"https://avatars.githubusercontent.com/u/8225721?v=3","gravatar_id":"","url":"https://api.github.com/users/ganimomer","html_url":"https://github.com/ganimomer","followers_url":"https://api.github.com/users/ganimomer/followers","following_url":"https://api.github.com/users/ganimomer/following{/other_user}","gists_url":"https://api.github.com/users/ganimomer/gists{/gist_id}","starred_url":"https://api.github.com/users/ganimomer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ganimomer/subscriptions","organizations_url":"https://api.github.com/users/ganimomer/orgs","repos_url":"https://api.github.com/users/ganimomer/repos","events_url":"https://api.github.com/users/ganimomer/events{/privacy}","received_events_url":"https://api.github.com/users/ganimomer/received_events","type":"User","site_admin":false},"created_at":"2015-12-18T10:49:37Z","updated_at":"2015-12-18T10:49:37Z","body":"So, I've done some tests and read the docs, and learned some interesting things about this rule:\r\n[`_.indexOf()` only works for arrays](https://lodash.com/docs#indexOf).\r\nAnd upon a test of my own, `_.indexOf('abcd', 'bc')` returns `-1`.\r\n(This also means there's a probable bug in `prefer-lodash-method`, since the two methods aren't interchangeable.)\r\n\r\nI had worries about not being able to tell if the first argument is a string or an array, but it looks like, counterintuitively, `_.startsWith()` also works for arrays!\r\nTry it yourself, and you'll see that `_.startsWith([1,2,3], 1)` returns `true`, and `_.startsWith([1,2,3], 2)` returns false.\r\nThis means this rule works, but not for the reason that we thought.\r\nAs for `[String|Array].prototype.indexOf()`, our belief is that every rule in the plugin (and in ESLint) should be atomic, and not rely on other rules being activated.\r\nWe also want to separate the users of the rules to two categories: rules that suggest the use of Lodash instead of native (e.g `prefer-lodash-typecheck`), and rules that enforce proper use of Lodash (e.g. `no-single-chain`).\r\nFor these reasons, I think the rule should have an *option* whether or not to report these cases, with the values `\"lodash\"` or `\"all\"`, with \"all\" by default."}}