/
no-commit.js
28 lines (24 loc) · 1.1 KB
/
no-commit.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
/**
* @fileoverview Rule to disallow using _.prototype.commit unless used after a function that only runs for its side effect.
*/
'use strict';
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = function (context) {
var lodashUtil = require('../util/lodashUtil');
var astUtil = require('../util/astUtil');
var lodashPragma = require('../util/settingsUtil').getLodashPragma(context);
return {
CallExpression: function (node) {
if (lodashUtil.isLodashChainStart(node, lodashPragma)) {
do {
node = node.parent.parent;
} while (astUtil.isMethodCall(node) && !lodashUtil.isCallToMethod(node, 'commit'));
if (lodashUtil.isCallToMethod(node, 'commit') && !lodashUtil.isCallToMethod(astUtil.getCaller(node), 'forEach')) {
context.report(node, 'Do not end chain with commit, except for side effects.');
}
}
}
};
};