Skip to content

[feat] i18n: extend no-hardcoded-i18n-string to catch ternary + template patterns - #4014

Merged
nynexman4464 merged 1 commit into
mainfrom
nynexman4464/feat/i18n-lint-rule-ternary
Jul 17, 2026
Merged

nynexman4464 merged 1 commit into
mainfrom
nynexman4464/feat/i18n-lint-rule-ternary

Conversation

@nynexman4464

@nynexman4464 nynexman4464 commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #4013. Extends @astryx/no-hardcoded-i18n-string to catch string literals inside ternary, logical, and template-literal expressions:

aria-label={isOpen ? 'Close X' : 'Open X'}    // ConditionalExpression
aria-label={cond && 'Something'}               // LogicalExpression
aria-label={fallback ?? 'Default label'}       // LogicalExpression
aria-label={`Clear ${label}`}                  // TemplateLiteral

Same treatment for destructure defaults. Real-world integration testing (pseudo-locale swap on a consumer app) surfaced ~50 pre-existing violations the plain-literal walker missed; all migrated in #4013, which this PR stacks on.

The walker deliberately stops at CallExpression (t() is fine), MemberExpression, and function bodies — those are too likely to false-positive.

Testing

  • 0 violations under the extended rule
  • 4,614 core tests pass

Refs #3641, builds on #4013.

@vercel

vercel Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 17, 2026 9:43pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 15, 2026
@nynexman4464
nynexman4464 marked this pull request as ready for review July 15, 2026 22:29
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-more-strings branch from ee7dbfe to bdadf04 Compare July 15, 2026 22:51
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-lint-rule-ternary branch from 3761240 to 501efd4 Compare July 15, 2026 22:51
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-more-strings branch from bdadf04 to 995e996 Compare July 17, 2026 16:26
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-lint-rule-ternary branch from 501efd4 to cb95539 Compare July 17, 2026 16:26
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-more-strings branch from 995e996 to bdba214 Compare July 17, 2026 17:54
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-lint-rule-ternary branch from cb95539 to b7f5546 Compare July 17, 2026 17:55
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-more-strings branch from bdba214 to 5fd23ed Compare July 17, 2026 21:28
…late patterns

Walks into a JSX-expression container (or a destructure default) and
recursively reports string literals nested inside conditional, logical,
and template-literal expressions. Handles the two patterns that a
plain-literal check missed:

  aria-label={isOpen ? 'Close X' : 'Open X'}     // ConditionalExpression
  aria-label={cond && 'Something'}                // LogicalExpression
  aria-label={fallback ?? 'Default'}              // LogicalExpression
  aria-label={`Clear ${label}`}                 // TemplateLiteral

Deliberately does NOT walk into CallExpression (already handled — t()
calls are the correct form), MemberExpression, Identifier, arrow
function bodies, or JSX expressions — those are either fine or too
likely to false-positive.

Same behavior for the destructure-default case:

  function Foo({label = cond ? 'A' : 'B'}) { ... }
  function Foo({label = `Default ${x}`}) { ... }

Both are now flagged as `hardcodedDefault`.

Real-world integration testing (pseudo-locale swap on a consumer app)
was the forcing function. The pattern is common enough that a 24-file
migration was needed to green up the extension — landed separately in
#4013 which this PR stacks on.

Refs #3641, builds on #4013
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-lint-rule-ternary branch from b7f5546 to e4d8a62 Compare July 17, 2026 21:40
@nynexman4464
nynexman4464 changed the base branch from nynexman4464/feat/i18n-more-strings to main July 17, 2026 21:40
github-actions Bot added a commit that referenced this pull request Jul 17, 2026
@nynexman4464
nynexman4464 merged commit a8cde0f into main Jul 17, 2026
19 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@github-actions
github-actions Bot deleted the nynexman4464/feat/i18n-lint-rule-ternary branch July 18, 2026 06:42

This branch was successfully deployed

1 active deployment
Preview — e4d8a62b Deployed Jul 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants