Programming

Why you should be using an EditorConfig file in your project

Advertisements

Let us all face it. It is 2017 and many of us are still fighting over tabs versus spaces! And nobody cares what code style you use, the main concern is that you should be having one across your project. And the fact that it should be consistent across your project. It is your code, so you define the rules. And anyone contributing to it will adhere to them. Tabs versus spaces should be handled by your editor and that is where EditorConfig files come in. All you do is drop a .editorconfig file in your project. In this file, you put some lines which define your configuration for the current project, and the editor applies these settings for this project only.

This is a pretty useful technique for people working in large groups having different favourite editors. This enables everyone to have consistent coding styles across all editors.

Common configurable options

  • indent style
  • indent size
  • end of line characters
  • character set
  • the maximum length of lines
  • trim trailing whitespace

These might sound like trivial things when writing code for a large-scale application. But having an editorconfig file ensures that these settings go along with your project to every place the code gets setup. Which in turn ensures that the editor’s settings do not need to be tweaked in order to have consistent coding styles. Some editors support editorconfig by default. For most of the others, there is a plugin which enables support for editorconfig. Also, you can specify different types of configurations for different file types, and you can even override the settings for a folder by creating another editorconfig in that directory. And if you are looking for more options to configure, there is a wiki with details about the possible ones.

A sample EditorConfig file

# indicate this is the root of the project
root = true

[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
indent_size = 2

[*.html]
indent_size = 4
max_line_length = 80

[*.md]
trim_trailing_whitespace = false
Bash

And that is all you need to know! Go and put a file in your project now. No more fights over tabs vs spaces!

Saransh Kataria

Born in Delhi, India, Saransh Kataria is the brain behind Wisdom Geek. Currently, Saransh is a software developer at a reputed firm in Austin, and he likes playing with new technologies to explore different possibilities. He holds an engineering degree in Computer Science. He also shares his passion for sharing knowledge as the community lead at Facebook Developer Circle Delhi, NCR which is a developer community in Delhi, India.

View Comments

    • Welcome. I also came to know about editorconfig recently. Hence made a post about it.

  • What I miss is a setting like soft_line_wrap = true. This would be very useful in markdown files.

  • I had no idea there was even such a thing. You might want to list that it works, out of the box with Eclipse, and most Jetbrains products either include it or have an easily added plugin for it, and with over a dozen other popular IDEs, via plugins, including XCode, and Visual Studio, there are downloadable plugins.

    Complete list HERE: http://editorconfig.org/#download

    • I do have it mentioned in the post that it works by default for some IDE's and there are plugins for others. Thanks for the comment.

      PS: For some reason, disqus had marked this as spam and so I could not respond to this earlier.

Share
Published by
Saransh Kataria

Recent Posts

Remapping keyboard keys to avoid Carpal Tunnel

I am terrible at optimizing my keyboard layout for anything. But off lately, my little…

1 month ago

Fixing cookies are blocked for a website with shields down on Brave

I recently switched completely to the Brave browser and have set ad blocking to aggressive…

5 months ago

Generating a QR code using Node.js

I was preparing a slide deck for a hackathon and decided to put in a…

6 months ago

How to clear the global npx cache

I have been using npx a lot lately, especially whenever I want to use a…

6 months ago

Copy/Pasting output from the terminal

Manually copy-pasting the output of a terminal command with a mouse/trackpad feels tedious. It is…

7 months ago

How To Get The Hash of A File In Node.js

While working on a project, I wanted to do an integrity check of a file…

8 months ago
Advertisements