File tree Expand file tree Collapse file tree 3 files changed +37
-47
lines changed Expand file tree Collapse file tree 3 files changed +37
-47
lines changed Original file line number Diff line number Diff line change @@ -105,4 +105,37 @@ export function hasThenProperty(node: TSESTree.Node) {
105
105
106
106
export function isArrowFunctionExpression ( node : TSESTree . Node ) : node is TSESTree . ArrowFunctionExpression {
107
107
return node && node . type === 'ArrowFunctionExpression'
108
+ }
109
+
110
+ function isRenderFunction (
111
+ callNode : TSESTree . CallExpression ,
112
+ renderFunctions : string [ ]
113
+ ) {
114
+ return [ 'render' , ...renderFunctions ] . some (
115
+ name => isIdentifier ( callNode . callee ) && name === callNode . callee . name
116
+ ) ;
117
+ }
118
+
119
+ export function isRenderVariableDeclarator (
120
+ node : TSESTree . VariableDeclarator ,
121
+ renderFunctions : string [ ] = [ ]
122
+ ) {
123
+ if ( node . init ) {
124
+ if ( isAwaitExpression ( node . init ) ) {
125
+ return (
126
+ node . init . argument &&
127
+ isRenderFunction (
128
+ node . init . argument as TSESTree . CallExpression ,
129
+ renderFunctions
130
+ )
131
+ ) ;
132
+ } else {
133
+ return (
134
+ isCallExpression ( node . init ) &&
135
+ isRenderFunction ( node . init , renderFunctions )
136
+ ) ;
137
+ }
138
+ }
139
+
140
+ return false ;
108
141
}
Original file line number Diff line number Diff line change @@ -6,22 +6,11 @@ import {
6
6
isMemberExpression ,
7
7
isObjectPattern ,
8
8
isProperty ,
9
+ isRenderVariableDeclarator ,
9
10
} from '../node-utils' ;
10
11
11
12
export const RULE_NAME = 'no-container' ;
12
13
13
- function isRender ( callNode : TSESTree . CallExpression ) {
14
- return isIdentifier ( callNode . callee ) && callNode . callee . name === 'render' ;
15
- }
16
-
17
- function isRenderVariableDeclarator ( node : TSESTree . VariableDeclarator ) {
18
- if ( node . init ) {
19
- if ( isCallExpression ( node . init ) ) {
20
- return isRender ( node . init ) ;
21
- }
22
- }
23
- }
24
-
25
14
export default ESLintUtils . RuleCreator ( getDocsUrl ) ( {
26
15
name : RULE_NAME ,
27
16
meta : {
@@ -32,7 +21,8 @@ export default ESLintUtils.RuleCreator(getDocsUrl)({
32
21
recommended : 'error' ,
33
22
} ,
34
23
messages : {
35
- noContainer : 'Unexpected use of container methods. Prefer the use of "screen.someMethod()".' ,
24
+ noContainer :
25
+ 'Unexpected use of container methods. Prefer the use of "screen.someMethod()".' ,
36
26
} ,
37
27
fixable : null ,
38
28
schema : [ ] ,
Original file line number Diff line number Diff line change @@ -6,46 +6,13 @@ import {
6
6
isIdentifier ,
7
7
isCallExpression ,
8
8
isLiteral ,
9
- isAwaitExpression ,
10
9
isMemberExpression ,
11
10
isImportSpecifier ,
11
+ isRenderVariableDeclarator ,
12
12
} from '../node-utils' ;
13
13
14
14
export const RULE_NAME = 'no-debug' ;
15
15
16
- function isRenderFunction (
17
- callNode : TSESTree . CallExpression ,
18
- renderFunctions : string [ ]
19
- ) {
20
- return [ 'render' , ...renderFunctions ] . some (
21
- name => isIdentifier ( callNode . callee ) && name === callNode . callee . name
22
- ) ;
23
- }
24
-
25
- function isRenderVariableDeclarator (
26
- node : TSESTree . VariableDeclarator ,
27
- renderFunctions : string [ ]
28
- ) {
29
- if ( node . init ) {
30
- if ( isAwaitExpression ( node . init ) ) {
31
- return (
32
- node . init . argument &&
33
- isRenderFunction (
34
- node . init . argument as TSESTree . CallExpression ,
35
- renderFunctions
36
- )
37
- ) ;
38
- } else {
39
- return (
40
- isCallExpression ( node . init ) &&
41
- isRenderFunction ( node . init , renderFunctions )
42
- ) ;
43
- }
44
- }
45
-
46
- return false ;
47
- }
48
-
49
16
function hasTestingLibraryImportModule (
50
17
importDeclarationNode : TSESTree . ImportDeclaration
51
18
) {
You can’t perform that action at this time.
0 commit comments