Per-Project Whitespace with EditorConfig

By  on  

Standards can change from project to project.  Single quotes or double quotes?  MooTools, Dojo, or micro-frameworks?  And then the question that has started wars:  spaces or tabs?  I'm a tab guy myself but the team that I work on has set a two-space standard.  It's not my preference but it was a team decision so I have to drink the Kool-Aid.  I still want to use my typical tab whitespace on other projects but just this one project should use spaces.  I thought this would be a nightmare but enter EditorConfig, a utility with plugins for several text editors which allows developers to specify settings per project.

Start by creating a .editorconfig and placing it at the root of the project which you'd like to create whitespace for:

touch .editorconfig

Once the file is in place, it's up to you to set the spacing settings per file type as you wish:

# EditorConfig is awesome:

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
end_of_line = lf
insert_final_newline = true

# 4 space indentation
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
indent_style = tab

# Indentation override for all JS under lib directory
indent_style = space
indent_size = 2

So not only can you set spacing per project but you can set them per file too.  I've found EditorConfig to be a lifesaver as I can code per usual without having to think about spaces or tabs.  EditorConfig made my day!

Recent Features

  • By
    How to Create a RetroPie on Raspberry Pi – Graphical Guide

    Today we get to play amazing games on our super powered game consoles, PCs, VR headsets, and even mobile devices.  While I enjoy playing new games these days, I do long for the retro gaming systems I had when I was a kid: the original Nintendo...

  • By
    9 Mind-Blowing Canvas Demos

    The <canvas> element has been a revelation for the visual experts among our ranks.  Canvas provides the means for incredible and efficient animations with the added bonus of no Flash; these developers can flash their awesome JavaScript skills instead.  Here are nine unbelievable canvas demos that...

Incredible Demos

  • By
    Making the Firefox Logo from HTML

    When each new t-shirt means staving off laundry for yet another day, swag quickly becomes the most coveted perk at any tech company. Mozilla WebDev had pretty much everything going for it: brilliant people, interesting problems, awesome office. Everything except a t-shirt. That had to change. The basic...

  • By
    Introducing LazyLoad 2.0

    While improvements in browsers means more cool APIs for us to play with, it also means we need to maintain existing code.  With Firefox 4's release came news that my MooTools LazyLoad plugin was not intercepting image loading -- the images were loading regardless of...


  1. MaxArt

    In Notepad++ you can change the indent behaviour clicking on Preferences / Tab Settings and defining the tab width and characters as a general behaviour or on a per language basis.

    • RC

      Yeah, nearly every editor and IDE worth its salt can do this.

      But you’re missing the point. EditorConfig is most useful in a COLLABORATIVE development project, where you have a multitude of devs and a multitude of IDEs/editors. EditorConfig attempts to establish a common standard for IDE/editors to enforce whitespace rules.

  2. I recently started a repo of my editorconfig, lint config, and sublime text user preferences, this way I always have them and can keep several machines in sync.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!