diff options
author | cjihrig <cjihrig@gmail.com> | 2017-12-09 09:38:14 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2017-12-11 21:04:48 -0500 |
commit | e4a71098efae67f7edf40962b684c816a7f59e68 (patch) | |
tree | 59bc9e0224420494c335d16f734201343714306a /tools/eslint-rules | |
parent | c84ca17305964905c99d16066cb56d6950e30256 (diff) | |
download | android-node-v8-e4a71098efae67f7edf40962b684c816a7f59e68.tar.gz android-node-v8-e4a71098efae67f7edf40962b684c816a7f59e68.tar.bz2 android-node-v8-e4a71098efae67f7edf40962b684c816a7f59e68.zip |
tools: simplify prefer-common-mustnotcall rule
PR-URL: https://github.com/nodejs/node/pull/17572
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Diffstat (limited to 'tools/eslint-rules')
-rw-r--r-- | tools/eslint-rules/prefer-common-mustnotcall.js | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/tools/eslint-rules/prefer-common-mustnotcall.js b/tools/eslint-rules/prefer-common-mustnotcall.js index 6bc428ed59..ef3c5fb729 100644 --- a/tools/eslint-rules/prefer-common-mustnotcall.js +++ b/tools/eslint-rules/prefer-common-mustnotcall.js @@ -10,30 +10,21 @@ const msg = 'Please use common.mustNotCall(msg) instead of ' + 'common.mustCall(fn, 0) or common.mustCall(0).'; - -function isCommonMustCall(node) { - return node && - node.callee && - node.callee.object && - node.callee.object.name === 'common' && - node.callee.property && - node.callee.property.name === 'mustCall'; -} - -function isArgZero(argument) { - return argument && - typeof argument.value === 'number' && - argument.value === 0; -} +const mustCallSelector = 'CallExpression[callee.object.name="common"]' + + '[callee.property.name="mustCall"]'; +const arg0Selector = `${mustCallSelector}[arguments.0.value=0]`; +const arg1Selector = `${mustCallSelector}[arguments.1.value=0]`; module.exports = function(context) { + function report(node) { + context.report(node, msg); + } + return { - CallExpression(node) { - if (isCommonMustCall(node) && - (isArgZero(node.arguments[0]) || // catch common.mustCall(0) - isArgZero(node.arguments[1]))) { // catch common.mustCall(fn, 0) - context.report(node, msg); - } - } + // Catch common.mustCall(0) + [arg0Selector]: report, + + // Catch common.mustCall(fn, 0) + [arg1Selector]: report }; }; |