Eslint: adopt @wordpress/use-recommended-components#48487
Conversation
@wordpress/use-recommended-components
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
tbradsha
left a comment
There was a problem hiding this comment.
I haven't done a deep code review, but any reason we're not just cleaning these up directly? Looks like ~250 instances in the suppressions file, and I suspect many of them are the same or similar instances. Could one throw AI at it?
I'd at least recommend trying a cleanup of violations/merge into trunk before adding this.
Also, if I'm skimming correctly, it seems that once a file has suppressed errors of the given type, it won't prevent additional such errors from being added to a file.
My fear is that we'll end up with an additional layer of complexity that only serves to suppress issues we haven't properly fixed.
That's not trivial as these aren't mere code-formatting lints; code change would be simple'ish, but each component swap usually needs some design decisions and, of course, lots of testing that things continue working, which is a lot of work. There are four folks replacing old components right now with Note that Gutenberg is using an identical strategy to change their components. |
We definitely appreciate the cleanup/modernization efforts! I totally get this, having dealt with Phan cleanup (which uses baselines) and Stylelint (no baselines but rule-by-rule cleanup). We have the same goal, so let's see if we can align on implementation. :^) Some thoughts:
|
|
As an aside, it seems If it's noise/interfering with your current work, feel free to close it. 😄 I also notice you put up a similar PR targeting just Forms here: #48407 |
|
Feel free to open an issue in Gutenberg to discuss / agree on improvements to |
Added here: WordPress/gutenberg#78062 |
482b6b5 to
af67d45
Compare
ba3becb to
593d7a8
Compare
@wordpress/use-recommended-components@wordpress/use-recommended-components
6708e8b to
213df3c
Compare
|
@anomiex I've updated the PR to use the existing custom FYI, current failures in the lint job are known and described in the PR description. I'm still working on those aspects. Can you clarify a couple of developer experience nuances just so that I understand correctly how the custom Jetpack Eslint workflow works, vs the regular Eslint functionality:
|
eslint-changed analyzes the diff between the old and new versions to account for changed line numbers.
If the new lint violations are due to changes in the file itself, yes. If the new lint violations are due to changes in other files, no. For one thing, we only run eslint-changed on excluded files that are being changed in the PR. For another, eslint-changed lints the old and new versions of each file individually, but does not attempt to account for anything else in the repo changing (e.g. different versions of eslint plugins, changes to eslint config, or changes to other files).
If an excluded file becomes clean, the "Check linter exclude lists" job will flag that If a non-excluded file becomes "dirty", it'll fail the "ESLint (non-excluded files only)" check in CI. Whoever is working on the update PR will have to choose between fixing it or adding it to the exclude list. If an excluded file becomes cleaner (without becoming completely clean) or dirtier, CI will not report it. |
213df3c to
1e35df1
Compare
Likely best done after #48405 and #48404 land (which updates UI and Eslint libraries)
Proposed changes
Enables
@wordpress/use-recommended-componentsas anerror-level ESLint rule monorepo-wide (intools/js-tools/eslintrc/base.mjs). This encourages migration away from deprecated/experimental@wordpress/componentsexports toward stable@wordpress/uicomponents:@wordpress/ui— allowlist onlyOnly these imports are allowed. Anything else from
@wordpress/uiis discouraged (ESLint error):BadgeCardCard.Root, etc.)CollapsibleCollapsibleCardEmptyStateLinkStackTextVisuallyHiddenWe use a few more components in Jetpack as our own judgment call (
Button,Popover,Icon,Notice). Usages are now listed in thesuppressions.jsonlist in this PR, but I might wait with merging to have those stable (they're close).@wordpress/components— denylist onlyImports from
@wordpress/componentsare fine by default, except these discouraged names (each points to a@wordpress/uialternative):ExternalLinkLinkfrom@wordpress/uiwithopenInNewTab__experimentalHeadingText__experimentalHStackStack__experimentalTextText__experimentalVStackStack__experimentalZStackCardCard.RootCardBodyCard.ContentCardDividerCardFooterCardHeaderCard.Header/Card.TitleCardMediaCard.FullBleedVisuallyHiddenVisuallyHiddenfrom@wordpress/uiAll other
@wordpress/componentsimports (Button,Modal,Popover,Panel, …) are not flagged by this rule yet, but future updates will include those, too.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Verify the rule is active:
ExternalLinkfrom@wordpress/components— ESLint should report an error: "UseLinkfrom@wordpress/uiwith theopenInNewTabprop instead."tools/eslint/suppressions.json(e.g.projects/js-packages/components/components/admin-page/index.tsx) — the existing violation should be silently suppressed andpnpm run lint-file <file>should exit 0.