@@ -12,14 +12,12 @@ const snapshotMatchers = ['toMatchSnapshot', 'toThrowErrorMatchingSnapshot'];
12
12
const snapshotMatcherNames = snapshotMatchers ;
13
13
14
14
const isSnapshotMatcherWithoutHint = ( expectFnCall : ParsedExpectFnCall ) => {
15
- if ( ! expectFnCall . args || expectFnCall . args . length === 0 ) {
15
+ if ( expectFnCall . args . length === 0 ) {
16
16
return true ;
17
17
}
18
18
19
- const matcher = expectFnCall . members [ expectFnCall . members . length - 1 ] ;
20
-
21
19
// this matcher only supports one argument which is the hint
22
- if ( ! isSupportedAccessor ( matcher , 'toMatchSnapshot' ) ) {
20
+ if ( ! isSupportedAccessor ( expectFnCall . matcher , 'toMatchSnapshot' ) ) {
23
21
return expectFnCall . args . length !== 1 ;
24
22
}
25
23
@@ -67,12 +65,9 @@ export default createRule<[('always' | 'multi')?], keyof typeof messages>({
67
65
const reportSnapshotMatchersWithoutHints = ( ) => {
68
66
for ( const snapshotMatcher of snapshotMatchers ) {
69
67
if ( isSnapshotMatcherWithoutHint ( snapshotMatcher ) ) {
70
- const matcher =
71
- snapshotMatcher . members [ snapshotMatcher . members . length - 1 ] ;
72
-
73
68
context . report ( {
74
69
messageId : 'missingHint' ,
75
- node : matcher ,
70
+ node : snapshotMatcher . matcher ,
76
71
} ) ;
77
72
}
78
73
}
@@ -126,12 +121,9 @@ export default createRule<[('always' | 'multi')?], keyof typeof messages>({
126
121
return ;
127
122
}
128
123
129
- const matcher = jestFnCall . members [ jestFnCall . members . length - 1 ] ;
124
+ const matcherName = getAccessorValue ( jestFnCall . matcher ) ;
130
125
131
- if (
132
- ! matcher ||
133
- ! snapshotMatcherNames . includes ( getAccessorValue ( matcher ) )
134
- ) {
126
+ if ( ! snapshotMatcherNames . includes ( matcherName ) ) {
135
127
return ;
136
128
}
137
129
0 commit comments