@@ -57,91 +57,74 @@ module.exports = {
5757 let testDepth = 0 ;
5858
5959 return {
60+ 'CallExpression[callee.name="describe"]' ( ) {
61+ suiteDepth ++ ;
62+ } ,
63+ 'CallExpression[callee.name=/^it|test$/]' ( ) {
64+ testDepth ++ ;
65+ } ,
66+ 'CallExpression[callee.name=/^it|test$/][arguments.length<2]' ( node ) {
67+ context . report ( {
68+ message : 'Test is missing function argument' ,
69+ node,
70+ } ) ;
71+ } ,
6072 CallExpression ( node ) {
6173 const functionName = getName ( node . callee ) ;
6274
6375 switch ( functionName ) {
64- case 'describe' :
65- suiteDepth ++ ;
66- break ;
67-
6876 case 'describe.skip' :
6977 context . report ( { message : 'Skipped test suite' , node } ) ;
7078 break ;
7179
72- case 'it' :
73- case 'test' :
74- testDepth ++ ;
75- if ( node . arguments . length < 2 ) {
76- context . report ( {
77- message : 'Test is missing function argument' ,
78- node,
79- } ) ;
80- }
81- break ;
82-
8380 case 'it.skip' :
8481 case 'test.skip' :
8582 context . report ( { message : 'Skipped test' , node } ) ;
8683 break ;
87-
88- case 'pending' : {
89- const references = collectReferences ( context . getScope ( ) ) ;
90-
91- if (
92- // `pending` was found as a local variable or function declaration.
93- references . locals . has ( 'pending' ) ||
94- // `pending` was not found as an unresolved reference,
95- // meaning it is likely not an implicit global reference.
96- ! references . unresolved . has ( 'pending' )
97- ) {
98- break ;
99- }
100-
101- if ( testDepth > 0 ) {
102- context . report ( {
103- message : 'Call to pending() within test' ,
104- node,
105- } ) ;
106- } else if ( suiteDepth > 0 ) {
107- context . report ( {
108- message : 'Call to pending() within test suite' ,
109- node,
110- } ) ;
111- } else {
112- context . report ( {
113- message : 'Call to pending()' ,
114- node,
115- } ) ;
116- }
117- break ;
118- }
119-
120- case 'xdescribe' :
121- context . report ( { message : 'Disabled test suite' , node } ) ;
122- break ;
123-
124- case 'xit' :
125- case 'xtest' :
126- context . report ( { message : 'Disabled test' , node } ) ;
127- break ;
12884 }
12985 } ,
86+ 'CallExpression[callee.name="pending"]' ( node ) {
87+ const references = collectReferences ( context . getScope ( ) ) ;
88+
89+ if (
90+ // `pending` was found as a local variable or function declaration.
91+ references . locals . has ( 'pending' ) ||
92+ // `pending` was not found as an unresolved reference,
93+ // meaning it is likely not an implicit global reference.
94+ ! references . unresolved . has ( 'pending' )
95+ ) {
96+ return ;
97+ }
13098
131- 'CallExpression:exit' ( node ) {
132- const functionName = getName ( node . callee ) ;
133-
134- switch ( functionName ) {
135- case 'describe' :
136- suiteDepth -- ;
137- break ;
138-
139- case 'it' :
140- case 'test' :
141- testDepth -- ;
142- break ;
99+ if ( testDepth > 0 ) {
100+ context . report ( {
101+ message : 'Call to pending() within test' ,
102+ node,
103+ } ) ;
104+ } else if ( suiteDepth > 0 ) {
105+ context . report ( {
106+ message : 'Call to pending() within test suite' ,
107+ node,
108+ } ) ;
109+ } else {
110+ context . report ( {
111+ message : 'Call to pending()' ,
112+ node,
113+ } ) ;
143114 }
144115 } ,
116+ 'CallExpression[callee.name="xdescribe"]' ( node ) {
117+ context . report ( { message : 'Disabled test suite' , node } ) ;
118+ } ,
119+ 'CallExpression[callee.name=/^xit|xtest$/]' ( node ) {
120+ context . report ( { message : 'Disabled test' , node } ) ;
121+ } ,
122+ 'CallExpression[callee.name="describe"]:exit' ( ) {
123+ suiteDepth -- ;
124+ } ,
125+ 'CallExpression[callee.name=/^it|test$/]:exit' ( ) {
126+ testDepth -- ;
127+ } ,
145128 } ;
146129 } ,
147130} ;
0 commit comments