Repository navigation
lint: flag hardcoded strings passed to announce() - #4387
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
humbertovirtudes
left a comment
There was a problem hiding this comment.
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 runon the new suite: 18/18 pass.ASTRYX_STRICT_LINT=1 eslint packages/core/src: exit 0 with the allowlist.- Emptied
allowedCalleeStringsand 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 existinglooksUserFacing()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. allowedCalleeStringsis 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.
f1d7d0c to
b027f69
Compare
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-stringdid 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 newhardcodedCallArgmessage:callees, default['announce']— the live-region announcer returned byuseAnnounce()).looksUserFacing()heuristics (soannounce('')clears and identifier-shaped strings stay allowed).t(...)results, variables, and templates with interpolations are allowed..doc.mjs).allowedCalleeStrings: string[]— exact-match, file/line-agnostic exemptions for grandfathered sites.eslint.config.js— passes options to the rule in the existingpackages/core/srcscope at the existing two-tier severity (errorin strict/CI,warnlocally), with a temporary allowlist for the three string-literal sites that exist at HEAD:'Copied'(CodeBlock),'Selection cleared'and'All selected'(MultiSelector)t(...)in the scan Add animation system exploration doc #3 i18n sweep PRs. Follow-up: remove each entry as its fix merges, then deleteallowedCalleeStringsentirely — 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-pluginis private and rooteslint.config.jsis 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: flagsannounce('Copied')and expression-free templates; allowsannounce(t('key')),announce(variable), templates with expressions, empty string, non-configured callees, member calls; allowlist exact-match behavior; customcalleesoption; 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).ASTRYX_STRICT_LINT=1 eslint eslint.config.js— clean.prettier --checkpasses on the new test file; the two edited.jsfiles 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
announce(...)) with no import/scope tracing. Any local function namedannounceis 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.announce(`Added ${label}`)) are intentionally NOT flagged by this conservative check to avoid false positives; those sites are handled directly by the i18n sweep.