Commit d59b0a7 1 parent f45ef44 commit d59b0a7 Copy full SHA for d59b0a7
File tree 1 file changed +13
-22
lines changed
1 file changed +13
-22
lines changed Original file line number Diff line number Diff line change 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
} ;
You can’t perform that action at this time.
0 commit comments