-
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: Improve lint regex for preventing "toggle" word usage in translation ready functions #68958
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 after I shared my observation in this comment |
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.
"Toggle" in the beginning of a string was most likely imperative, where we can easily say it was used as a verb.
That won't be the case for mid-sentence use, though. And what's wrong with "toggle" as a noun?
We can't know whether it's used as a noun or verb. If there's a legitimate use then the rule can be disabled in that specific location. |
I see, and that's my point: if a rule can often be a false alarm, then it may harm more than it helps, and it's debatable whether it makes sense to have in the first place. However, I don't have strong feelings either way. |
The keyword here is often. Usage of the word "toggle" is very rare, and it's rarely used as a noun. This PR here flags a few new places, all of which are correct because the word is used as a verb: gutenberg/packages/components/src/mobile/bottom-sheet/switch-cell.native.js Lines 59 to 60 in e850c68
gutenberg/packages/components/src/mobile/bottom-sheet/switch-cell.native.js Lines 59 to 60 in e850c68
No false positives. If we can fix these instances in this PR then this is good to go IMO. |
@tyxla and @swissspidy , What would you suggest as the best replacement for these strings? I'd appreciate your guidance and advice.
|
^ Also @afercia |
My personal votes:
|
Related Comment: #67741 (comment)
Related issue: #66372
What?
As described in the above comment, after the new rule had been added to prevent the usage of the word "toggle" in the repositiory. The solution merged previoulsy could be optimised better by improving the regex.
Why?
Previously the word toggle was only detected/flaagged incase if it were the first word in the string ie __("toggle is the first word") but if "toggle" was used in the middle or at the end it would not be flagged.
How?
Updated the regex of the eslint rule to further improve the warning. and prevent usage of the word toggle.
The new regex:
Literal[value=/toggle\\b/i]
Screencast
Before
Screen.Recording.2025-01-29.at.11.18.42.PM.mov
After
Screen.Recording.2025-01-29.at.11.26.02.PM.mov