@@ -2,7 +2,6 @@ import * as AST from "@eslint-react/ast";
22import type { RuleContext } from "@eslint-react/shared" ;
33import type { TSESTree } from "@typescript-eslint/types" ;
44import { AST_NODE_TYPES as T } from "@typescript-eslint/types" ;
5- import { JsxDetectionHint , isJsxLike } from "../jsx" ;
65
76/**
87 * Unsafe check whether given node is a render function
@@ -16,23 +15,13 @@ import { JsxDetectionHint, isJsxLike } from "../jsx";
1615 * @param node The AST node to check
1716 * @returns `true` if node is a render function, `false` if not
1817 */
19- export function isRenderFunctionLoose ( context : RuleContext , node : AST . TSESTreeFunction ) {
20- const { body, parent } = node ;
21- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
22- if ( AST . getFunctionId ( node ) ?. name . startsWith ( "render" ) ) {
23- return parent . type === T . JSXExpressionContainer
24- && parent . parent . type === T . JSXAttribute
25- && parent . parent . name . type === T . JSXIdentifier
26- && parent . parent . name . name . startsWith ( "render" ) ;
27- }
28- return isJsxLike (
29- context . sourceCode ,
30- body ,
31- JsxDetectionHint . SkipNullLiteral
32- | JsxDetectionHint . SkipUndefined
33- | JsxDetectionHint . StrictLogical
34- | JsxDetectionHint . StrictConditional ,
35- ) ;
18+ export function isRenderFunctionLoose ( context : RuleContext , node : TSESTree . Node ) : node is AST . TSESTreeFunction {
19+ if ( ! AST . isFunction ( node ) ) return false ;
20+ if ( ( AST . getFunctionId ( node ) ?. name . startsWith ( "render" ) ) ?? false ) return true ;
21+ return node . parent . type === T . JSXExpressionContainer
22+ && node . parent . parent . type === T . JSXAttribute
23+ && node . parent . parent . name . type === T . JSXIdentifier
24+ && node . parent . parent . name . name . startsWith ( "render" ) ;
3625}
3726
3827/**
@@ -51,7 +40,6 @@ export function isRenderPropLoose(context: RuleContext, node: TSESTree.JSXAttrib
5140 }
5241 return node . name . name . startsWith ( "render" )
5342 && node . value ?. type === T . JSXExpressionContainer
54- && AST . isFunction ( node . value . expression )
5543 && isRenderFunctionLoose ( context , node . value . expression ) ;
5644}
5745
0 commit comments