Skip to content

Commit 1010ec3

Browse files
committed
ESLint Plugin: Add the recommended Prettier config to enforce WP coding styles (#21602)
* ESLint Config: Add the recommended Prettier config to enforce WordPress coding styles * Update CHANGELOG.md
1 parent e7c0b57 commit 1010ec3

7 files changed

Lines changed: 17 additions & 22 deletions

File tree

.prettierrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Import the default config file and expose it in the project root.
22
// Useful for editor integrations.
3-
module.exports = require( '@wordpress/scripts/config/.prettierrc.js' );
3+
module.exports = require( '@wordpress/prettier-config' );

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/eslint-plugin/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Bug Fixes
44

55
- Fixes an error caused by missing `utils` directory from published package ([#21609](https://github.com/WordPress/gutenberg/pull/21609)).
6+
- Added the recommended `Prettier` config that enforces WordPress coding style guidelines ([#21602](https://github.com/WordPress/gutenberg/pull/21602)).
67

78
## 5.0.0 (2020-04-15)
89

@@ -26,7 +27,7 @@
2627
- New Rule: [`@wordpress/i18n-ellipsis`](https://github.com/WordPress/gutenberg/blob/master/packages/eslint-plugin/docs/rules/i18n-ellipsis.md)
2728
- 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)).
2829

29-
### Bug Fix
30+
### Bug Fixes
3031

3132
- The `@wordpress/valid-sprintf` rule now detects usage of `sprintf` via `i18n.sprintf` (e.g. when using `import * as i18n from '@wordpress/i18n'`).
3233
- `@wordpress/no-unused-vars-before-return` will correctly consider other unused variables after encountering an instance of an `excludePattern` option exception.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
const defaultPrettierConfig = require( '@wordpress/prettier-config' );
5+
16
module.exports = {
27
extends: [
38
require.resolve( './recommended-with-formatting.js' ),
49
'plugin:prettier/recommended',
510
'prettier/react',
611
],
12+
rules: {
13+
'prettier/prettier': [ 'error', defaultPrettierConfig ],
14+
},
715
};

packages/eslint-plugin/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
],
2626
"main": "index.js",
2727
"dependencies": {
28+
"@wordpress/prettier-config": "file:../prettier-config",
2829
"babel-eslint": "^10.1.0",
2930
"eslint-config-prettier": "^6.10.1",
3031
"eslint-plugin-jest": "^23.8.2",
Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
/**
2-
* Internal dependencies
3-
*/
4-
const defaultPrettierConfig = require( './.prettierrc' );
5-
const { hasPrettierConfig } = require( '../utils' );
6-
71
const eslintConfig = {
82
root: true,
93
extends: [
@@ -17,16 +11,4 @@ const eslintConfig = {
1711
],
1812
};
1913

20-
if ( ! hasPrettierConfig() ) {
21-
eslintConfig.rules = {
22-
'prettier/prettier': [
23-
'error',
24-
defaultPrettierConfig,
25-
{
26-
usePrettierrc: false,
27-
},
28-
],
29-
};
30-
}
31-
3214
module.exports = eslintConfig;

packages/scripts/scripts/format-js.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ if ( ! checkResult.success ) {
7272
// needed for config, otherwise pass in args to default config in packages
7373
// See: https://prettier.io/docs/en/configuration.html
7474
let configArgs = [];
75-
// TODO: once setup, use @wordpress/prettier-config
7675
if ( ! hasPrettierConfig() ) {
77-
configArgs = [ '--config', fromConfigRoot( '.prettierrc.js' ) ];
76+
configArgs = [
77+
'--config',
78+
require.resolve( '@wordpress/prettier-config' ),
79+
];
7880
}
7981

8082
// If `--ignore-path` is not explicitly specified, use the project's or global .eslintignore

0 commit comments

Comments
 (0)