Skip to content

lint: flag hardcoded strings passed to announce() - #4387

Merged
cixzhang merged 1 commit into
meta:mainfrom
bhamodi:lint/announce-i18n
Jul 30, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
bhamodi:lint/announce-i18n

Conversation

@bhamodi

@bhamodi bhamodi commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Evergreen a11y/i18n scan #3 found 8 hardcoded-English strings reaching users through announce() live-region calls and aria-labels that @astryx/no-hardcoded-i18n-string did not catch: the rule covered JSX attributes, object properties, and destructure defaults, but not call arguments. The individual sites are being fixed in parallel sweep PRs; this PR closes the class so it cannot be reintroduced.

Changes

  • internal/eslint-plugin-astryx/no-hardcoded-i18n-string.js — new call-argument surface with a new hardcodedCallArg message:
    • Flags the first argument of calls to configured callees (option callees, default ['announce'] — the live-region announcer returned by useAnnounce()).
    • Only plain string literals and expression-free template literals are flagged, and only when they pass the existing looksUserFacing() heuristics (so announce('') clears and identifier-shaped strings stay allowed). t(...) results, variables, and templates with interpolations are allowed.
    • Same file ignores as the rest of the rule (tests, stories, .doc.mjs).
    • New option allowedCalleeStrings: string[] — exact-match, file/line-agnostic exemptions for grandfathered sites.
  • eslint.config.js — passes options to the rule in the existing packages/core/src scope at the existing two-tier severity (error in strict/CI, warn locally), with a temporary allowlist for the three string-literal sites that exist at HEAD:
    • 'Copied' (CodeBlock), 'Selection cleared' and 'All selected' (MultiSelector)
    • These are being replaced with t(...) in the scan Add animation system exploration doc #3 i18n sweep PRs. Follow-up: remove each entry as its fix merges, then delete allowedCalleeStrings entirely — the allowlist is self-cleaning and should reach zero.
  • internal/eslint-plugin-astryx/no-hardcoded-i18n-string.test.mjs — new RuleTester suite (the rule previously had no tests).

No changeset: internal lint tooling only (@astryx/eslint-plugin is private and root eslint.config.js is not a published package), so no published package version changes.

Test plan

  • vitest run internal/eslint-plugin-astryx/no-hardcoded-i18n-string.test.mjs — 18/18 pass. Cases include: flags announce('Copied') and expression-free templates; allows announce(t('key')), announce(variable), templates with expressions, empty string, non-configured callees, member calls; allowlist exact-match behavior; custom callees option; test/story filename ignores; existing JSX-attribute surface still behaves.
  • ASTRYX_STRICT_LINT=1 eslint packages/core/src — exit 0 on this branch (allowlist working).
  • With the allowlist temporarily emptied, strict eslint reports exactly the 3 known sites (CodeBlock.tsx:762, MultiSelector.tsx:701, MultiSelector.tsx:703) and nothing else — no false positives across core.
  • ASTRYX_STRICT_LINT=1 eslint eslint.config.js — clean.
  • prettier --check passes on the new test file; the two edited .js files were already not prettier-clean at HEAD (repo only enforces prettier on ts/tsx/md), so they were left in their existing style rather than mass-reformatted.

Notes

  • Callee-name matching limitation: the rule matches calls by identifier name only (announce(...)) with no import/scope tracing. Any local function named announce is checked; a renamed destructure (const {announce: say} = useAnnounce()) escapes it. This is a deliberate simplicity tradeoff documented in the rule header — the codebase consistently uses the conventional name.
  • Interpolated announcements (e.g. announce(`Added ${label}`)) are intentionally NOT flagged by this conservative check to avoid false positives; those sites are handled directly by the i18n sweep.
  • Vercel fork-PR deployment failure is known infra and unrelated.

@vercel

vercel Bot commented Jul 26, 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 Jul 30, 2026 8:01am

Request Review

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 26, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 26, 2026
@github-actions

github-actions Bot commented Jul 26, 2026 •

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

@humbertovirtudes humbertovirtudes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice close on this. The rule already covered JSX attributes, object properties, and destructure defaults, but call arguments were the obvious gap and announce() is exactly the right sink to guard. Extending the existing rule rather than adding a parallel one keeps the surface small, and adding the first RuleTester suite for a rule that had none is a real improvement.

Triage: internal lint tooling, non-breaking, low blast radius -> fast path.

Verified locally on this branch:

  • vitest run on the new suite: 18/18 pass.
  • ASTRYX_STRICT_LINT=1 eslint packages/core/src: exit 0 with the allowlist.
  • Emptied allowedCalleeStrings and re-ran strict lint: exactly 3 problems, and exactly the three grandfathered sites (CodeBlock.tsx:762 'Copied', MultiSelector.tsx:701 'Selection cleared', :703 'All selected'), zero false positives across core. The central claim holds.
  • Confirmed all three allowlisted strings map to real announce(...) calls at those exact lines.

What I like:

  • The conservative definition of "hardcoded" (plain string literals + expression-free templates only) is the right call: announce(t(...)), variables, and interpolated templates all stay allowed, so the interpolation class is left to the i18n sweep instead of generating false positives here.
  • Empty-string clearing (announce('')) and identifier-shaped strings stay allowed via the existing looksUserFacing() reuse.
  • The callee-name-only matching limitation and the self-cleaning allowlist are both documented in the rule header and the config comment, so the follow-up path (drop each entry as its sweep PR merges, then delete allowedCalleeStrings) is clear.

Non-blocking nits (fine to land as-is):

  • The allowlist is file/line-agnostic exact-match, so once a real announce('Copied') is localized, any other future 'Copied' would still be silently exempted until the entry is removed. Given the self-cleaning follow-up plan and the small window, that is an acceptable tradeoff, not a change request.
  • allowedCalleeStrings is global rather than per-callee. Not needed for the current single-callee setup; worth revisiting only if a second callee is ever configured with colliding strings.

No changeset is correct here: @astryx/eslint-plugin is private and root eslint.config.js is not a published package, so no consumer-visible version change.


PR #4387 - lint: flag hardcoded strings passed to announce()
Author: @bhamodi
What it does: extends @astryx/no-hardcoded-i18n-string to flag hardcoded user-facing strings passed as the first argument to announce(), closing the call-argument gap; adds the rule's first test suite and a temporary self-cleaning allowlist for three known sites.
Recommendation: Approve.

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Jul 29, 2026
@cixzhang
cixzhang merged commit 72c0956 into meta:main Jul 30, 2026
20 checks passed
@github-actions
github-actions Bot deleted the lint/announce-i18n branch July 31, 2026 08:38

This branch was successfully deployed

1 active deployment
Preview — b027f691 Deployed Jul 30, 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. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants