Editorconfig

When we’re collaborating with other developers, whether you’re writing JavaScript, C~ or whatever, it’s useful (some may say essential) to create a coding style that all developers adhere to. After all, one of the aims of collaboration is that you shouldn’t really be able to tell who wrote what code just by the code style.

With web development it’s not unusual to enforce code style etc. with eslint & prettier but this is often shown as a warning when things are working against the style or in some cases, these changes are only applied upon committing the source code. It’s be much better if we could have the editor automatically work the same, for things like indent styles (for example).

This is where the .editorconfig comes in. A file you should commit with your source code and is supported by Visual Code, Visual Studio, JetBrains IDE’s etc.

I’ll be honest, the main reason I use the .editorconfig is to configure my editors to use the same indent_size. Here’s a basic .editorconfig file

root=true

[*]
indent_size = 2
end_of_line = lf

Visual Code has an extension available named EditorConfig which can be used to generate a bare bones .editorconfig for you. Visual Studio has a file template, just add a new file to your project using the Add | New Item… context menu and search for editorconfig. Selecting the editorconfig (.NET) will populate the .editorconfig with lots of options set for various .NET languages.

If you have an .editorconfig file in the root of your project it will be applied to all sub-folders unless overridden by another .editorconfig in one or more of these folders.

If you want to override some, but not all options within the root .editorconfig then just put those additions/changes in the file and ensure

root = true

exists in the root level file.

As you’d expect the .editorconfig is read top to bottom, hence if you have a duplicate key later on in the file this will override any previous value.

References

EditorConfig
Create portable, custom editor settings with EditorConfig