The editorconfig project provides a powerful tool for standardizing the general coding standards used in a project, specifically in regards to:
indent_style
(spaces vs tabs)indent_size
end_of_line
(lf vs cr vs crlf)charset
(e.g. latin1, utf-8)trim_trailing_whitespace
insert_final_newline
The functionality of reading a project’s .editorconfig
file is built into some editors and available in many others via a plugin. If your browser doesn’t already support an .editorconfig
file, I suggest you install a plugin.
WordPress .editorconfig
The WordPress project uses the following .editorconfig as found at https://github.com/WordPress/wordpress-develop/blob/master/.editorconfig
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
[*.yml]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
You can download this to your project directly from the command line with
curl -O https://raw.githubusercontent.com/WordPress/wordpress-develop/master/.editorconfig
Modified WordPress .editorconfig
I’ve made some modifications to the official WordPress .editorconfig
file. Specifically,
- Display a tab taking up 4 spaces in my editor (e.g. in a PHP file).
- Use 2 spaces (instead of tabs) when working with JavaScript (and JSON) files.
You can download this modified WordPress .editorconfig file to your project directly from the command line with
curl -O https://gist.githubusercontent.com/salcode/285303f7983ad729b74d13d752214f4c/raw/.editorconfig
Here is a copy of my WordPress .editorconfig
file.
# EditorConfig helps keep your project formatting consistent. | |
# See https://EditorConfig.org | |
# | |
# This is a modified version of the WordPress coding standards. | |
# | |
# Author: Sal Ferrarello (@salcode) | |
# https://salferrarello.com/wordpress-editorconfig/ | |
# | |
# You can download this file directly | |
# to your project from the command-line with | |
# curl -O https://gist.githubusercontent.com/salcode/285303f7983ad729b74d13d752214f4c/raw/.editorconfig | |
root = true | |
[*] | |
charset = utf-8 | |
end_of_line = lf | |
insert_final_newline = true | |
trim_trailing_whitespace = true | |
indent_style = tab | |
indent_size = 4 | |
[*.{js,json}] | |
indent_style = space | |
indent_size = 2 | |
[*.yml] | |
indent_style = space | |
indent_size = 2 | |
[*.md] | |
trim_trailing_whitespace = false | |
[{*.txt,wp-config-sample.php}] | |
end_of_line = crlf |
Leave a Reply