@@ -26,45 +26,25 @@ module.exports = {
26
26
] ,
27
27
} ,
28
28
create ( context ) {
29
- // variables should be defined here
30
29
const unchecked = [ ] ;
31
30
const assertFunctionNames =
32
31
context . options [ 0 ] && context . options [ 0 ] . assertFunctionNames
33
32
? context . options [ 0 ] . assertFunctionNames
34
33
: [ 'expect' ] ;
35
34
36
- //----------------------------------------------------------------------
37
- // Helpers
38
- //----------------------------------------------------------------------
39
- const isExpectCall = node =>
40
- // if we're not calling a function, ignore
41
- node . type === 'CallExpression' &&
42
- // if we're not calling allowed assertion
43
- assertFunctionNames . some ( name => name === node . callee . name ) ;
44
- //----------------------------------------------------------------------
45
- // Public
46
- //----------------------------------------------------------------------
47
35
return {
48
- // give me methods
49
- CallExpression ( node ) {
50
- // keep track of `it` calls
51
- if ( [ 'it' , 'test' ] . indexOf ( node . callee . name ) > - 1 ) {
52
- unchecked . push ( node ) ;
53
- return ;
54
- }
55
- if ( ! isExpectCall ( node ) ) {
56
- return ;
57
- }
58
- // here, we do have a call to expect
59
- // use `some` to return early (in case of nested `it`s
60
- context . getAncestors ( ) . some ( ancestor => {
36
+ 'CallExpression[callee.name=/^it|test$/]' ( node ) {
37
+ unchecked . push ( node ) ;
38
+ } ,
39
+ [ `CallExpression[callee.name=/^${ assertFunctionNames . join ( '|' ) } $/]` ] ( ) {
40
+ // Return early in case of nested `it` statements.
41
+ for ( const ancestor of context . getAncestors ( ) ) {
61
42
const index = unchecked . indexOf ( ancestor ) ;
62
43
if ( index !== - 1 ) {
63
44
unchecked . splice ( index , 1 ) ;
64
- return true ;
45
+ break ;
65
46
}
66
- return false ;
67
- } ) ;
47
+ }
68
48
} ,
69
49
'Program:exit' ( ) {
70
50
unchecked . forEach ( node =>
0 commit comments