EditorConfig: Consistent coding style

If you’ve worked on more than one project in your coding career, you’ll probably have come across different coding styles. While some projects prefer an indentation of four spaces, others might prefer to only use two. Some may even use tabs. Then there’s line-endings, charsets and trailing whitespace.

When you are contributing to a project, it’s a good idea to try and follow the coding style already in place. This makes it more likely that your contributions will get accepted, and is in general a Nice Thing™ to do. So how can we simplify the task of setting up our editor to use a project coding style? Enter: EditorConfig.

EditorConfig

Not sure why the logo is a mouse.

EditorConfig introduces a simple way to synchronize the coding style across different IDEs and editors. Basically, when you open a file, it will look for a .editorconfig-file in the same directory and every parent directory until one is found. It then parses the file and applies the settings to your editor. Simple, eh?

The syntax is simple and the settings fairly self-explanatory. Here’s an example .editorconfig from one of my projects:

There are plugins available for many of the most popular editors and IDEs such as Vim, Emacs, Sublime Text, TextMate etc. Take a look at the official page for a full listing.

My advice: Install the plugin for your editor today and create an .editorconfig for your projects.

Read more from the Software engineering category
SUBSCRIBE TO OUR UPDATES
Menu