Open NovemLinguae opened 7 months ago
We can use the already present unicorn plugin for startsWith:
Alternatively the rules could be applied to ES2016 rules only, where Array.indexOf can also be replaced by Array.includes, and so the type wouldn't matter
543 hits in CodeSearch for !== -1, and 200 for === 0. Lots of good potential autofixing here.
edit: Actually, some of those may be Array.indexOf()
.
String.startsWith()
andString.includes()
were introduced in ES6 and are great. Very readable.String.indexOf(a) !== -1
, suggestString.includes()
insteadString.indexOf(a) === 0
, suggestString.startsWith()
insteadSource code from another eslint plugin with these rules here and here (MIT license)
edit:
Array.indexOf() !== -1
is also a very common pattern. Might also want to tackle it at the same time.Array.indexOf(a) !== -1
, suggestArray.includes()
insteadCareful of this pattern when autofixing:
(badIndex = params.tags.indexOf('Bad GIF')) !== -1
. That should not be autofixed due to the variable depending on getting the indexOf's value.