From 3c616fc95445a976fe6239894040623392128689 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Tue, 13 Aug 2019 18:31:19 +0200 Subject: [PATCH 1/5] Babel Preset Default: Add missing @wordpress/element dependency --- package-lock.json | 1 + packages/babel-preset-default/CHANGELOG.md | 6 ++++++ packages/babel-preset-default/package.json | 4 +--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index db4ab1e5b5f252..9514962f782bd1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4593,6 +4593,7 @@ "@babel/runtime": "^7.4.4", "@wordpress/babel-plugin-import-jsx-pragma": "file:packages/babel-plugin-import-jsx-pragma", "@wordpress/browserslist-config": "file:packages/browserslist-config", + "@wordpress/element": "file:packages/element", "core-js": "^3.1.4" } }, diff --git a/packages/babel-preset-default/CHANGELOG.md b/packages/babel-preset-default/CHANGELOG.md index e84e32066de1ea..ec6cc518320381 100644 --- a/packages/babel-preset-default/CHANGELOG.md +++ b/packages/babel-preset-default/CHANGELOG.md @@ -1,3 +1,9 @@ +## Master + +### Bug Fixes + +- Added missing `@wordpress/element` dependency which is used internally. + ## 4.4.0 (2019-08-05) ### Bug Fixes diff --git a/packages/babel-preset-default/package.json b/packages/babel-preset-default/package.json index a6e298d055ac07..61638438487387 100644 --- a/packages/babel-preset-default/package.json +++ b/packages/babel-preset-default/package.json @@ -36,11 +36,9 @@ "@babel/runtime": "^7.4.4", "@wordpress/babel-plugin-import-jsx-pragma": "file:../babel-plugin-import-jsx-pragma", "@wordpress/browserslist-config": "file:../browserslist-config", + "@wordpress/element": "file:../element", "core-js": "^3.1.4" }, - "peerDependencies": { - "@babel/core": "^7.0.0" - }, "publishConfig": { "access": "public" } From 35b412fb01f597450a2d1a8d53d0ecf40efeb65c Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Tue, 13 Aug 2019 18:38:48 +0200 Subject: [PATCH 2/5] Remove `@wordpress/dependency-group` and `@wordpress/gutenberg-phase` rules from the `custom` and `recommended` configs and leave them as opt-in features. --- .eslintrc.js | 2 ++ packages/eslint-plugin/CHANGELOG.md | 4 ++++ packages/eslint-plugin/configs/custom.js | 2 -- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 363cd259c838bf..f145372a655cd5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -30,6 +30,8 @@ module.exports = { wp: 'off', }, rules: { + '@wordpress/dependency-group': 'error', + '@wordpress/gutenberg-phase': 'error', '@wordpress/react-no-unsafe-timeout': 'error', 'no-restricted-syntax': [ 'error', diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index b40d7e8bb8ff4e..5b7636b9d36d83 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/CHANGELOG.md @@ -10,6 +10,10 @@ - New Rule: [`@wordpress/no-unguarded-get-range-at`](https://github.com/WordPress/gutenberg/blob/master/packages/eslint-plugin/docs/rules/no-unguarded-get-range-at.md) - Enable `wp` global by default in the `recommended` config. +### Enhancements + +- Remove `@wordpress/dependency-group` and `@wordpress/gutenberg-phase` rules from the `custom` and `recommended` configs and leave them as opt-in features. + ## 2.4.0 (2019-08-05) ### New Features diff --git a/packages/eslint-plugin/configs/custom.js b/packages/eslint-plugin/configs/custom.js index efb873980b22f4..69ca991b7e56bb 100644 --- a/packages/eslint-plugin/configs/custom.js +++ b/packages/eslint-plugin/configs/custom.js @@ -3,8 +3,6 @@ module.exports = { '@wordpress', ], rules: { - '@wordpress/dependency-group': 'error', - '@wordpress/gutenberg-phase': 'error', '@wordpress/no-unused-vars-before-return': 'error', '@wordpress/valid-sprintf': 'error', '@wordpress/no-base-control-with-label-without-id': 'error', From 7e186e4b55d5b65d5508f6d1629c13915be43ef2 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Tue, 13 Aug 2019 20:11:36 +0200 Subject: [PATCH 3/5] ESLint Plugin: Extract 2 test configs and add them conditionally to the recommended one --- .eslintrc.js | 21 +++++++++------- package-lock.json | 7 +++--- package.json | 1 - packages/eslint-plugin/configs/recommended.js | 24 +++++++++++++++++-- packages/eslint-plugin/configs/test-e2e.js | 13 ++++++++++ packages/eslint-plugin/configs/test-unit.js | 5 ++++ packages/eslint-plugin/package.json | 1 + packages/is-shallow-equal/.eslintrc.json | 14 +++++++++-- .../is-shallow-equal/benchmark/.eslintrc.json | 4 ---- packages/is-shallow-equal/test/.eslintrc.json | 4 ---- 10 files changed, 69 insertions(+), 25 deletions(-) create mode 100644 packages/eslint-plugin/configs/test-e2e.js create mode 100644 packages/eslint-plugin/configs/test-unit.js delete mode 100644 packages/is-shallow-equal/benchmark/.eslintrc.json delete mode 100644 packages/is-shallow-equal/test/.eslintrc.json diff --git a/.eslintrc.js b/.eslintrc.js index f145372a655cd5..16eccf6f1c73e9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -20,7 +20,6 @@ module.exports = { root: true, extends: [ 'plugin:@wordpress/eslint-plugin/recommended', - 'plugin:jest/recommended', 'plugin:eslint-comments/recommended', ], plugins: [ @@ -125,16 +124,20 @@ module.exports = { '**/@(benchmark|test|__tests__)/**/*.js', ], }, + { + files: [ + 'packages/block-serialization-spec-parser/shared-tests.js', + 'packages/jest*/**/*.js', + ], + extends: [ + 'plugin:@wordpress/eslint-plugin/test-unit', + ], + }, { files: [ 'packages/e2e-test*/**/*.js' ], - env: { - browser: true, - }, - globals: { - browser: 'readonly', - page: 'readonly', - wp: 'readonly', - }, + extends: [ + 'plugin:@wordpress/eslint-plugin/test-e2e', + ], }, ], }; diff --git a/package-lock.json b/package-lock.json index 9514962f782bd1..b1809c91e94140 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4983,6 +4983,7 @@ "dev": true, "requires": { "babel-eslint": "^10.0.2", + "eslint-plugin-jest": "^22.15.1", "eslint-plugin-jsdoc": "^15.8.0", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", @@ -11058,9 +11059,9 @@ } }, "eslint-plugin-jest": { - "version": "22.14.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-22.14.1.tgz", - "integrity": "sha512-mpLjhADl+HjagrlaGNx95HIji089S18DhnU/Ee8P8VP+dhEnuEzb43BXEaRmDgQ7BiSUPcSCvt1ydtgPkjOF/Q==", + "version": "22.15.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-22.15.1.tgz", + "integrity": "sha512-CWq/RR/3tLaKFB+FZcCJwU9hH5q/bKeO3rFP8G07+q7hcDCFNqpvdphVbEbGE6o6qo1UbciEev4ejUWv7brUhw==", "dev": true, "requires": { "@typescript-eslint/experimental-utils": "^1.13.0" diff --git a/package.json b/package.json index 46ebf924d604a2..49d35dc9f1a907 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,6 @@ "enzyme": "3.9.0", "eslint-plugin-eslint-comments": "3.1.2", "eslint-plugin-import": "2.18.2", - "eslint-plugin-jest": "22.14.1", "fast-glob": "2.2.7", "fbjs": "0.8.17", "fs-extra": "8.0.1", diff --git a/packages/eslint-plugin/configs/recommended.js b/packages/eslint-plugin/configs/recommended.js index 5aaead8880681a..6f3c53c60f188a 100644 --- a/packages/eslint-plugin/configs/recommended.js +++ b/packages/eslint-plugin/configs/recommended.js @@ -10,8 +10,28 @@ module.exports = { node: true, }, globals: { - window: true, - document: true, + window: 'readonly', + document: 'readonly', wp: 'readonly', }, + overrides: [ + { + files: [ + '**/@(test|__tests__)/**/*.js', + '**/?(*.)test.js', + ], + extends: [ + require.resolve( './test-unit.js' ), + ], + }, + { + files: [ + '**/specs/**/*.js', + '**/?(*.)spec.js', + ], + extends: [ + require.resolve( './test-e2e.js' ), + ], + }, + ], }; diff --git a/packages/eslint-plugin/configs/test-e2e.js b/packages/eslint-plugin/configs/test-e2e.js new file mode 100644 index 00000000000000..63a52f0f0d0105 --- /dev/null +++ b/packages/eslint-plugin/configs/test-e2e.js @@ -0,0 +1,13 @@ +module.exports = { + extends: [ + 'plugin:jest/recommended', + ], + env: { + browser: true, + }, + globals: { + browser: 'readonly', + page: 'readonly', + wp: 'readonly', + }, +}; diff --git a/packages/eslint-plugin/configs/test-unit.js b/packages/eslint-plugin/configs/test-unit.js new file mode 100644 index 00000000000000..048ced2fe38d1f --- /dev/null +++ b/packages/eslint-plugin/configs/test-unit.js @@ -0,0 +1,5 @@ +module.exports = { + extends: [ + 'plugin:jest/recommended', + ], +}; diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 3e5ee9add8aac6..7a0369eaab06e5 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -25,6 +25,7 @@ "main": "index.js", "dependencies": { "babel-eslint": "^10.0.2", + "eslint-plugin-jest": "^22.15.1", "eslint-plugin-jsdoc": "^15.8.0", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", diff --git a/packages/is-shallow-equal/.eslintrc.json b/packages/is-shallow-equal/.eslintrc.json index 3ab5b55d74cc09..2127e794d08b99 100644 --- a/packages/is-shallow-equal/.eslintrc.json +++ b/packages/is-shallow-equal/.eslintrc.json @@ -1,7 +1,17 @@ { "root": true, - "extends": "plugin:@wordpress/eslint-plugin/es5", + "extends": [ + "plugin:@wordpress/eslint-plugin/es5" + ], "env": { "node": true - } + }, + "overrides": [ + { + "files": [ "@(test|benchmark)/*.js" ], + "extends": [ + "plugin:@wordpress/eslint-plugin/recommended" + ] + } + ] } diff --git a/packages/is-shallow-equal/benchmark/.eslintrc.json b/packages/is-shallow-equal/benchmark/.eslintrc.json deleted file mode 100644 index 93ba810c785626..00000000000000 --- a/packages/is-shallow-equal/benchmark/.eslintrc.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "root": true, - "extends": "../../../.eslintrc.js" -} diff --git a/packages/is-shallow-equal/test/.eslintrc.json b/packages/is-shallow-equal/test/.eslintrc.json deleted file mode 100644 index 93ba810c785626..00000000000000 --- a/packages/is-shallow-equal/test/.eslintrc.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "root": true, - "extends": "../../../.eslintrc.js" -} From 8a8c320c08f0f2d856939c61142d01bd27bbd37e Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Wed, 14 Aug 2019 10:36:58 +0200 Subject: [PATCH 4/5] Add missing documentation for changes applied --- .eslintrc.js | 1 - .../block-serialization-spec-parser/.eslintrc.json | 10 ++++++++++ packages/eslint-plugin/CHANGELOG.md | 3 +++ packages/eslint-plugin/README.md | 5 +++++ packages/eslint-plugin/configs/recommended.js | 6 ++++-- 5 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 packages/block-serialization-spec-parser/.eslintrc.json diff --git a/.eslintrc.js b/.eslintrc.js index 16eccf6f1c73e9..7d2e6f3d40bca0 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -126,7 +126,6 @@ module.exports = { }, { files: [ - 'packages/block-serialization-spec-parser/shared-tests.js', 'packages/jest*/**/*.js', ], extends: [ diff --git a/packages/block-serialization-spec-parser/.eslintrc.json b/packages/block-serialization-spec-parser/.eslintrc.json new file mode 100644 index 00000000000000..ffee0154641f1d --- /dev/null +++ b/packages/block-serialization-spec-parser/.eslintrc.json @@ -0,0 +1,10 @@ +{ + "overrides": [ + { + "files": [ "shared-tests.js" ], + "extends": [ + "plugin:@wordpress/eslint-plugin/test-unit" + ] + } + ] +} diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index 5b7636b9d36d83..4096609b421f40 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/CHANGELOG.md @@ -4,11 +4,14 @@ - The [`@wordpress/no-unused-vars-before-return` rule](https://github.com/WordPress/gutenberg/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars-before-return.md) has been improved to exempt object destructuring only if destructuring to more than one property. - Stricter JSDoc linting using [`eslint-plugin-jsdoc`](https://github.com/gajus/eslint-plugin-jsdoc). +- Stricter validation enabled for test files only using new `test-e2e` and `test-unit` rulesets. ### New Features - New Rule: [`@wordpress/no-unguarded-get-range-at`](https://github.com/WordPress/gutenberg/blob/master/packages/eslint-plugin/docs/rules/no-unguarded-get-range-at.md) - Enable `wp` global by default in the `recommended` config. +- New ruleset `test-e2e` added for end-to-end tests validation. +- New ruleset `test-unit` added for unit tests validation. ### Enhancements diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index f6f89c95f10819..63034c7efe8005 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -28,10 +28,15 @@ The `recommended` preset will include rules governing an ES2015+ environment, an Alternatively, you can opt-in to only the more granular rulesets offered by the plugin. These include: +- `custom` - `es5` - `esnext` +- `jsdoc` +- `jshint` (legacy) - `jsx-a11y` - `react` +- `test-e2e` +- `test-unit` For example, if your project does not use React, you could consider extending including only the ESNext rules in your project using the following `extends` definition: diff --git a/packages/eslint-plugin/configs/recommended.js b/packages/eslint-plugin/configs/recommended.js index 6f3c53c60f188a..71d8625cd961ba 100644 --- a/packages/eslint-plugin/configs/recommended.js +++ b/packages/eslint-plugin/configs/recommended.js @@ -10,12 +10,13 @@ module.exports = { node: true, }, globals: { - window: 'readonly', - document: 'readonly', + window: true, + document: true, wp: 'readonly', }, overrides: [ { + // Unit test files and their helpers only. files: [ '**/@(test|__tests__)/**/*.js', '**/?(*.)test.js', @@ -25,6 +26,7 @@ module.exports = { ], }, { + // End-to-end test files and their helpers only. files: [ '**/specs/**/*.js', '**/?(*.)spec.js', From 1bfc971c29622047bb6635a7101c9523d8088e9c Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Wed, 14 Aug 2019 11:10:35 +0200 Subject: [PATCH 5/5] Scripts: Update CHANGELOG file --- packages/scripts/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index 7ccc3d4d75efa7..d7392cd49ce847 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -5,6 +5,7 @@ - The bundled `puppeteer` dependency has been updated from requiring `1.6.1` to requiring `^1.19.0` ([#16875](https://github.com/WordPress/gutenberg/pull/16875)). It uses Chromium v77 instead of Chromium v69. - The bundled `jest-puppeteer` dependency has been updated from requiring `^4.0.0` to requiring `^4.3.0` ([#16875](https://github.com/WordPress/gutenberg/pull/16875)). - The bundled `eslint` dependency has been updated from requiring `^5.16.0` to requiring `^6.1.0`. +- The bundled `@wordpress/eslint-plugin` dependency has been updated to the next major version `^3.0.0` due to new ESLint rules enabled for all test files. ## 3.4.0 (2019-08-05)