What is a
.editorconfig file, and how to use it?
Say hello to
EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs. (EditorConfig website)
Let's create a
First, create a file named
.editorconfig and place it in the root folder. The below file is what I use in my development environment.
true [ ] end_of_line = lf indent_style = space indent_size = 4 insert_final_newline = true trim_trailing_whitespace = true [ ] indent_size = 2 [ ] trim_trailing_whitespace = falseroot =
Now, all you have to do is, use the format command in your editor to format your documents when you finish editing. I am using Visual Studio Code. EditorConfig extension for Visual Studio Code supports applying some of the rules(i.e.
trim_trailing_whitespace) on file save. Visit editorconfig.org to find if your editor requires a plugin.
When EditorConfig search for the
.editorconfig file, it will start with the directory of the opened file. Then it will search every parent directory. EditorConfig will stop searching if the root of the file path is found or EditorConfig finds a file with
root = true rule.
EditorConfig reads the file from top to bottom. Due to this, the most recent rules found take precedence over the previous rules.
If you would like to find all available properties and their values, you could find them at the EditorConfig Properties wiki.
*Note: At the time of writing, all EditorConfig properties and values are case-insensitive.*
If I tickled your curiosity with EditorConfig to help maintain consistency, I recommend reading the articles below for more information regarding how to set up a
.editorconfig file for the .Net development workspace.
Did you find this article valuable?
Support Dilan Livera by becoming a sponsor. Any amount is appreciated!