-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESLint: Add rule to prevent usage of the word 'sidebar' in translatable strings #68894
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Hi @swissspidy, When you have a moment, could you please review my PR. cc: @afercia |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall 👍
The lint checks are failing, but the ones related to this PR possibly include... I'll put together a comprehensive set of suggestions so we can move forward. Edit: I see some false positives being raised, especially in URLs, such as Lines 45 to 56 in be0f32a
gutenberg/packages/edit-site/src/components/welcome-guide/page.js Lines 53 to 64 in be0f32a
gutenberg/packages/editor/src/components/page-attributes/parent.js Lines 279 to 294 in be0f32a
gutenberg/packages/editor/src/components/post-excerpt/index.js Lines 78 to 90 in be0f32a
gutenberg/packages/editor/src/components/post-template/create-new-template-modal.js Lines 120 to 131 in be0f32a
gutenberg/packages/editor/src/components/post-url/index.js Lines 90 to 106 in be0f32a
gutenberg/packages/editor/src/components/preferences-modal/index.js Lines 87 to 94 in be0f32a
gutenberg/packages/editor/src/components/sidebar/header.js Lines 19 to 27 in be0f32a
gutenberg/packages/editor/src/components/sidebar/index.js Lines 104 to 107 in be0f32a
gutenberg/packages/fields/src/fields/parent/parent-edit.tsx Lines 323 to 337 in be0f32a
|
Hi @afercia , @swissspidy , @tyxla , I’d appreciate your input once again in suggesting alternative strings for the following: For now, I have replaced "sidebar" with "panel," but if you have any alternative suggestions for any of these, I’d be happy to update them.
Additionally, we have URLs inside translation functions( 4 instances ), such as: __('https://wordpress.org/documentation/article/page-post-settings-sidebar/#page-attributes') We could add an ESLint ignore here, but I don’t think that’s the best solution. A better approach would be to update the regex. The previous regex worked well, but it caused false positives for URLs because \b only checks for alphanumeric characters, and a hyphen (-) is not considered alphanumeric. This led to unintended matches. I have updated the regex to ensure that "sidebar" is only flagged when it is a standalone word and not part of another word (e.g., "no-sidebar"). Updated regex: {
selector:
'CallExpression[callee.name=/^(__|_x|_n|_nx)$/] > Literal[value=/(?<![-\\w])sidebar(?![-\\w])/i]',
message:
"Avoid using the word 'sidebar' in translatable strings. Consider using 'panel' instead.",
} I have updated the PR with this new regex. Let me know your thoughts! @swissspidy |
New regex looks good at first glance, seems to nicely prevent false positives. I don't think we should change the instances where Curious what others say though. |
I'd agree with @swissspidy that the only occurrences to change should be the ones in the editor UI. |
Then I'd say for the other instances let's ignore the eslint errors & add an explanatory comment why it's disabled |
Hi @afercia and @swissspidy, Hopefully, it can be merged into trunk soon. Thanks! |
packages/editor/src/components/post-template/create-new-template-modal.js
Outdated
Show resolved
Hide resolved
Hi @afercia and @swissspidy, |
Related comment: #61499 (comment)
What?
This PR introduces a new ESLint rule to prevent the use of the term "sidebar" in user-facing strings throughout the codebase. The rule aims to ensure that more generic and accessible terms like "panel" are used in place of "sidebar."
Why?
The term "sidebar" is problematic for blind and low-vision users, as it relies on spatial concepts that are irrelevant to them. Additionally, the term can be misleading on smaller screens where "sidebars" are often full-width overlays. This change is necessary to align with the accessibility guidelines. It ensures consistency in user-facing language across WordPress projects.
How?
The PR implements an ESLint rule that flags occurrences of the word "sidebar" in translatable strings, helping developers avoid its usage in user-facing content. The rule is added to the .eslintrc.js configuration to prevent new instances of this term from being introduced.
Testing Instructions
Screencast
Screen.Recording.2025-01-27.at.4.03.49.PM.mov