eslint-plugin-lodash
Version:
Lodash specific linting rules for ESLint
28 lines (24 loc) • 947 B
JavaScript
/**
* @fileoverview Rule to check if a call to _.indexOf === 0 should be a call to _.startsWith
*/
;
/**
* @fileoverview Rule to check if a call to _.indexOf === 0 should be a call to _.startsWith
*/
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
create: function create(context) {
var _require = require('../util/astUtil');
var isIndexOfCall = _require.isIndexOfCall;
var getExpressionComparedToInt = _require.getExpressionComparedToInt;
return {
BinaryExpression: function BinaryExpression(node) {
if (isIndexOfCall(getExpressionComparedToInt(node, 0))) {
context.report(node, 'Prefer _.startsWith instead of comparing indexOf() to 0');
}
}
};
}
};