@@ -60,17 +60,17 @@ export const onlyExportComponents: TSESLint.RuleModule<
6060 const filename = context . filename ;
6161 // Skip tests & stories files
6262 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." )
6767 ) {
6868 return { } ;
6969 }
7070 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" ) ) ;
7474 if ( ! shouldScan ) return { } ;
7575
7676 const allowExportNamesSet = allowExportNames
@@ -83,8 +83,8 @@ export const onlyExportComponents: TSESLint.RuleModule<
8383 const jsInit = skipTSWrapper ( init ) ;
8484 if ( jsInit . type === "ArrowFunctionExpression" ) return true ;
8585 if (
86- jsInit . type === "CallExpression" &&
87- jsInit . callee . type === "Identifier"
86+ jsInit . type === "CallExpression"
87+ && jsInit . callee . type === "Identifier"
8888 ) {
8989 return reactHOCs . includes ( jsInit . callee . name ) ;
9090 }
@@ -114,9 +114,9 @@ export const onlyExportComponents: TSESLint.RuleModule<
114114 }
115115 if ( allowExportNamesSet ?. has ( identifierNode . name ) ) return ;
116116 if (
117- allowConstantExport &&
118- init &&
119- constantExportExpressions . has ( skipTSWrapper ( init ) . type )
117+ allowConstantExport
118+ && init
119+ && constantExportExpressions . has ( skipTSWrapper ( init ) . type )
120120 ) {
121121 return ;
122122 }
@@ -129,22 +129,22 @@ export const onlyExportComponents: TSESLint.RuleModule<
129129 }
130130 } else {
131131 if (
132- init &&
133- init . type === "CallExpression" &&
132+ init
133+ && init . type === "CallExpression"
134134 // 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" ) )
140140 ) {
141141 reactContextExports . push ( identifierNode ) ;
142142 return ;
143143 }
144144 if (
145- init &&
145+ init
146146 // Switch to allowList?
147- notReactComponentExpression . has ( init . type )
147+ && notReactComponentExpression . has ( init . type )
148148 ) {
149149 nonComponentExports . push ( identifierNode ) ;
150150 return ;
@@ -163,16 +163,16 @@ export const onlyExportComponents: TSESLint.RuleModule<
163163 const isCalleeHOC =
164164 // support for react-redux
165165 // 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" )
169169 // 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 ) )
173173 // memo(...)
174- ( node . callee . type === "Identifier" &&
175- reactHOCs . includes ( node . callee . name ) ) ;
174+ || ( node . callee . type === "Identifier"
175+ && reactHOCs . includes ( node . callee . name ) ) ;
176176 if ( ! isCalleeHOC ) return false ;
177177 if ( node . arguments . length === 0 ) return false ;
178178 const arg = skipTSWrapper ( node . arguments [ 0 ] ) ;
@@ -229,9 +229,9 @@ export const onlyExportComponents: TSESLint.RuleModule<
229229 hasExports = true ;
230230 const declaration = skipTSWrapper ( node . declaration ) ;
231231 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"
235235 ) {
236236 handleExportDeclaration ( declaration ) ;
237237 }
@@ -249,18 +249,18 @@ export const onlyExportComponents: TSESLint.RuleModule<
249249 }
250250 for ( const specifier of node . specifiers ) {
251251 handleExportIdentifier (
252- specifier . exported . type === "Identifier" &&
253- specifier . exported . name === "default"
252+ specifier . exported . type === "Identifier"
253+ && specifier . exported . name === "default"
254254 ? specifier . local
255255 : specifier . exported ,
256256 ) ;
257257 }
258258 } else if ( node . type === "VariableDeclaration" ) {
259259 for ( const variable of node . declarations ) {
260260 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 )
264264 ) {
265265 localComponents . push ( variable . id ) ;
266266 }
@@ -270,8 +270,8 @@ export const onlyExportComponents: TSESLint.RuleModule<
270270 localComponents . push ( node . id ) ;
271271 }
272272 } else if (
273- node . type === "ImportDeclaration" &&
274- node . source . value === "react"
273+ node . type === "ImportDeclaration"
274+ && node . source . value === "react"
275275 ) {
276276 reactIsInScope = true ;
277277 }
@@ -280,7 +280,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
280280 if ( checkJS && ! reactIsInScope ) return ;
281281
282282 if ( hasExports ) {
283- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
283+ // tsl-ignore core/noUnnecessaryCondition
284284 if ( hasReactExport ) {
285285 for ( const node of nonComponentExports ) {
286286 context . report ( { messageId : "namedExport" , node } ) ;
0 commit comments