Skip to content

Commit 3e70ee8

Browse files
cjihriggibfahn
authored andcommitted
tools: simplify prefer-common-mustnotcall rule
PR-URL: #17572 Reviewed-By: Anatoli Papirovski <[email protected]>
1 parent 2d74af0 commit 3e70ee8

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

‎tools/eslint-rules/prefer-common-mustnotcall.js‎

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,21 @@
1010

1111
constmsg='Please use common.mustNotCall(msg) instead of '+
1212
'common.mustCall(fn, 0) or common.mustCall(0).';
13-
14-
functionisCommonMustCall(node){
15-
returnnode&&
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-
functionisArgZero(argument){
24-
returnargument&&
25-
typeofargument.value==='number'&&
26-
argument.value===0;
27-
}
13+
constmustCallSelector='CallExpression[callee.object.name="common"]'+
14+
'[callee.property.name="mustCall"]';
15+
constarg0Selector=`${mustCallSelector}[arguments.0.value=0]`;
16+
constarg1Selector=`${mustCallSelector}[arguments.1.value=0]`;
2817

2918
module.exports=function(context){
19+
functionreport(node){
20+
context.report(node,msg);
21+
}
22+
3023
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
3829
};
3930
};

0 commit comments

Comments
(0)