eslint-plugin-lodash
Version:
Lodash specific linting rules for ESLint
40 lines (31 loc) • 1.52 kB
JavaScript
/**
* @fileoverview Rule to check if there's a method in the chain start that can be in the chain
*/
;
/**
* @fileoverview Rule to check if there's a method in the chain start that can be in the chain
*/
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
create: function create(context) {
var _require = require('../util/lodashUtil');
var isLodashChainStart = _require.isLodashChainStart;
var getLodashImportVisitors = _require.getLodashImportVisitors;
var _require$getSettings = require('../util/settingsUtil').getSettings(context);
var pragma = _require$getSettings.pragma;
var _require2 = require('../util/ruleUtil');
var combineVisitorObjects = _require2.combineVisitorObjects;
function isSingleArgumentFunctionCall(node) {
return node && node.type === 'CallExpression' && node.arguments.length === 1 && node.arguments[0].type !== 'Literal';
}
return combineVisitorObjects({
CallExpression: function CallExpression(node) {
if (isLodashChainStart(node, pragma, context) && isSingleArgumentFunctionCall(node.arguments[0])) {
context.report(node, 'Prefer using thru instead of function call in chain start.');
}
}
}, getLodashImportVisitors(context));
}
};