@@ -568,28 +568,37 @@ function isIgnoredProperty(node: TSESTree.Node, ignoreProperties: string[]): boo
568568}
569569
570570/**
571- * Checks if a string is inside an object assigned to a styling constant.
571+ * Checks if a string is a direct property value in an object assigned to a styling constant.
572572 *
573- * Matches patterns like :
573+ * Only matches the exact structure :
574574 * const STATUS_COLORS = { active: "bg-green-100..." }
575- * const BUTTON_STYLES = { primary: "px-4 py-2..." }
575+ *
576+ * Does NOT match strings inside functions, IIFEs, or nested structures:
577+ * const STATUS_COLORS = { active: (() => "value")() } // ❌ not matched
578+ * const STATUS_COLORS = { active: fn("value") } // ❌ not matched
576579 */
577580function isInsideStylingConstant ( node : TSESTree . Node ) : boolean {
578- let current : TSESTree . Node | undefined = node . parent ?? undefined
581+ // Must be: Literal → Property (as value) → ObjectExpression → VariableDeclarator
582+ const property = node . parent
583+ if ( property ?. type !== AST_NODE_TYPES . Property || property . value !== node ) {
584+ return false
585+ }
579586
580- while ( current !== undefined ) {
581- // Look for: const NAME = { ... } or let NAME = { ... }
582- if (
583- current . type === AST_NODE_TYPES . VariableDeclarator &&
584- current . id . type === AST_NODE_TYPES . Identifier &&
585- isStylingConstant ( current . id . name )
586- ) {
587- return true
588- }
589- current = current . parent ?? undefined
587+ const objectExpr = property . parent
588+ if ( objectExpr . type !== AST_NODE_TYPES . ObjectExpression ) {
589+ return false
590590 }
591591
592- return false
592+ const declarator = objectExpr . parent
593+ if (
594+ declarator . type !== AST_NODE_TYPES . VariableDeclarator ||
595+ declarator . id . type !== AST_NODE_TYPES . Identifier ||
596+ declarator . init !== objectExpr
597+ ) {
598+ return false
599+ }
600+
601+ return isStylingConstant ( declarator . id . name )
593602}
594603
595604// ============================================================================
0 commit comments