Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint Plugin: Add the recommended Prettier config to enforce WP coding styles #21602

Merged
merged 3 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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)).
gziolo marked this conversation as resolved.
Show resolved Hide resolved

## 4.0.0 (2020-02-10)

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 @@ -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",
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