ES7 introduced the includes
method for arrays so bitwise and comparisons to -1
are no longer needed.
Apply with the Grit CLI
grit apply index_of_to_includes
Transforms indexOf
BEFORE
!~foo.indexOf("a"); foo.indexOf("a") === -1; foo.indexOf("a") == -1; foo.indexOf("a") !== -1; foo.indexOf("a") != -1; ~foo.indexOf("a");
AFTER
!foo.includes("a"); !foo.includes("a") !foo.includes("a") foo.includes("a") foo.includes("a") foo.includes("a")
Transforms lastIndexOf
BEFORE
!~foo.lastIndexOf("a"); foo.lastIndexOf("a") === -1; foo.lastIndexOf("a") == -1; foo.lastIndexOf("a") !== -1; foo.lastIndexOf("a") != -1; ~foo.lastIndexOf("a");
AFTER
!foo.includes("a"); !foo.includes("a") !foo.includes("a") foo.includes("a") foo.includes("a") foo.includes("a")
Does not change lastIndexOf or indexOf if it checks for a real index
JAVASCRIPT
foo.lastIndexOf("") == 1; foo.indexOf("") == 1;