Skip to content

Improve formatting of .json and .yml files #1605

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

Open
wants to merge 21 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f101786
Formats json and yml files using npm run format
devansh016 Oct 18, 2024
3fed57a
Adds override config for yml and json
devansh016 Oct 18, 2024
eaaa59d
Formats json and yml files
devansh016 Oct 18, 2024
a3ae0e1
Add singleQuote for yml files
devansh016 Oct 18, 2024
d336d2a
Ignores generated lock files
devansh016 Oct 18, 2024
90ac758
Updates .editorconfig as per core and Gutenberg
devansh016 Oct 21, 2024
1d13a44
Formats using npm run format-js
devansh016 Oct 21, 2024
a565773
Updates patterns to ignore
devansh016 Oct 21, 2024
afc3339
Overides .yml config to use 2 spaces
devansh016 Oct 21, 2024
4a9d135
Adds file end line and update WordPress coding standards URL
devansh016 Oct 21, 2024
f9a6838
Merge branch 'trunk' of github.com:devansh016/wp-performance into For…
devansh016 Oct 28, 2024
6773f8e
Merge branch 'Format-files-using-npm-run-format-js' of github.com:dev…
devansh016 Oct 28, 2024
376b0fd
Merge branch 'trunk' of github.com:devansh016/wp-performance into For…
devansh016 Nov 19, 2024
9356e5a
Removes yml file override from prettier config
devansh016 Nov 19, 2024
9f687fd
Merge branch 'trunk' into Format-files-using-npm-run-format-js
devansh016 Jun 3, 2025
278fd9a
Merge branch 'trunk' into Format-files-using-npm-run-format-js
devansh016 Jun 6, 2025
3432198
Merge branch 'trunk' of https://github.com/WordPress/performance into…
westonruter Jun 10, 2025
981e5e5
Update package-lock.json
westonruter Jun 10, 2025
7c0f56c
Ignore build files in plugins and fix path to ignore minified files
westonruter Jun 10, 2025
d59caf6
Remove duplicate prettier config file
devansh016 Jun 10, 2025
ebeefd3
Update indent size to 4 for yml and yaml
devansh016 Jun 10, 2025
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
33 changes: 9 additions & 24 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/best-practices/coding-standards/
# https://developer.wordpress.org/coding-standards/wordpress-coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
tab_width = 4
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
Comment on lines -9 to +14
Copy link
Member

Choose a reason for hiding this comment

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

Why this change? The tab width for actual code (PHP and JS) should be 4, so I don't see why this needs to be removed here.

It doesn't apply to .json and .yml, but then we should have specific rules for these file types.

Copy link
Contributor Author

@devansh016 devansh016 Jun 3, 2025

Choose a reason for hiding this comment

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

@felixarntz
When both .editorconfig and .prettierrc are present, Prettier gives precedence to .prettierrc, which ensures PHP and JS files retain their intended 4-space/tab indentation.

I removed the global indent_size = 4 from .editorconfig since it was unintentionally being inherited by .json and .yml files. These files conventionally follow 2-space indentation, so I added specific overrides for them instead.

These updates follow the coding standards defined in the WordPress Core and Gutenberg repositories to stay aligned with WordPress development practices.

Please let me know if you'd like me to make any adjustments or if there's anything I might have missed. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Following up on this, I am still not sure about it.

You mention it was removed because it made .json and .yml files use the indent of 4, but that's exactly what is currently happening: All .json and .yml files use the indent of 4. So from that perspective, I don't see why having this here would be problematic.

Copy link
Contributor Author

@devansh016 devansh016 Jun 10, 2025

Choose a reason for hiding this comment

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

Looking back at this more carefully, I realize I may have overcomplicated the situation. The global indent_size = 4 shouldn't actually cause issues with .json and .yml files if we have proper Prettier configuration in place, since Prettier takes precedence for formatting.

But still we should keep the .editorconfig aligned with WordPress Core and Gutenberg repositories for consistency.


[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_style = space
indent_size = 2
Copy link
Member

Choose a reason for hiding this comment

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

This is confusing to me. As far as I can tell, all the .yml files were now updated to use indent size 4, which looks right. But then why does this say indent size 2 here? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're absolutely right about the inconsistency. Looking at the actual formatting changes in this PR, all .yml files are indeed using an indent size of 4, which aligns with the existing codebase standards.

The indent_size = 2 in the .editorconfig is misleading since Prettier takes precedence and formats these files with 4-space indentation. I initially copied this configuration from the Gutenberg and Core repositories, but it seems now .editorconfig file may not be updated correctly in them.

For consistency and clarity, we should update this to indent_size = 4 to accurately reflect how the files are actually being formatted. This way, the .editorconfig and the actual file formatting are aligned, even though Prettier is the one enforcing the formatting rules.

Would you prefer I update it to indent_size = 4, or we could remove the YAML-specific configuration entirely since Prettier is handling the formatting?

Copy link
Member

Choose a reason for hiding this comment

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

Probably add indent_size = 4 since then the editor will automatically format it properly without requiring Prettier to run, potentially.


[*.txt]
[*.md]
trim_trailing_whitespace = false

[*.json]
indent_style = space
indent_size = 2

[.*rc]
insert_final_newline = false
indent_style = space
indent_size = 2

[*.yml]
insert_final_newline = false
quote_type = single
indent_style = space
indent_size = 2

[.github/CODEOWNERS]
indent_style = space
[*.txt]
end_of_line = crlf
54 changes: 27 additions & 27 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: '/'
schedule:
interval: weekly
open-pull-requests-limit: 10
labels:
- "no milestone"
- "[Type] Enhancement"
- "github_actions"
- package-ecosystem: github-actions
directory: '/'
schedule:
interval: weekly
open-pull-requests-limit: 10
labels:
- 'no milestone'
- '[Type] Enhancement'
- 'github_actions'

- package-ecosystem: npm
directory: '/'
schedule:
interval: weekly
open-pull-requests-limit: 10
labels:
- "no milestone"
- "[Type] Enhancement"
- "javascript"
- package-ecosystem: npm
directory: '/'
schedule:
interval: weekly
open-pull-requests-limit: 10
labels:
- 'no milestone'
- '[Type] Enhancement'
- 'javascript'

- package-ecosystem: composer
directory: '/'
schedule:
interval: weekly
open-pull-requests-limit: 10
labels:
- "no milestone"
- "[Type] Enhancement"
- "php"
- package-ecosystem: composer
directory: '/'
schedule:
interval: weekly
open-pull-requests-limit: 10
labels:
- 'no milestone'
- '[Type] Enhancement'
- 'php'
58 changes: 29 additions & 29 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,42 @@ name: CodeQL

# Cancel previous workflow run groups that have not completed.
concurrency:
# Group workflow runs by workflow name, along with the head branch ref of the pull request
# or otherwise the branch or tag ref.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
cancel-in-progress: true
# Group workflow runs by workflow name, along with the head branch ref of the pull request
# or otherwise the branch or tag ref.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
cancel-in-progress: true

# Disable permissions for all available scopes.
# Enable permissions for specific scopes as needed on job level.
permissions: {}

on:
push:
# Only run if JS files changed.
paths:
- '**.js'
branches:
- trunk
- 'release/**'
pull_request:
# Only run if JS files changed.
paths:
- '**.js'
push:
# Only run if JS files changed.
paths:
- '**.js'
branches:
- trunk
- 'release/**'
pull_request:
# Only run if JS files changed.
paths:
- '**.js'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- name: Checkout
uses: actions/checkout@v4
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: javascript
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: javascript

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
Loading
Loading