-
Notifications
You must be signed in to change notification settings - Fork 65
/
no-double-unwrap.js
26 lines (24 loc) · 1 KB
/
no-double-unwrap.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
/**
* @fileoverview Rule to make sure value() wasn't called on a lodash chain twice
*/
'use strict';
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = function (context) {
var lodashUtil = require('../util/lodashUtil');
var astUtil = require('../util/astUtil');
return {
CallExpression: function (node) {
if (lodashUtil.isImplicitChainStart(node)) {
do {
node = node.parent.parent;
} while (astUtil.isMethodCall(node) && !lodashUtil.isChainBreaker(node));
var caller = astUtil.getCaller(node);
if (astUtil.isMethodCall(node) && !lodashUtil.isChainable(caller)) {
context.report(node, 'Do not use .value() after chain-ending method {{method}}', {method: astUtil.getMethodName(caller)});
}
}
}
};
};