@@ -60,17 +60,17 @@ export const onlyExportComponents: TSESLint.RuleModule<
60
60
const filename = context . filename ;
61
61
// Skip tests & stories files
62
62
if (
63
- filename . includes ( ".test." ) ||
64
- filename . includes ( ".spec." ) ||
65
- filename . includes ( ".cy." ) ||
66
- filename . includes ( ".stories." )
63
+ filename . includes ( ".test." )
64
+ || filename . includes ( ".spec." )
65
+ || filename . includes ( ".cy." )
66
+ || filename . includes ( ".stories." )
67
67
) {
68
68
return { } ;
69
69
}
70
70
const shouldScan =
71
- filename . endsWith ( ".jsx" ) ||
72
- filename . endsWith ( ".tsx" ) ||
73
- ( checkJS && filename . endsWith ( ".js" ) ) ;
71
+ filename . endsWith ( ".jsx" )
72
+ || filename . endsWith ( ".tsx" )
73
+ || ( checkJS && filename . endsWith ( ".js" ) ) ;
74
74
if ( ! shouldScan ) return { } ;
75
75
76
76
const allowExportNamesSet = allowExportNames
@@ -83,8 +83,8 @@ export const onlyExportComponents: TSESLint.RuleModule<
83
83
const jsInit = skipTSWrapper ( init ) ;
84
84
if ( jsInit . type === "ArrowFunctionExpression" ) return true ;
85
85
if (
86
- jsInit . type === "CallExpression" &&
87
- jsInit . callee . type === "Identifier"
86
+ jsInit . type === "CallExpression"
87
+ && jsInit . callee . type === "Identifier"
88
88
) {
89
89
return reactHOCs . includes ( jsInit . callee . name ) ;
90
90
}
@@ -114,9 +114,9 @@ export const onlyExportComponents: TSESLint.RuleModule<
114
114
}
115
115
if ( allowExportNamesSet ?. has ( identifierNode . name ) ) return ;
116
116
if (
117
- allowConstantExport &&
118
- init &&
119
- constantExportExpressions . has ( skipTSWrapper ( init ) . type )
117
+ allowConstantExport
118
+ && init
119
+ && constantExportExpressions . has ( skipTSWrapper ( init ) . type )
120
120
) {
121
121
return ;
122
122
}
@@ -129,22 +129,22 @@ export const onlyExportComponents: TSESLint.RuleModule<
129
129
}
130
130
} else {
131
131
if (
132
- init &&
133
- init . type === "CallExpression" &&
132
+ init
133
+ && init . type === "CallExpression"
134
134
// createContext || React.createContext
135
- ( ( init . callee . type === "Identifier" &&
136
- init . callee . name === "createContext" ) ||
137
- ( init . callee . type === "MemberExpression" &&
138
- init . callee . property . type === "Identifier" &&
139
- init . callee . property . name === "createContext" ) )
135
+ && ( ( init . callee . type === "Identifier"
136
+ && init . callee . name === "createContext" )
137
+ || ( init . callee . type === "MemberExpression"
138
+ && init . callee . property . type === "Identifier"
139
+ && init . callee . property . name === "createContext" ) )
140
140
) {
141
141
reactContextExports . push ( identifierNode ) ;
142
142
return ;
143
143
}
144
144
if (
145
- init &&
145
+ init
146
146
// Switch to allowList?
147
- notReactComponentExpression . has ( init . type )
147
+ && notReactComponentExpression . has ( init . type )
148
148
) {
149
149
nonComponentExports . push ( identifierNode ) ;
150
150
return ;
@@ -163,16 +163,16 @@ export const onlyExportComponents: TSESLint.RuleModule<
163
163
const isCalleeHOC =
164
164
// support for react-redux
165
165
// export default connect(mapStateToProps, mapDispatchToProps)(...)
166
- ( node . callee . type === "CallExpression" &&
167
- node . callee . callee . type === "Identifier" &&
168
- node . callee . callee . name === "connect" ) ||
166
+ ( node . callee . type === "CallExpression"
167
+ && node . callee . callee . type === "Identifier"
168
+ && node . callee . callee . name === "connect" )
169
169
// React.memo(...)
170
- ( node . callee . type === "MemberExpression" &&
171
- node . callee . property . type === "Identifier" &&
172
- reactHOCs . includes ( node . callee . property . name ) ) ||
170
+ || ( node . callee . type === "MemberExpression"
171
+ && node . callee . property . type === "Identifier"
172
+ && reactHOCs . includes ( node . callee . property . name ) )
173
173
// memo(...)
174
- ( node . callee . type === "Identifier" &&
175
- reactHOCs . includes ( node . callee . name ) ) ;
174
+ || ( node . callee . type === "Identifier"
175
+ && reactHOCs . includes ( node . callee . name ) ) ;
176
176
if ( ! isCalleeHOC ) return false ;
177
177
if ( node . arguments . length === 0 ) return false ;
178
178
const arg = skipTSWrapper ( node . arguments [ 0 ] ) ;
@@ -229,9 +229,9 @@ export const onlyExportComponents: TSESLint.RuleModule<
229
229
hasExports = true ;
230
230
const declaration = skipTSWrapper ( node . declaration ) ;
231
231
if (
232
- declaration . type === "VariableDeclaration" ||
233
- declaration . type === "FunctionDeclaration" ||
234
- declaration . type === "CallExpression"
232
+ declaration . type === "VariableDeclaration"
233
+ || declaration . type === "FunctionDeclaration"
234
+ || declaration . type === "CallExpression"
235
235
) {
236
236
handleExportDeclaration ( declaration ) ;
237
237
}
@@ -249,18 +249,18 @@ export const onlyExportComponents: TSESLint.RuleModule<
249
249
}
250
250
for ( const specifier of node . specifiers ) {
251
251
handleExportIdentifier (
252
- specifier . exported . type === "Identifier" &&
253
- specifier . exported . name === "default"
252
+ specifier . exported . type === "Identifier"
253
+ && specifier . exported . name === "default"
254
254
? specifier . local
255
255
: specifier . exported ,
256
256
) ;
257
257
}
258
258
} else if ( node . type === "VariableDeclaration" ) {
259
259
for ( const variable of node . declarations ) {
260
260
if (
261
- variable . id . type === "Identifier" &&
262
- reactComponentNameRE . test ( variable . id . name ) &&
263
- canBeReactFunctionComponent ( variable . init )
261
+ variable . id . type === "Identifier"
262
+ && reactComponentNameRE . test ( variable . id . name )
263
+ && canBeReactFunctionComponent ( variable . init )
264
264
) {
265
265
localComponents . push ( variable . id ) ;
266
266
}
@@ -270,8 +270,8 @@ export const onlyExportComponents: TSESLint.RuleModule<
270
270
localComponents . push ( node . id ) ;
271
271
}
272
272
} else if (
273
- node . type === "ImportDeclaration" &&
274
- node . source . value === "react"
273
+ node . type === "ImportDeclaration"
274
+ && node . source . value === "react"
275
275
) {
276
276
reactIsInScope = true ;
277
277
}
@@ -280,7 +280,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
280
280
if ( checkJS && ! reactIsInScope ) return ;
281
281
282
282
if ( hasExports ) {
283
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
283
+ // tsl-ignore core/noUnnecessaryCondition
284
284
if ( hasReactExport ) {
285
285
for ( const node of nonComponentExports ) {
286
286
context . report ( { messageId : "namedExport" , node } ) ;
0 commit comments