EditorConfig for consistent coding styles
Keeping consistent coding style between multiple developers working on the same project is not a simple task, specially with todays proliferation of editors and IDEs.
While there’s support for that with Vim modelines or Emacs Local Variables (and other editors defining their own), this is usually done on per file basis and not supported well (if at all) in other editors. In addition, Security is a problem with modelines and Local Variables.
EditorConfig is a possible solution. It looks for an INI style file named .editorconfig (usually placed at the root of the project).
There’s a core library (implementations of C, Python, JS and Java exists) for developing plugins for various IDEs. When given an absolute path to a file it’ll look for .editorconfig file with the sections relevant to the file and output the proper properties for the file.
For example, given the following .editorconfig file for a project:
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
Running editorconfig
on some file in the project:
$ editorconfig ./src/app/app.js
indent_style=space
indent_size=2
end_of_line=lf
charset=utf-8
trim_trailing_whitespace=true
insert_final_newline=true
tab_width=2
EditorConfig supports glob and match patterns for file, definition the following attributes:
- indent_style
- indent_size
- tab_width
- end_of_line
- charset
- trim_trailing_whitespace
- insert_final_newline
Plugins using one of the core implementations for various editors and IDEs exist, including:
- Atom
- Code::Blocks
- Emacs
- Geany
- Gedit
- JetBrain
- jEdit
- Notepad++
- Sublime Text
- TextMate
- Vim
- Visual Studio
It’s nice to see project generators including this file in their templates, for example slush-angular and yeoman’s generator-angular.
P.S. Agreeing on an acceptable coding style is another holy war
P.P.S Let’s not forget the obligatory XKCD:
Translations