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
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:
Plugins using one of the core implementations for various editors and IDEs exist, including:
- Sublime Text
- 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: