-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Prettier formatting script (#18048)
* Add Prettier NPM dependency to packages/scripts and top-level * Scripts: export the fromProjectRoot function from scripts/utils module * Scripts: Add Prettier formatting script * ESLint config: use default (linebreak before ternary op) config for operator-linebreak rule * ESLint: disable formatting rules in the recommended config Adds `eslint-config-prettier` to the recommended config and creates an alternative `recommended-with-formatting` config for project that want to keep ESLint formatting rules and opt-out of Prettier. * Scripts: the format-js script checks if Prettier is present and has top-level config Prettier presence in a `wp-scripts`-powered project is optional, and the `format-js` script checks if it's there and if it's indeed the fork (`wp-prettier`). Will report error otherwise. Also, require a top-level Prettier config to be present. We can't default to the one inside `wp-scripts`, because IDE and editor integrations won't find it there and will use the Prettier defaults. * Bump the minimum required version of npm to 6.9.0 * Add ESLint config changes notice to changelog * Update package-lock.json * Regenerate package-lock.json Co-authored-by: Grzegorz (Greg) Ziółkowski <[email protected]>
- Loading branch information
Showing
16 changed files
with
303 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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' ); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,7 @@ | |
"node-watch": "0.6.0", | ||
"postcss": "7.0.13", | ||
"postcss-loader": "3.0.0", | ||
"prettier": "npm:[email protected]", | ||
"progress": "2.0.3", | ||
"react": "16.9.0", | ||
"react-dom": "16.9.0", | ||
|
@@ -186,6 +187,7 @@ | |
"fixtures:server-registered": "packages/env/bin/wp-env run wordpress ./wp-content/plugins/gutenberg/bin/get-server-blocks.php > test/integration/full-content/server-registered.json", | ||
"fixtures:generate": "npm run fixtures:server-registered && cross-env GENERATE_MISSING_FIXTURES=y npm run test-unit", | ||
"fixtures:regenerate": "npm run fixtures:clean && npm run fixtures:generate", | ||
"format-js": "wp-scripts format-js", | ||
"lint": "concurrently \"npm run lint-js\" \"npm run lint-pkg-json\" \"npm run lint-css\" \"npm run lint-types\"", | ||
"lint-js": "wp-scripts lint-js", | ||
"lint-js:fix": "npm run lint-js -- --fix", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/eslint-plugin/configs/recommended-with-formatting.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module.exports = { | ||
parser: 'babel-eslint', | ||
extends: [ | ||
require.resolve( './jsx-a11y.js' ), | ||
require.resolve( './custom.js' ), | ||
require.resolve( './react.js' ), | ||
require.resolve( './esnext.js' ), | ||
], | ||
env: { | ||
node: true, | ||
}, | ||
globals: { | ||
window: true, | ||
document: true, | ||
wp: 'readonly', | ||
}, | ||
overrides: [ | ||
{ | ||
// Unit test files and their helpers only. | ||
files: [ | ||
'**/@(test|__tests__)/**/*.js', | ||
'**/?(*.)test.js', | ||
], | ||
extends: [ | ||
require.resolve( './test-unit.js' ), | ||
], | ||
}, | ||
{ | ||
// End-to-end test files and their helpers only. | ||
files: [ | ||
'**/specs/**/*.js', | ||
'**/?(*.)spec.js', | ||
], | ||
extends: [ | ||
require.resolve( './test-e2e.js' ), | ||
], | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,3 @@ | ||
module.exports = { | ||
parser: 'babel-eslint', | ||
extends: [ | ||
require.resolve( './jsx-a11y.js' ), | ||
require.resolve( './custom.js' ), | ||
require.resolve( './react.js' ), | ||
require.resolve( './esnext.js' ), | ||
], | ||
env: { | ||
node: true, | ||
}, | ||
globals: { | ||
window: true, | ||
document: true, | ||
wp: 'readonly', | ||
}, | ||
overrides: [ | ||
{ | ||
// Unit test files and their helpers only. | ||
files: [ | ||
'**/@(test|__tests__)/**/*.js', | ||
'**/?(*.)test.js', | ||
], | ||
extends: [ | ||
require.resolve( './test-unit.js' ), | ||
], | ||
}, | ||
{ | ||
// End-to-end test files and their helpers only. | ||
files: [ | ||
'**/specs/**/*.js', | ||
'**/?(*.)spec.js', | ||
], | ||
extends: [ | ||
require.resolve( './test-e2e.js' ), | ||
], | ||
}, | ||
], | ||
extends: [ require.resolve( './recommended-with-formatting.js' ), 'eslint-config-prettier' ], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.