diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000000000..39d3acb571b21 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,8 @@ +.cache +build +build-module +build-types +packages/block-serialization-spec-parser/parser.js +packages/e2e-tests/plugins +packages/react-native-editor/bundle +vendor diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index 1aeba8b878c47..9eb8af12fe4e4 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -5,6 +5,7 @@ ### New Features - Include a Jest Reporter that formats test results for GitHub Actions annotations ([#31041](https://github.com/WordPress/gutenberg/pull/31041)). +- Have the `format` command ignore files listed in a `.prettierignore` file, add a fallback `.prettierignore` to the package ([30844](https://github.com/WordPress/gutenberg/pull/30844)). ### Breaking Changes diff --git a/packages/scripts/README.md b/packages/scripts/README.md index ea507e8625c1d..ab94f94cdb6c4 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -150,7 +150,7 @@ This is how you execute the script with presented setup: When you run commands similar to the `npm run format:src` example above, you can provide a file, a directory, or `glob` syntax or any combination of them. -By default, files located in `build`, `node_modules`, and `vendor` folders are ignored. +By default, files located in `build`, `node_modules`, and `vendor` folders are ignored. You can customize the list of ignored files and directories by adding them to a `.prettierignore` file in your project. ### `lint-js` diff --git a/packages/scripts/config/.prettierignore b/packages/scripts/config/.prettierignore new file mode 100644 index 0000000000000..411a5b8a43744 --- /dev/null +++ b/packages/scripts/config/.prettierignore @@ -0,0 +1,2 @@ +build +vendor diff --git a/packages/scripts/scripts/format.js b/packages/scripts/scripts/format.js index 6dd655bdab701..7ac808de4457a 100644 --- a/packages/scripts/scripts/format.js +++ b/packages/scripts/scripts/format.js @@ -79,13 +79,13 @@ if ( ! hasPrettierConfig() ) { ]; } -// If `--ignore-path` is not explicitly specified, use the project's or global .eslintignore +// If `--ignore-path` is not explicitly specified, use the project's or global .prettierignore. let ignorePath = getArgFromCLI( '--ignore-path' ); if ( ! ignorePath ) { - if ( hasProjectFile( '.eslintignore' ) ) { - ignorePath = fromProjectRoot( '.eslintignore' ); + if ( hasProjectFile( '.prettierignore' ) ) { + ignorePath = fromProjectRoot( '.prettierignore' ); } else { - ignorePath = fromConfigRoot( '.eslintignore' ); + ignorePath = fromConfigRoot( '.prettierignore' ); } } const ignoreArgs = [ '--ignore-path', ignorePath ];