Skip to content

Commit

Permalink
ESLint Plugin: Add the recommended Prettier config to enforce WP codi…
Browse files Browse the repository at this point in the history
…ng styles (#21602)

* ESLint Config: Add the recommended Prettier config to enforce WordPress coding styles

* Update CHANGELOG.md
  • Loading branch information
gziolo committed Apr 15, 2020
1 parent e7c0b57 commit 1010ec3
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -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' );
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/eslint-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions packages/eslint-plugin/configs/recommended.js
Original file line number Diff line number Diff line change
@@ -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 ],
},
};
1 change: 1 addition & 0 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 0 additions & 18 deletions packages/scripts/config/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/**
* Internal dependencies
*/
const defaultPrettierConfig = require( './.prettierrc' );
const { hasPrettierConfig } = require( '../utils' );

const eslintConfig = {
root: true,
extends: [
Expand All @@ -17,16 +11,4 @@ const eslintConfig = {
],
};

if ( ! hasPrettierConfig() ) {
eslintConfig.rules = {
'prettier/prettier': [
'error',
defaultPrettierConfig,
{
usePrettierrc: false,
},
],
};
}

module.exports = eslintConfig;
6 changes: 4 additions & 2 deletions packages/scripts/scripts/format-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1010ec3

Please sign in to comment.