Why do you need EditorConfig ?

EditorConfig helps maintain consistent coding style across the team of developers, working on the same source code but across different IDEs and Operating systems.

The above sentence means is that the tabs appear as tabs in all the developers’ IDEs, irrespective of the IDE and the OS. The same goes for spaces and especially newlines which are different in different Operating Systems.

It is usually enabled in a project by following these two rules:

  • have a .editorconfig file in the project
  • install a IDE extension/plugin or in some cases the IDEs support it by default

The nice thing about Editorconfig is that once it is configured and installed, it enforces the coding style automatically as you keep typing code, even before you save the file. For example, as you press enter at the end of the line, EditorConfig makes sure the next line is indented with preferred indent and width and any spaces before the newline character are removed.

Most of the other formatters require you to save the file or enable auto-saving and auto-formatting. I don’t like this for multiple reasons:

  • The indentation is not happening automatically as I type new code and get the new line. I have to wait for the file to be auto-saved or saved to see the final style. Some of this problem is alleviated by IDEs which recognize the indentation and auto-indent but it won’t work in all IDEs.
  • Auto-save, especially in webpack-dev-server world causes unnecessary refreshes of my browser.

EditorConfig only helps to maintain coding styles related to indentation, whitespace and charset. For a more advanced opinionated coding style, look into Prettier. I think both EditorConfig and Prettier can live together because of the way they enforce the coding style.

Options available with Editorconfig

  • indent_style →Indentation Style

Possible Values: tab | space

  • indent_size → Indentation Size (in single-spaced characters)

Possible Values — an integer | tab

If indent_size equals to tab, the indent_size will be set to the tab size, which should be tab_width if tab_width is specified, or the tab size set by editor if tab_width is not specified.

  • tab_width → Width of a single tabstop character

Possible Values — a positive integer (defaults indent_size when indent_size is a number)

  • end_of_line → Line ending file format (Unix, DOS, Mac)

Possible Values — lf | crlf | cr

  • charset → File character encoding (See Character Set Support.)

Possible Values: latin1 | utf-8 | utf-16be | utf-16le | utf-8-bom

  • trim_trailing_whitespace → Denotes whether whitespace is removed from the end of lines

Possible Values — true | false

  • insert_final_newline → Denotes whether file should end with a newline

Possible Values — true | false

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store