WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.5k stars 4.2k forks source link

ESLint Plugin: Add I18N ESLint rules #19777

Closed swissspidy closed 1 year ago

swissspidy commented 4 years ago

Is your feature request related to a problem? Please describe.

Similar to the i18n sniffs in WPCS there could be some custom ESLint rules to catch some common i18n mistakes.

Describe the solution you'd like

Off the top of my head, there could be rules like follows:

Done

Likely to-do

On the fence

Actual implementation should be split up into multiple PRs.

Describe alternatives you've considered

Find other solutions out there that likely won't work with @wordpress/i18n or build something custom.

swissspidy commented 4 years ago

I have a working version of text domain validation ready, will push it soon.

Passing a variable to __() et al instead of a string literal

This is currently enforced using no-restricted-syntax:

https://github.com/WordPress/gutenberg/blob/4ea066829724caf7641af9a60bbbf5b38e2036b5/packages/eslint-plugin/configs/custom.js#L8-L28

Should be fairly easy to port this to its own proper rule.

swissspidy commented 4 years ago

Needs some way to detect whether text is passed as a prop or child that should probably be translatable

Some cases, off the top of my head:

Might even be fixable by wrapping the found strings in __()

gziolo commented 2 years ago

It looks like a lot of tasks listed are done. Excellent work! There is only one left on the list that was initially marked as “likely to do”. @swissspidy, what would be your current recommendation on criteria to consider this issue finished?

swissspidy commented 2 years ago

I was just thinking the pther day that a rule for catching trailing whitespace would be nice. See https://core.trac.wordpress.org/ticket/55669

This mistake wasn‘t caught in the Gutenberg code base.

gziolo commented 2 years ago

I was just thinking the pther day that a rule for catching trailing whitespace would be nice. See https://core.trac.wordpress.org/ticket/55669

This mistake wasn‘t caught in the Gutenberg code base.

I agree that it would be great to cover as much as possible from the cases that slipped through WP 6.0 Beta phase from the Gutenberg repository ❤️

swissspidy commented 2 years ago

Looks like #38225 introduced such a rule (i18n-no-flanking-whitespace)

Edit: this begs the question why it didn't catch dd7db32c1a3430046576b9c2da3f306d7cec06d2

swissspidy commented 2 years ago

Looks like the rule was only enabled for React Native code and not the whole code base 🙃

@jhnstn Do you recall why it wasn't considered to apply the i18n-no-flanking-whitespace rule for the rest of the code base? Seems like a missed opportunity.

gziolo commented 2 years ago

@jhnstn Do you recall why it wasn't considered to apply the i18n-no-flanking-whitespace rule for the rest of the code base? Seems like a missed opportunity.

It would be great to find out and potentially enable for the rest of Gutenberg 👍🏻