Skip to content

fix: match only Literal, TemplateLiteral#105

Closed
lee-donghyun wants to merge 1 commit intolingui:mainfrom
lee-donghyun:main
Closed

fix: match only Literal, TemplateLiteral#105
lee-donghyun wants to merge 1 commit intolingui:mainfrom
lee-donghyun:main

Conversation

@lee-donghyun
Copy link

Summary

This PR fixes a bug where hardcoded strings within JSX attributes were not consistently detected by the plugin. In particular, string literals inside event handlers (e.g., onClick={() => alert("unlocalized string")}) were being skipped unintentionally.

What’s Fixed

I updated the selector:

'JSXAttribute > :matches(Literal, TemplateLiteral)'

This ensures that only direct children of JSXAttribute are matched — such as aria-hidden="true" — and not literals nested inside expressions.

Before

<button onClick={() => alert('not linted')}>
  ...
</button>

The string "not linted" was not reported. This is because the JSXAttribute node (onClick) was associated with a native DOM element (<button>) and skipped via helper.ts, after being added to the visited map. Thus, its subtree was not evaluated.

After

<button onClick={() => alert('linted')}>
  ...
</button>

The string "linted" is now reported correctly. Since the literal is not a direct child of a JSXAttribute, it is instead evaluated during the Literal:exit or TemplateLiteral:exit phase — ensuring the plugin inspects it properly.

Why It Matters

This change separates static attribute values from expressions and ensures hardcoded strings inside expressions are evaluated in the correct traversal phase, fixing false negatives without introducing false positives.

@lee-donghyun lee-donghyun changed the title Fix false negatives for JSX attribute values by updating selector to match only direct Literals fix: match only Literal, TemplateLiteral May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant