@@ -192,8 +192,7 @@ export default createRule<[], MessageID>({
192
192
} ) ;
193
193
194
194
export function create ( context : RuleContext < MessageID , [ ] > ) : RuleListener {
195
- if ( ! context . sourceCode . text . includes ( "&&" ) && ! context . sourceCode . text . includes ( "?" ) ) return { } ;
196
-
195
+ if ( ! context . sourceCode . text . includes ( "&&" ) ) return { } ;
197
196
const { version } = getSettingsFromContext ( context ) ;
198
197
199
198
// Allowed left node type variants
@@ -213,10 +212,18 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
213
212
] as const satisfies VariantType [ ] ;
214
213
215
214
const services = ESLintUtils . getParserServices ( context , false ) ;
216
- function getReportDescriptor ( node : TSESTree . Expression | _ ) : ReportDescriptor < MessageID > | _ {
215
+ function getReportDescriptor (
216
+ node :
217
+ | _
218
+ | TSESTree . Expression
219
+ | TSESTree . JSXExpressionContainer
220
+ | TSESTree . JSXExpressionContainer [ "expression" ] ,
221
+ ) : ReportDescriptor < MessageID > | _ {
217
222
if ( node == null ) return _ ;
223
+ if ( AST . is ( T . JSXExpressionContainer ) ( node ) ) return getReportDescriptor ( node . expression ) ;
224
+ if ( AST . isJSX ( node ) ) return _ ;
225
+ if ( AST . isTypeExpression ( node ) ) return getReportDescriptor ( node . expression ) ;
218
226
return match < typeof node , ReportDescriptor < MessageID > | _ > ( node )
219
- . when ( AST . isJSX , ( ) => _ )
220
227
. with ( { type : T . LogicalExpression , operator : "&&" } , ( { left, right } ) => {
221
228
const isLeftUnaryNot = left . type === T . UnaryExpression && left . operator === "!" ;
222
229
if ( isLeftUnaryNot ) {
@@ -260,10 +267,8 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
260
267
} )
261
268
. otherwise ( ( ) => _ ) ;
262
269
}
263
- const visitorFunction = flow ( getReportDescriptor , Report . make ( context ) . send ) ;
264
270
return {
265
- "JSXExpressionContainer > ConditionalExpression" : visitorFunction ,
266
- "JSXExpressionContainer > LogicalExpression" : visitorFunction ,
271
+ JSXExpressionContainer : flow ( getReportDescriptor , Report . make ( context ) . send ) ,
267
272
} ;
268
273
}
269
274
0 commit comments