diff --git a/.prettierrc.js b/.prettierrc.js index 0605f83bf90782..51b8aeb41505a6 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 82d0ecdc121cc1..5b3985b08eb670 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 11cb8dddfdaa5b..444381e3271d71 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/CHANGELOG.md @@ -3,6 +3,7 @@ ### Bug Fixes - Fixes an error caused by missing `utils` directory from published package ([#21609](https://github.com/WordPress/gutenberg/pull/21609)). +- Added the recommended `Prettier` config that enforces WordPress coding style guidelines ([#21602](https://github.com/WordPress/gutenberg/pull/21602)). ## 5.0.0 (2020-04-15) @@ -26,7 +27,7 @@ - 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. diff --git a/packages/eslint-plugin/configs/recommended.js b/packages/eslint-plugin/configs/recommended.js index 9e1659685a85ad..bb4fcb4f24feea 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 e73df503667039..f70186a4a26409 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -25,6 +25,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 b3bb9bce2d2d32..68e37cf71d9cc5 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 29b2a78ab1fb9f..60b75a12d82bc8 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