Skip to content
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 regex for valid-sprintf rule to handle '%%' #68270

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

im3dabasia
Copy link
Contributor

Fixes: #52787

What?

Updated the regex in the valid-sprintf ESLint rule to correctly handle escaped percent signs (%%). Added 4 new test cases that cover various scenarios involving %%.

Why?

The current regex fails to handle cases like sprintf('Rotated at %d %% degrees', 90) by mistakenly flagging valid format strings with escaped percent signs as incorrect. This update ensures proper handling of %d %% and similar cases.

Screenshots or screencast

Screenshot 2024-12-24 at 5 24 38 PM

Copy link

github-actions bot commented Dec 24, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: im3dabasia <[email protected]>
Co-authored-by: swissspidy <[email protected]>
Co-authored-by: colorful-tones <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. Internationalization (i18n) Issues or PRs related to internationalization efforts [Tool] ESLint plugin /packages/eslint-plugin labels Dec 24, 2024
@Mamaduka Mamaduka requested a review from swissspidy December 24, 2024 12:18
Copy link
Member

@swissspidy swissspidy left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

@im3dabasia
Copy link
Contributor Author

Hi @swissspidy ,

I wanted to check if this change is likely to be merged in the upcoming release or if it might take a bit longer.

@swissspidy swissspidy merged commit e746a95 into WordPress:trunk Jan 9, 2025
70 of 74 checks passed
@github-actions github-actions bot added this to the Gutenberg 20.1 milestone Jan 9, 2025
@t-hamano
Copy link
Contributor

t-hamano commented Jan 9, 2025

Thanks for solving this issue! With the improved ESLint rules, the issues mentioned here may also be addressed:

Ideally, the string could be simplified to %d%%. Unfortunately, ESLint currently considers this an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internationalization (i18n) Issues or PRs related to internationalization efforts [Tool] ESLint plugin /packages/eslint-plugin [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESLint: Improve regex for valid-sprintf rule
4 participants