-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Lint: Add rule to prohibit @wordpress/* unstable and experimental features #47712
Conversation
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
packages/eslint-plugin-wpcalypso/lib/rules/test/wp-no-unsafe-features.js
Outdated
Show resolved
Hide resolved
@@ -26,5 +26,8 @@ | |||
}, | |||
"devDependencies": { | |||
"babel-eslint": "^10.1.0" | |||
}, | |||
"scripts": { | |||
"test": "jest" |
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.
Shouldn't this be tested as part of yarn test-packages
in the root? Why do we need our own jest
call?
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.
I moved into the package and did yarn test
. I expected that to work and was surprised when it didn't. With this change it does work, but if that's in violation of the repo setup I'm happy to drop the change.
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.
I think having a test
command here may be a bit confusing:
- Technically we don't run this command on CI, so it can break at anytime and go unnoticed. In CI we only do
yarn test-packages
in the root. - With the current setup, the way to run tests for a single package is
yarn test-packages packages/eslint-plugin-wpcalypso
. Doingcd packages/eslint-plugin-wpcalypso && yarn jest
also works, but that's a trick
I changed the 'Code style' build to lint all files and not only the files changed in this PR. This should show existing violations of this rule (if any) |
Thanks for the review @scinos 👍
Fixing these is on the short list, especially considering they caused a production issue recently. Teams use these features because they needed them and the features are fine as long as the Gutenberg version we're using doesn't change. We have control over the Gutenberg version, so what we want to do is make sure we have tests on the features so they don't break without notice. For most (all?) of the features, we can probably add a test and configure the rule: wp-calypso/test/e2e/specs/wp-gutenberg-experimental-features-spec.js Lines 21 to 30 in d278aee
https://github.com/Automattic/wp-calypso/blob/b311e2bb1f08bf82fe36f145ac9272863b4bc14e/.eslintrc.js#L392-L395 I'll see what that looks like, if it's really that simple we can do it here. Otherwise I'd prefer to get the responsible teams to handle each case. |
'wpcalypso/jsx-gridicon-size': 'error', | ||
'wpcalypso/jsx-classname-namespace': 'error', | ||
'wpcalypso/redux-no-bound-selectors': 'error', | ||
'wpcalypso/wp-no-unsafe-features': 'error', |
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.
This line adds the new rule. The rest just rewrite from confusing numbers to clear strings.
Great work here 💯! I've tried it out today and have a few questions: 1) Running
Am I missing something? 2) Should we also detect when unstable members are used, like this? |
packages/eslint-plugin-wpcalypso/docs/rules/wp-no-unsafe-features.md
Outdated
Show resolved
Hide resolved
e90d65b
to
e97061e
Compare
Proposing for Gutenberg: WordPress/gutenberg#27301 |
0 -> "off" 1 -> "warn" 2 -> "error"
Based on improvements in WordPress/gutenberg#27301
e97061e
to
1cab570
Compare
@@ -23,10 +23,21 @@ const gutenbergUser = | |||
// of the @wordpress/* packages. The purpose of these tests is to give us an early | |||
// warning if an experimental feature has been removed or renamed. | |||
const EXPERIMENTAL_FEATURES = { |
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.
It's unclear whether and when this is actually run. I can see the spec file in CircleCI logs, but I don't see the describe actually appear like it isn't being run. We may need to tag this describe somehow, e.g. @parallel
and/or whatever tag runs on Gutenberg edge tests.
@fullofcaffeine can own that bit? I'd expect this to run as part of the full suite and the Gutenberg edge suites. We can handle that in a separate PR (which could include the changes to this file).
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.
@fullofcaffeine can own that bit?
Sure! Tracked it here. Will get to it as soon as I can.
packages/eslint-plugin-wpcalypso/docs/rules/no-unsafe-wp-apis.md
Outdated
Show resolved
Hide resolved
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
/* eslint-disable wpcalypso/no-unsafe-wp-apis */ |
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.
This seems like encouraging folks to disable the rule right in the docs. That seems like the wrong message. Can we ignore the lint error or add an .eslintrc override?
@@ -7,7 +7,7 @@ Three dots for indicating an ellipsis should be replaced with the UTF-8 characte | |||
The following patterns are considered warnings: | |||
|
|||
```js | |||
translate( 'Loading…' ); | |||
translate( 'Loading...' ); |
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.
Thanks for fixing this :)
The Gutenberg edge failures are expected and the woo test failure is happening on all PRs. I'll merge. |
Changes proposed in this Pull Request
Introduce a new lint rule. It bans
__experimental
- and__unstable
-prefixed imported names from@wordpress/*
packages.Experimental features caused problem recently (p58i-9K9-p2).
__unstable
cannot be configured__experimental
can be configured by providing a configuration object:{ "@wordpress/foo": [ "__experimentalBar" ] }
allows the__experimentalBar
import from@wordpress/foo
package, e.g.import { __experimentalBar } from '@wordpress/foo';
.Adds this to the default wpcalypso rule set. Disable the rule for the only experimental feature we have e2e tests for.
Of course, the rule can always be disabled at the eslint level case-by-case.
Results
Testing instructions
npx eslint-nibble --rule wpcalypso/wp-no-unsafe-features apps/editing-toolkit
npx eslint-nibble --rule wpcalypso/wp-no-unsafe-features apps client packages
Closes #47551