-
Notifications
You must be signed in to change notification settings - Fork 65
/
no-single-chain.js
36 lines (30 loc) · 1.1 KB
/
no-single-chain.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* @fileoverview Rule to disallow the use of a chain for a single method
*/
'use strict';
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = function (context) {
var lodashUtil = require('../util/lodashUtil');
var astUtil = require('../util/astUtil');
function isEndOfChain(node) {
return !astUtil.isObjectOfMethodCall(node);
}
function isBeforeChainBreaker(node) {
return lodashUtil.isChainBreaker(node.parent.parent);
}
return {
CallExpression: function (node) {
if (lodashUtil.isLodashChainStart(node)) {
var firstCall = node.parent.parent;
if (astUtil.isMethodCall(firstCall) && (isEndOfChain(firstCall) || isBeforeChainBreaker(firstCall))) {
context.report(firstCall, 'Do not use chain syntax for single method');
}
}
}
};
};
module.exports.schema = [
// JSON Schema for rule options goes here
];