canonical
Version:
Canonical code style linter and formatter for JavaScript, SCSS and CSS.
27 lines (22 loc) • 889 B
JavaScript
/**
* @fileoverview Rule to disallow the use of a chain for a single method
*/
;
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = function (context) {
var lodashUtil = require('../util/lodashUtil');
var astUtil = require('../util/astUtil');
function isBound(node) {
return node && node.type === 'CallExpression' && astUtil.getMethodName(node) === 'bind' && node.arguments.length === 1;
}
return {
CallExpression: function (node) {
var iteratee = lodashUtil.getLodashIteratee(node);
if (isBound(iteratee)) {
context.report(iteratee.callee.property, 'Unnecessary bind, pass `thisArg` to lodash method instead');
}
}
};
};