From 8c033e8194b845416d9dbd0d4946133b50afb39f Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Wed, 15 Apr 2020 11:01:28 +0200 Subject: [PATCH 1/2] ESLint Config: Add the recommended Prettier config to enforce WordPress coding styles --- .prettierrc.js | 2 +- package-lock.json | 1 + packages/eslint-plugin/CHANGELOG.md | 3 ++- packages/eslint-plugin/configs/recommended.js | 8 ++++++++ packages/eslint-plugin/package.json | 1 + packages/scripts/config/.eslintrc.js | 18 ------------------ packages/scripts/scripts/format-js.js | 6 ++++-- 7 files changed, 17 insertions(+), 22 deletions(-) diff --git a/.prettierrc.js b/.prettierrc.js index 0605f83bf9078..51b8aeb41505a 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,3 +1,3 @@ // Import the default config file and expose it in the project root. // Useful for editor integrations. -module.exports = require( '@wordpress/scripts/config/.prettierrc.js' ); +module.exports = require( '@wordpress/prettier-config' ); diff --git a/package-lock.json b/package-lock.json index 82d0ecdc121cc..5b3985b08eb67 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11215,6 +11215,7 @@ "version": "file:packages/eslint-plugin", "dev": true, "requires": { + "@wordpress/prettier-config": "file:packages/prettier-config", "babel-eslint": "^10.1.0", "eslint-config-prettier": "^6.10.1", "eslint-plugin-jest": "^23.8.2", diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index 3a240b667c678..4f94e8bc5c471 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/CHANGELOG.md @@ -20,10 +20,11 @@ - New Rule: [`@wordpress/i18n-ellipsis`](https://github.com/WordPress/gutenberg/blob/master/packages/eslint-plugin/docs/rules/i18n-ellipsis.md) - The bundled `eslint-plugin-react` dependency has been updated from requiring `^7.14.3` to requiring `^7.19.0` ([#21424](https://github.com/WordPress/gutenberg/pull/21424)). -### Bug Fix +### Bug Fixes - The `@wordpress/valid-sprintf` rule now detects usage of `sprintf` via `i18n.sprintf` (e.g. when using `import * as i18n from '@wordpress/i18n'`). - `@wordpress/no-unused-vars-before-return` will correctly consider other unused variables after encountering an instance of an `excludePattern` option exception. +- Added the recommended `Prettier` config that enforces WordPress coding style guidelines ([#21602](https://github.com/WordPress/gutenberg/pull/21602)). ## 4.0.0 (2020-02-10) diff --git a/packages/eslint-plugin/configs/recommended.js b/packages/eslint-plugin/configs/recommended.js index 9e1659685a85a..bb4fcb4f24fee 100644 --- a/packages/eslint-plugin/configs/recommended.js +++ b/packages/eslint-plugin/configs/recommended.js @@ -1,7 +1,15 @@ +/** + * WordPress dependencies + */ +const defaultPrettierConfig = require( '@wordpress/prettier-config' ); + module.exports = { extends: [ require.resolve( './recommended-with-formatting.js' ), 'plugin:prettier/recommended', 'prettier/react', ], + rules: { + 'prettier/prettier': [ 'error', defaultPrettierConfig ], + }, }; diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index f910c5d6e1b83..18698aa27c066 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -24,6 +24,7 @@ ], "main": "index.js", "dependencies": { + "@wordpress/prettier-config": "file:../prettier-config", "babel-eslint": "^10.1.0", "eslint-config-prettier": "^6.10.1", "eslint-plugin-jest": "^23.8.2", diff --git a/packages/scripts/config/.eslintrc.js b/packages/scripts/config/.eslintrc.js index b3bb9bce2d2d3..68e37cf71d9cc 100644 --- a/packages/scripts/config/.eslintrc.js +++ b/packages/scripts/config/.eslintrc.js @@ -1,9 +1,3 @@ -/** - * Internal dependencies - */ -const defaultPrettierConfig = require( './.prettierrc' ); -const { hasPrettierConfig } = require( '../utils' ); - const eslintConfig = { root: true, extends: [ @@ -17,16 +11,4 @@ const eslintConfig = { ], }; -if ( ! hasPrettierConfig() ) { - eslintConfig.rules = { - 'prettier/prettier': [ - 'error', - defaultPrettierConfig, - { - usePrettierrc: false, - }, - ], - }; -} - module.exports = eslintConfig; diff --git a/packages/scripts/scripts/format-js.js b/packages/scripts/scripts/format-js.js index 29b2a78ab1fb9..60b75a12d82bc 100644 --- a/packages/scripts/scripts/format-js.js +++ b/packages/scripts/scripts/format-js.js @@ -72,9 +72,11 @@ if ( ! checkResult.success ) { // needed for config, otherwise pass in args to default config in packages // See: https://prettier.io/docs/en/configuration.html let configArgs = []; -// TODO: once setup, use @wordpress/prettier-config if ( ! hasPrettierConfig() ) { - configArgs = [ '--config', fromConfigRoot( '.prettierrc.js' ) ]; + configArgs = [ + '--config', + require.resolve( '@wordpress/prettier-config' ), + ]; } // If `--ignore-path` is not explicitly specified, use the project's or global .eslintignore From b40fc814c87c53ca84b32afba08ab634068c3b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=28Greg=29=20Zi=C3=B3=C5=82kowski?= Date: Wed, 15 Apr 2020 16:45:23 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md --- packages/eslint-plugin/CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index 4f94e8bc5c471..891aac6b148e2 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/CHANGELOG.md @@ -1,5 +1,9 @@ ## Master +### Bug Fix + +- Added the recommended `Prettier` config that enforces WordPress coding style guidelines ([#21602](https://github.com/WordPress/gutenberg/pull/21602)). + ### Breaking Changes - There is a new `i18n` ruleset that includes all i18n-related rules and is included in the `recommended` ruleset. @@ -24,7 +28,6 @@ - The `@wordpress/valid-sprintf` rule now detects usage of `sprintf` via `i18n.sprintf` (e.g. when using `import * as i18n from '@wordpress/i18n'`). - `@wordpress/no-unused-vars-before-return` will correctly consider other unused variables after encountering an instance of an `excludePattern` option exception. -- Added the recommended `Prettier` config that enforces WordPress coding style guidelines ([#21602](https://github.com/WordPress/gutenberg/pull/21602)). ## 4.0.0 (2020-02-10)