File tree 5 files changed +27
-64
lines changed
5 files changed +27
-64
lines changed Original file line number Diff line number Diff line change 1
1
import { AST_NODE_TYPES , TSESTree } from '@typescript-eslint/utils' ;
2
2
import {
3
3
EqualityMatcher ,
4
- ParsedExpectFnCall ,
5
4
createRule ,
6
- followTypeAssertionChain ,
7
5
getAccessorValue ,
6
+ getFirstMatcherArg ,
7
+ isBooleanLiteral ,
8
8
isStringNode ,
9
9
parseJestFnCall ,
10
10
} from './utils' ;
11
11
12
- const isBooleanLiteral = (
13
- node : TSESTree . Node ,
14
- ) : node is TSESTree . BooleanLiteral =>
15
- node . type === AST_NODE_TYPES . Literal && typeof node . value === 'boolean' ;
16
-
17
- const getFirstMatcherArg = ( expectFnCall : ParsedExpectFnCall ) => {
18
- const [ firstArg ] = expectFnCall . args ;
19
-
20
- if ( firstArg . type === AST_NODE_TYPES . SpreadElement ) {
21
- return firstArg ;
22
- }
23
-
24
- return followTypeAssertionChain ( firstArg ) ;
25
- } ;
26
-
27
12
const isString = ( node : TSESTree . Node ) => {
28
13
return isStringNode ( node ) || node . type === AST_NODE_TYPES . TemplateLiteral ;
29
14
} ;
Original file line number Diff line number Diff line change 1
- import { AST_NODE_TYPES , TSESLint , TSESTree } from '@typescript-eslint/utils' ;
1
+ import { AST_NODE_TYPES , TSESLint } from '@typescript-eslint/utils' ;
2
2
import {
3
3
EqualityMatcher ,
4
4
ModifierName ,
5
- ParsedExpectFnCall ,
6
5
createRule ,
7
- followTypeAssertionChain ,
8
6
getAccessorValue ,
7
+ getFirstMatcherArg ,
8
+ isBooleanLiteral ,
9
9
parseJestFnCall ,
10
10
} from './utils' ;
11
11
12
- const isBooleanLiteral = (
13
- node : TSESTree . Node ,
14
- ) : node is TSESTree . BooleanLiteral =>
15
- node . type === AST_NODE_TYPES . Literal && typeof node . value === 'boolean' ;
16
-
17
- const getFirstMatcherArg = ( expectFnCall : ParsedExpectFnCall ) => {
18
- const [ firstArg ] = expectFnCall . args ;
19
-
20
- if ( firstArg . type === AST_NODE_TYPES . SpreadElement ) {
21
- return firstArg ;
22
- }
23
-
24
- return followTypeAssertionChain ( firstArg ) ;
25
- } ;
26
-
27
12
export default createRule ( {
28
13
name : __filename ,
29
14
meta : {
Original file line number Diff line number Diff line change 4
4
EqualityMatcher ,
5
5
ParsedExpectFnCall ,
6
6
createRule ,
7
- followTypeAssertionChain ,
8
7
getAccessorValue ,
8
+ getFirstMatcherArg ,
9
9
isIdentifier ,
10
10
parseJestFnCall ,
11
11
replaceAccessorFixer ,
@@ -38,16 +38,6 @@ const shouldUseToBe = (expectFnCall: ParsedExpectFnCall): boolean => {
38
38
return firstArg . type === AST_NODE_TYPES . TemplateLiteral ;
39
39
} ;
40
40
41
- const getFirstMatcherArg = ( expectFnCall : ParsedExpectFnCall ) => {
42
- const [ firstArg ] = expectFnCall . args ;
43
-
44
- if ( firstArg . type === AST_NODE_TYPES . SpreadElement ) {
45
- return firstArg ;
46
- }
47
-
48
- return followTypeAssertionChain ( firstArg ) ;
49
- } ;
50
-
51
41
type MessageId =
52
42
| 'useToBe'
53
43
| 'useToBeUndefined'
Original file line number Diff line number Diff line change @@ -4,30 +4,15 @@ import {
4
4
EqualityMatcher ,
5
5
KnownCallExpression ,
6
6
ModifierName ,
7
- ParsedExpectFnCall ,
8
7
createRule ,
9
- followTypeAssertionChain ,
10
8
getAccessorValue ,
9
+ getFirstMatcherArg ,
11
10
hasOnlyOneArgument ,
11
+ isBooleanLiteral ,
12
12
isSupportedAccessor ,
13
13
parseJestFnCall ,
14
14
} from './utils' ;
15
15
16
- const isBooleanLiteral = (
17
- node : TSESTree . Node ,
18
- ) : node is TSESTree . BooleanLiteral =>
19
- node . type === AST_NODE_TYPES . Literal && typeof node . value === 'boolean' ;
20
-
21
- const getFirstMatcherArg = ( expectFnCall : ParsedExpectFnCall ) => {
22
- const [ firstArg ] = expectFnCall . args ;
23
-
24
- if ( firstArg . type === AST_NODE_TYPES . SpreadElement ) {
25
- return firstArg ;
26
- }
27
-
28
- return followTypeAssertionChain ( firstArg ) ;
29
- } ;
30
-
31
16
type FixableIncludesCallExpression = KnownCallExpression < 'includes' > &
32
17
CallExpressionWithSingleArgument ;
33
18
Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ import {
11
11
getAccessorValue ,
12
12
isSupportedAccessor ,
13
13
} from './accessors' ;
14
- import { isTypeOfJestFnCall } from './parseJestFnCall' ;
14
+ import { followTypeAssertionChain } from './followTypeAssertionChain' ;
15
+ import { ParsedExpectFnCall , isTypeOfJestFnCall } from './parseJestFnCall' ;
15
16
16
17
const REPO_URL = 'https://github.com/jest-community/eslint-plugin-jest' ;
17
18
@@ -191,3 +192,20 @@ export const findTopMostCallExpression = (
191
192
192
193
return topMostCallExpression ;
193
194
} ;
195
+
196
+ export const isBooleanLiteral = (
197
+ node : TSESTree . Node ,
198
+ ) : node is TSESTree . BooleanLiteral =>
199
+ node . type === AST_NODE_TYPES . Literal && typeof node . value === 'boolean' ;
200
+
201
+ export const getFirstMatcherArg = (
202
+ expectFnCall : ParsedExpectFnCall ,
203
+ ) : TSESTree . SpreadElement | TSESTree . Expression => {
204
+ const [ firstArg ] = expectFnCall . args ;
205
+
206
+ if ( firstArg . type === AST_NODE_TYPES . SpreadElement ) {
207
+ return firstArg ;
208
+ }
209
+
210
+ return followTypeAssertionChain ( firstArg ) ;
211
+ } ;
You can’t perform that action at this time.
0 commit comments