@@ -31,14 +31,6 @@ const isExpectAssertionsOrHasAssertionsCall = expression => {
31
31
}
32
32
} ;
33
33
34
- const isTestOrItFunction = node => {
35
- return (
36
- node . type === 'CallExpression' &&
37
- node . callee &&
38
- ( node . callee . name === 'it' || node . callee . name === 'test' )
39
- ) ;
40
- } ;
41
-
42
34
const getFunctionFirstLine = functionBody => {
43
35
return functionBody [ 0 ] && functionBody [ 0 ] . expression ;
44
36
} ;
@@ -47,14 +39,6 @@ const isFirstLineExprStmt = functionBody => {
47
39
return functionBody [ 0 ] && functionBody [ 0 ] . type === 'ExpressionStatement' ;
48
40
} ;
49
41
50
- const getTestFunctionBody = node => {
51
- try {
52
- return node . arguments [ 1 ] . body . body ;
53
- } catch ( e ) {
54
- return undefined ;
55
- }
56
- } ;
57
-
58
42
const reportMsg = ( context , node ) => {
59
43
context . report ( {
60
44
message : ruleMsg ,
@@ -70,18 +54,15 @@ module.exports = {
70
54
} ,
71
55
create ( context ) {
72
56
return {
73
- CallExpression ( node ) {
74
- if ( isTestOrItFunction ( node ) ) {
75
- const testFuncBody = getTestFunctionBody ( node ) ;
76
- if ( testFuncBody ) {
77
- if ( ! isFirstLineExprStmt ( testFuncBody ) ) {
78
- reportMsg ( context , node ) ;
79
- } else {
80
- const testFuncFirstLine = getFunctionFirstLine ( testFuncBody ) ;
81
- if ( ! isExpectAssertionsOrHasAssertionsCall ( testFuncFirstLine ) ) {
82
- reportMsg ( context , node ) ;
83
- }
84
- }
57
+ 'CallExpression[callee.name=/^it|test$/][arguments.1.body.body]' ( node ) {
58
+ const testFuncBody = node . arguments [ 1 ] . body . body ;
59
+
60
+ if ( ! isFirstLineExprStmt ( testFuncBody ) ) {
61
+ reportMsg ( context , node ) ;
62
+ } else {
63
+ const testFuncFirstLine = getFunctionFirstLine ( testFuncBody ) ;
64
+ if ( ! isExpectAssertionsOrHasAssertionsCall ( testFuncFirstLine ) ) {
65
+ reportMsg ( context , node ) ;
85
66
}
86
67
}
87
68
} ,
0 commit comments