Skip to content

Improve formatting of .json and .yml files#1605

Merged
westonruter merged 30 commits intoWordPress:trunkfrom
devansh016:Format-files-using-npm-run-format-js
Jan 8, 2026
Merged

Improve formatting of .json and .yml files#1605
westonruter merged 30 commits intoWordPress:trunkfrom
devansh016:Format-files-using-npm-run-format-js

Conversation

@devansh016
Copy link
Contributor

@devansh016 devansh016 commented Oct 18, 2024

Summary

Fixes #1603

Relevant technical choices

The following files have been formatted by using npm run format-js
Note: .yml and .json files were not ignored to ensure they are properly formatted as well.

.eslintrc.js 22ms
.github/dependabot.yml 12ms
.github/workflows/bump-wordpress-tested-up-to.yml 7ms
.github/workflows/codeql-analysis.yml 3ms
.github/workflows/deploy-plugins.yml 8ms
.github/workflows/e2e-test.yml 3ms
.github/workflows/js-lint.yml 2ms
.github/workflows/php-lint.yml 3ms
.github/workflows/php-test-plugins.yml 5ms
.github/workflows/plugin-check.yml 4ms
.github/workflows/pr-validation.yml 1ms
.github/workflows/props-bot.yml 2ms
.github/workflows/spell-check.yml 1ms
.prettierrc.js 2ms
.wp-env.json 2ms
.wp-env.override.json 2ms
bin/plugin/cli.js 7ms
bin/plugin/commands/changelog.js 15ms
bin/plugin/commands/readme.js 7ms
bin/plugin/commands/since.js 4ms
bin/plugin/commands/versions.js 4ms
bin/plugin/config.js 1ms
bin/plugin/lib/logger.js 1ms
bin/plugin/lib/milestone.js 2ms
bin/validate-json-schema.js 3ms
codecov.yml 1ms
composer.json 1ms
lint-staged.config.js 3ms
package.json 1ms
plugins.json 0ms
plugins/auto-sizes/tests/e2e/specs/improve-calculate-sizes.spec.js 3ms
plugins/embed-optimizer/detect.js 2ms
plugins/embed-optimizer/lazy-load.js 2ms
plugins/image-prioritizer/detect.js 3ms
plugins/image-prioritizer/lazy-load-bg-image.js 2ms
plugins/image-prioritizer/lazy-load-video.js 2ms
plugins/image-prioritizer/tests/test-cases/preload-links-with-one-half-stale-group/url-metrics.json 8ms
plugins/optimization-detective/detect-loader.js 1ms
plugins/optimization-detective/detect.js 14ms
plugins/optimization-detective/tests/data/url-metrics/tablet-viewport-half-stale.json 5ms
plugins/optimization-detective/types.ts 64ms
plugins/performance-lab/.wordpress-org/blueprints/blueprint.json 1ms
plugins/performance-lab/includes/admin/plugin-activate-ajax.js 2ms
plugins/view-transitions/js/types.ts 2ms
plugins/view-transitions/js/view-transitions.js 4ms
tools/e2e/playwright.config.ts 2ms
tools/webpack/utils.js 3ms
tsconfig.json 1ms
webpack.config.js 8ms

@westonruter westonruter added no milestone PRs that do not have a defined milestone for release [Type] Bug An existing feature is broken labels Oct 18, 2024
@devansh016 devansh016 marked this pull request as ready for review October 18, 2024 05:04
@github-actions
Copy link

github-actions bot commented Oct 18, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: devansh016 <devansh2002@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: mukeshpanchal27 <mukesh27@git.wordpress.org>
Co-authored-by: thelovekesh <thelovekesh@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
Co-authored-by: felixarntz <flixos90@git.wordpress.org>
Co-authored-by: phanduynam <phanduynam@git.wordpress.org>
Co-authored-by: dilipom13 <dilip2615@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@westonruter
Copy link
Member

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?

@westonruter
Copy link
Member

Will Dependabot updates undo the changes to composer.json, package-lock.json, and package.json?

@devansh016
Copy link
Contributor Author

Also, why isn't the formatting not causing a failure on the GHA checks?

npm run lint-js doesn't check for .yml and .json file and hence not causing a failure on the GHA checks.

@thelovekesh
Copy link
Member

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.

@swissspidy
Copy link
Member

We should exclude generated lock files from Prettier, just to avoid conflicts

@thelovekesh
Copy link
Member

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?

@westonruter
Copy link
Member

See also WordPress/gutenberg#30714 in which Gutenberg started applying formatting to JSON files.

Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
@westonruter
Copy link
Member

Will Dependabot updates undo the changes to composer.json, package-lock.json, and package.json?

I think we still need to confirm Dependabot's behavior. We wouldn't want it constantly reverting tabs back to spaces.

@devansh016
Copy link
Contributor Author

Will Dependabot updates undo the changes to composer.json, package-lock.json, and package.json?

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 package.json when updating the lockfile so it should not revert tabs back to spaces. Ref

@devansh016 devansh016 requested a review from felixarntz July 7, 2025 05:22
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Comment on lines +23 to +24
[*.txt]
end_of_line = crlf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 9813349

@swissspidy
Copy link
Member

Same here.

Happy to take another look once those changes are (partially) reverted and the merge conflicts resolved.

@westonruter
Copy link
Member

westonruter commented Jan 7, 2026

Once #2325 is merged, let's pick this up again. It's annoying to me how every time I run npm run format-js it modifies many files.

@westonruter
Copy link
Member

Merge conflicts have been resolved.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .prettierrc file to package.json
  • Added .prettierignore to 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
Comment on lines +16 to +18
[*.{yml,yaml}]
indent_style = space
indent_size = 2
indent_size = 4
Copy link
Member

@westonruter westonruter Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested by making changes to .editorconfig in wordpress-develop's and running the format command. It is not following the changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we override the prettier config to force it to match .editorconfig?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gutenberg's YAML files are formatted with 4 spaces.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.json

that 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, i think the override changes should be proposed to @wordpress/prettier-config since gutenberg and core .editorconfig says so, which is correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that's correct

westonruter and others added 4 commits January 7, 2026 16:17
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>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

westonruter and others added 2 commits January 7, 2026 16:56
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@westonruter westonruter merged commit 11c5c5c into WordPress:trunk Jan 8, 2026
43 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no milestone PRs that do not have a defined milestone for release [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running npm run format-js formats more files than expected

8 participants