'debug': function (context) {
return {
Program: function (node) {
console.log('debug active');
context.report({
node,
message: 'debug active',
loc: { start: { line: 1, column: 1 } },
});
}
}
},
...
// this is a very simplistic rule to find 'unnecesary use of indexOf' until I find a better eslint plugin that does this
'prefer-index-of': function (context) {
return {
Program: function (node) {
let lineno = 0;
let m;
for (const line of context.getSourceCode().getText().split('\n')) { // eslint-disable-line newline-per-chained-call
lineno += 1;
if (m = line.match(/\.indexOf(.*) *(=+ *-1|!=+ *-1|> *-1|>= *0|< *0)/)) {
context.report({
node,
message: "Unnecessary '.indexOf()', use '.includes()' instead",
loc: { start: { line: lineno, column: line.indexOf(m[0]) + 1 } },
});
}
}
}
};
},
Created
February 28, 2019 11:21
-
-
Save retorquere/5144bbe3da1db27de445b5474282ef36 to your computer and use it in GitHub Desktop.
Author
retorquere
commented
Feb 28, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment