til

Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as an open source contributor and product manager

View project on GitHub

Use EditorConfig

EditorConfig is a magnificent tool.

It lets you control aspect of file types such as:

  • Encoding (charset)
  • Line endings (end_of_line) and (trim_trailing_whitespace)
  • Line length (max_line_length)
  • File ending (insert_final_newline)
  • Indentation style (indent_style)
  • Indentation size (indent_size)

:point_right: Do note that all implementations might not support all properties.

The properties can be specified for file types:

All files:

[*]
# properties

Or file patterns:

[*.{js,py}]
# properties

And finally:

You can use it globally on a project basis, by specifying if you file is the root in your project by adding the file: .editorconfig to your project directory.

# top-most EditorConfig file
root = true

And you can then add the global definition (.editorconfig) to your $HOME directory.

It integrates with most editors like Visual Studio Code, Sublime Text, Atom or Vim, check the list on the EditorConfig site.

Do note that the rule of thumb is not to change everything, but just the new adjustments, when you change or add a property, because this could cause misleading file diffs and hence commits.

If you want to change everything according to your EditorConfig property settings, check out eclint (Editor Config Linter), see my TIL on eclint. Do note eclint is no longer actively maintained so alternatives like ec (editorconfig-checker).

You can also enable use of EditorConfig for GitHub Actions, see my TIL on EditorConfig GitHub Action

References