-
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: Enable react/jsx-boolean-value
for the Gutenberg codebase and fix
#59557
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. |
Size Change: 0 B Total Size: 1.71 MB ℹ️ View Unchanged
|
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.
One thing that strikes me is the very varied naming of boolean properties across the codebase. It would be good to not just resolve the issue at hand, but also think about how the props are used. That's rather subjective though, and outside the scope of this PR!
As I'm rather unopinionated on the usage JSX boolean values, I may not be best placed to approve, but from a purely technical perspective, this is fine!
I'm probably a little more opinionated on true
defaults, thinking about it, and if we're going to enforce no ...={ true }
, it would be nice to avoid ...={ false }
as well. Ideally the prop name reflects what it does, and we should be able to tell a truly binary value from the presence of the prop alone.
For example, what is the default behaviour here? If I don't set disableCustomColors
, are custom colours disabled or not? Would enableCustomColors
be a better prop name, if the default behaviour is to disable them?
<ColorGradientControl
...
- disableCustomColors={ false }
+ enableCustomColors
...
/>
Interesting observation, and thanks for taking a look! This rather large PR can get obsolete quickly, so I appreciate being able to land it quickly. Just to clarify, this PR isn't about "if we force And with that in mind, there will always be boolean props that make sense to have a Last, but not least, while there might be places where a |
FWIW, I unintentionally misclicked the merge button as I intended to add the "Co-authored by" section - sorry about that. |
* Refactor global styles and refactor existing background components * Porting over existing hook code to shared, global styles component. * Move tests, move styles, remove duplicate code from block support hook * Pull over changes to background.js from #59557 * Add default control values for block supports. The default backgroundSize value for block backgrounds is 'cover' * Resetting position if it's center and size is not contain. * Add background-image to INDIRECT_PROPERTIES_METADATA because the value is "indirectly" stored in an array, at least determined by multiple values in an array. --------- Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org> Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
* Refactor global styles and refactor existing background components * Porting over existing hook code to shared, global styles component. * Move tests, move styles, remove duplicate code from block support hook * Pull over changes to background.js from WordPress#59557 * Add default control values for block supports. The default backgroundSize value for block backgrounds is 'cover' * Resetting position if it's center and size is not contain. * Add background-image to INDIRECT_PROPERTIES_METADATA because the value is "indirectly" stored in an array, at least determined by multiple values in an array. --------- Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org> Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
* Refactor global styles and refactor existing background components * Porting over existing hook code to shared, global styles component. * Move tests, move styles, remove duplicate code from block support hook * Pull over changes to background.js from WordPress#59557 * Add default control values for block supports. The default backgroundSize value for block backgrounds is 'cover' * Resetting position if it's center and size is not contain. * Add background-image to INDIRECT_PROPERTIES_METADATA because the value is "indirectly" stored in an array, at least determined by multiple values in an array. --------- Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org> Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
What?
This PR enables the
react/jsx-boolean-value
ESLint rule for the Gutenberg codebase. It also fixes all violations of the rule across the codebase.Why?
Using the truthy shorthand is a recommendation I often encounter in PR reviews, and if we enforce it with ESLint, it will no longer be an issue.
By using the shorthand we also keep the code more concise and short.
How?
We're enabling the rule for the codebase. I'm intentionally not enabling it in the
@wordpress/eslint-plugin
package because it's a bit opinionated and I'm not convinced we want to apply this beyond the Gutenberg codebase. I'm happy to be convinced otherwise.Testing Instructions
All checks should be green.
Testing Instructions for Keyboard
None
Screenshots or screencast
None