feat(react): add rule to enforce translator comment in sr-only contexts - #5
Open
vraja-pro wants to merge 1 commit into
Open
feat(react): add rule to enforce translator comment in sr-only contexts#5vraja-pro wants to merge 1 commit into
vraja-pro wants to merge 1 commit into
Conversation
vraja-pro
force-pushed
the
add-sr-only-translator-comment-rule
branch
from
August 28, 2026 12:22
9a4751e to
9a00536
Compare
Adds yoast/require-sr-only-translator-comment to reactConfig. The rule requires /* translators: Hidden accessibility text. */ before i18n calls (__(), _x(), _n(), _nx(), or sprintf wrapping one of these) inside: - JSX elements with className containing "yst-sr-only" - aria-label JSX attributes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
vraja-pro
force-pushed
the
add-sr-only-translator-comment-rule
branch
from
August 28, 2026 12:23
9a00536 to
dcf0a51
Compare
vraja-pro
added a commit
to Yoast/wordpress-seo
that referenced
this pull request
Aug 28, 2026
The rule is pending in Yoast/eslint-config#5. Until that PR is merged and the package version bumped, the rule is inlined here so CI enforces it. Remove this once @yoast/eslint-config ships the rule in reactConfig. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new ESLint rule
yoast/require-sr-only-translator-commenttoreactConfig. The rule enforces that every i18n call whose output is only visible to screen readers has a/* translators: Hidden accessibility text. */comment directly above it, so translators understand the string has no visual context.What the rule checks
The rule fires on:
__(),_x(),_n(),_nx(), or any of these wrapped insprintf()inside a JSX element whoseclassNamecontains"yst-sr-only"aria-labelJSX attributeIt recognises the comment whether it appears before the attribute, before the
JSXExpressionContainer, or directly above the i18n call inside the braces — covering all common placement patterns.Technical notes
jsdoc/require-jsdocconfig (which exemptsArrowFunctionExpression).rules/is added to thefilesfield inpackage.jsonso the rule file is included when the package is published.Testing
wordpress-seo/node_modules/@yoast/eslint-configremove all content except thenode_modulesfolder.wordpress-seo/node_modules/@yoast/eslint-configpackages/jsand runyarn lint🤖 Generated with Claude Code