-
Notifications
You must be signed in to change notification settings - Fork 128
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
base: trunk
Are you sure you want to change the base?
Changes from 12 commits
f101786
3fed57a
eaaa59d
a3ae0e1
d336d2a
90ac758
1d13a44
a565773
afc3339
4a9d135
f9a6838
6773f8e
376b0fd
9356e5a
9f687fd
278fd9a
3432198
981e5e5
7c0f56c
d59caf6
ebeefd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
[*.yml] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.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 | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Files and folders related to build | ||
/build | ||
/node_modules | ||
/vendor | ||
/dist | ||
|
||
# Minified files | ||
/*.min.js | ||
|
||
# Ignore Composer lock file | ||
composer.lock | ||
|
||
# Ignore npm package lock file | ||
package-lock.json |
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this any different than the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, functionally they're identical in this case. Both .prettierrc.js and .prettierrc contain the same configuration options and produce the same formatting results. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, it could be added to "prettier": "@wordpress/prettier-config", |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Import the default config file and expose it in the project root. | ||
// Useful for editor integrations. | ||
const wpPrettierConfig = require( '@wordpress/prettier-config' ); | ||
|
||
module.exports = { | ||
...wpPrettierConfig, | ||
overrides: [ | ||
{ | ||
files: '*.yml', | ||
options: { | ||
useTabs: false, | ||
tabWidth: 2, | ||
}, | ||
}, | ||
], | ||
}; | ||
swissspidy marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
{ | ||
"core": null, | ||
"plugins": [ | ||
"./plugins/optimization-detective", | ||
"./plugins/auto-sizes", | ||
"./plugins/dominant-color-images", | ||
"./plugins/embed-optimizer", | ||
"./plugins/image-prioritizer", | ||
"./plugins/performance-lab", | ||
"./plugins/speculation-rules", | ||
"./plugins/web-worker-offloading", | ||
"./plugins/webp-uploads" | ||
], | ||
"env": { | ||
"tests": { | ||
"config": { | ||
"FS_METHOD": "direct" | ||
}, | ||
"mappings": { | ||
"/wp-content/plugins/performance": "." | ||
} | ||
} | ||
} | ||
"core": null, | ||
swissspidy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"plugins": [ | ||
"./plugins/optimization-detective", | ||
"./plugins/auto-sizes", | ||
"./plugins/dominant-color-images", | ||
"./plugins/embed-optimizer", | ||
"./plugins/image-prioritizer", | ||
"./plugins/performance-lab", | ||
"./plugins/speculation-rules", | ||
"./plugins/web-worker-offloading", | ||
"./plugins/webp-uploads" | ||
], | ||
"env": { | ||
"tests": { | ||
"config": { | ||
"FS_METHOD": "direct" | ||
}, | ||
"mappings": { | ||
"/wp-content/plugins/performance": "." | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about aligning
.editorconfig
just for the sake of aligning - aren't the configurations for WordPress Core and Gutenberg somewhat incompldete?d
The WordPress Coding Standards clearly state that indent size of a tab should be 4. If this is not expressed in
.editorconfig
, doesn't it leave things up to chance? That wouldn't be right.I don't think we should accept that just because Prettier handles it. The Coding Standards setup of the repository should be consistently configured between different tooling, it shouldn't conflict.
In other words, I think we have two options:
indent_size = 4
globally and override it for any file types where it isn't 4..php
,.js
,.css
,.html
,.ts
,.tsx
).