| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,30 +10,21 @@ | |||
| 10 | 10 | ||
| 11 | 11 | const msg = 'Please use common.mustNotCall(msg) instead of ' + | |
| 12 | 12 | 'common.mustCall(fn, 0) or common.mustCall(0).'; | |
| 13 | - | ||
| 14 | - function isCommonMustCall(node) { | ||
| 15 | - return node && | ||
| 16 | - node.callee && | ||
| 17 | - node.callee.object && | ||
| 18 | - node.callee.object.name === 'common' && | ||
| 19 | - node.callee.property && | ||
| 20 | - node.callee.property.name === 'mustCall'; | ||
| 21 | - } | ||
| 22 | - | ||
| 23 | - function isArgZero(argument) { | ||
| 24 | - return argument && | ||
| 25 | - typeof argument.value === 'number' && | ||
| 26 | - argument.value === 0; | ||
| 27 | - } | ||
| 13 | + const mustCallSelector = 'CallExpression[callee.object.name="common"]' + | ||
| 14 | + '[callee.property.name="mustCall"]'; | ||
| 15 | + const arg0Selector = `${mustCallSelector}[arguments.0.value=0]`; | ||
| 16 | + const arg1Selector = `${mustCallSelector}[arguments.1.value=0]`; | ||
| 28 | 17 | ||
| 29 | 18 | module.exports = function(context) { | |
| 19 | + function report(node) { | ||
| 20 | + context.report(node, msg); | ||
| 21 | + } | ||
| 22 | + | ||
| 30 | 23 | return { | |
| 31 | - CallExpression(node) { | ||
| 32 | - if (isCommonMustCall(node) && | ||
| 33 | - (isArgZero(node.arguments[0]) || // catch common.mustCall(0) | ||
| 34 | - isArgZero(node.arguments[1]))) { // catch common.mustCall(fn, 0) | ||
| 35 | - context.report(node, msg); | ||
| 36 | - } | ||
| 37 | - } | ||
| 24 | + // Catch common.mustCall(0) | ||
| 25 | + [arg0Selector]: report, | ||
| 26 | + | ||
| 27 | + // Catch common.mustCall(fn, 0) | ||
| 28 | + [arg1Selector]: report | ||
| 38 | 29 | }; | |
| 39 | 30 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments