File tree 2 files changed +40
-0
lines changed
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 9
9
# Custom rules in tools/eslint-rules
10
10
prefer-assert-iferror : 2
11
11
prefer-assert-methods : 2
12
+ prefer-common-mustnotcall : 2
12
13
# # common module is mandatory in tests
13
14
required-modules : [2, common]
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