Improve formatting of .json and .yml files#1605
Improve formatting of .json and .yml files#1605westonruter merged 30 commits intoWordPress:trunkfrom
.json and .yml files#1605Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Let's also do linting of JSON and YML files in the lint-staged config so this doesn't happen again. Also, why isn't the formatting not causing a failure on the GHA checks? |
|
Will Dependabot updates undo the changes to |
|
|
I think we squash and merge this one and include an ignore commit for the merge commit to hide it in git blame. Ref: https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view. |
|
We should exclude generated lock files from Prettier, just to avoid conflicts |
Yes, we should ignore any auto-generated files. @devansh016 can you please add a https://prettier.io/docs/en/ignore.html with such files? |
|
See also WordPress/gutenberg#30714 in which Gutenberg started applying formatting to JSON files. |
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
I think we still need to confirm Dependabot's behavior. We wouldn't want it constantly reverting tabs back to spaces. |
Dependabot generally respects the indentation style in |
felixarntz
left a comment
There was a problem hiding this comment.
I'm still not sold on the changes in .editorconfig - making things more vague just to not conflict doesn't seem right to me. For any problems that the current .editorconfig is causing, we should fix them, not avoid them. Related: #1605 (comment)
In general, I'd also love to get @swissspidy to sign off on the changes in this PR.
.editorconfig
Outdated
| [*.txt] | ||
| end_of_line = crlf |
There was a problem hiding this comment.
I don't see a reason for this. WP core has historically done this for its readme.txt for Windows, but we shouldn't do this here. Let's remove it.
|
Same here. Happy to take another look once those changes are (partially) reverted and the merge conflicts resolved. |
|
Once #2325 is merged, let's pick this up again. It's annoying to me how every time I run |
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
|
Merge conflicts have been resolved. |
There was a problem hiding this comment.
Pull request overview
This PR standardizes the formatting of JSON and YAML files across the repository using Prettier and WordPress coding standards. The changes switch JSON files from 2-space indentation to tab indentation, and YAML files to 4-space indentation.
Key changes:
- JSON and YAML files reformatted with consistent indentation (tabs for JSON, 4 spaces for YAML)
- Prettier configuration moved from standalone
.prettierrcfile topackage.json - Added
.prettierignoreto exclude build artifacts and lock files from formatting
Reviewed changes
Copilot reviewed 7 out of 23 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
.editorconfig |
Simplified configuration, removed specific JSON rules (now uses default tab indentation) |
.prettierrc |
Deleted - configuration moved to package.json |
.prettierignore |
Added to exclude build files, vendor, and lock files from formatting |
package.json |
Added "prettier": "@wordpress/prettier-config" field |
tsconfig.json |
Reformatted with tabs instead of spaces |
composer.json |
Reformatted with tabs, improved readability |
plugins.json |
Reformatted with tabs |
.wp-env.json |
Reformatted with tabs |
codecov.yml |
Reformatted with 4-space indentation |
.github/workflows/*.yml |
All workflow files reformatted with 4-space indentation |
.github/dependabot.yml |
Reformatted with 4-space indentation |
plugins/*/tests/**/*.json |
Test data files reformatted with tabs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.editorconfig
Outdated
| [*.{yml,yaml}] | ||
| indent_style = space | ||
| indent_size = 2 | ||
| indent_size = 4 |
There was a problem hiding this comment.
Humm. Gutenberg's .editorconfig includes:
[*.{yml,yaml}]
indent_style = space
indent_size = 2
Same as in wordpress-develop's .editorconfig
And yet, running npm run format-js automatically adds 4 spaces to YAML files. 😕
There was a problem hiding this comment.
I just tested by making changes to .editorconfig in wordpress-develop's and running the format command. It is not following the changes.
There was a problem hiding this comment.
For reference adding .prettierrc.js is making the format follow these rules. Not sure why .editorconfig rules are been followed.
/**
* Prettier configuration.
*
* @see https://prettier.io/docs/en/configuration.html
*/
const wordpressConfig = require( '@wordpress/prettier-config' );
/** @type {import("prettier").Config} */
const config = {
...wordpressConfig,
overrides: [
...( wordpressConfig.overrides || [] ),
{
files: '*.{yml,yaml}',
options: {
useTabs: false,
tabWidth: 2,
},
},
],
};
module.exports = config;There was a problem hiding this comment.
Should we override the prettier config to force it to match .editorconfig?
There was a problem hiding this comment.
Gutenberg's YAML files are formatted with 4 spaces.
There was a problem hiding this comment.
yes you'll need to override settings in a prettier config because at the moment prettier is loading its options from (package.json).prettier
$ npx prettier --find-config-path webpack.config.js
package.jsonthat loads @wordpress/prettier-config which have tabWidth: 4 for every file.
const config = {
useTabs: true,
tabWidth: 4,
printWidth: 80,
singleQuote: true,
trailingComma: 'es5',
bracketSameLine: false,
bracketSpacing: true,
semi: true,
arrowParens: 'always',
...customOptions,
overrides: [
{
files: '*.{css,sass,scss}',
options: {
singleQuote: false,
...customStyleOptions,
},
},
],
};.editorconfig is just here to provide styles to editors and it don't have any effect on formatting, but when prettier config doesn't exists, it tries to resolve defaults from .editorconfig, which have no effect here since prettier config is already being resolved from @wordpress/prettier-config.
There was a problem hiding this comment.
also, i think the override changes should be proposed to @wordpress/prettier-config since gutenberg and core .editorconfig says so, which is correct.
There was a problem hiding this comment.
My head is kinda spinning here.
Gutenberg is using 4 spaces in its YAML files, for example: https://github.com/WordPress/gutenberg/blob/trunk/.github/dependabot.yml
wordpress-develop is using 2 spaces ints in YAML files, for example: https://github.com/WordPress/wordpress-develop/blob/trunk/.github/workflows/php-compatibility.yml
Nevertheless, both Gutenberg and wordpress-develop have .editorconfig files with:
[*.{yml,yaml}]
indent_style = space
indent_size = 2
So Gutenberg's YAML files are incorrectly formatted according to the .editorconfig and this appears to be due to format-js which is configured to use 4 spaces instead of 2.
So we need to override the Prettier config to force it to use 2 spaces for YAML files. I've committed this in 15f2f03.
Update .editorconfig to use 2 spaces for YAML files. Add .prettierrc.js to override @wordpress/prettier-config for YAML files. Remove prettier config from package.json in favor of the new configuration file. Co-authored-by: devansh016 <devanshchaudhary2002@gmail.com> Co-authored-by: thelovekesh <thelovekesh@git.wordpress.org> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
… Format-files-using-npm-run-format-js
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 16 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 16 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… Format-files-using-npm-run-format-js
Summary
Fixes #1603
Relevant technical choices
The following files have been formatted by using
npm run format-jsNote: .yml and .json files were not ignored to ensure they are properly formatted as well.