File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 66 no-var : 2
77 prefer-const : 2
88
9+ # Custom rules in tools/eslint-rules
10+ prefer-common-mustnotcall : 2
11+
912 # # common module is mandatory in tests
1013 required-modules : [2, common]
1114 prefer-assert-methods : 2
Original file line number Diff line number Diff line change 1+ /**
2+ * @fileoverview Prefer common.mustNotCall(msg) over common.mustCall(fn, 0)
3+ * @author James M Snell <[email protected] > 4+ */
5+ 'use strict' ;
6+
7+ //------------------------------------------------------------------------------
8+ // Rule Definition
9+ //------------------------------------------------------------------------------
10+
11+ const msg = 'Please use common.mustNotCall(msg) instead of ' +
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+ }
28+
29+ module . exports = function ( context ) {
30+ 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+ }
38+ } ;
39+ } ;
You can’t perform that action at this time.
0 commit comments