EditorConfig for Consistent Formatting
What you'll learn: How to use .editorconfig files to ensure every developer on your team uses the same indentation, line endings, and file encoding—no matter which editor they prefer.
The Problem EditorConfig Solves
Imagine three developers on your team: one uses VS Code with tabs, another uses Sublime with spaces, and a third uses Vim with different line endings. Every time they commit code, version control shows hundreds of "changes" that are just formatting differences. EditorConfig prevents this chaos.
What is EditorConfig?
EditorConfig is a simple configuration file (.editorconfig) that lives in your project root and tells any compatible editor how to format files. Most modern editors support it natively or through plugins—including VS Code, Sublime, Atom, WebStorm, and even Vim.
Think of it as a universal formatting rulebook that works across all editors, unlike Prettier or ESLint which run as separate tools.
How It Works
Create a .editorconfig file in your project root:
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
[*.{js,css,html}]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
This tells editors: use UTF-8 encoding, Unix line endings (lf), always add a final newline, use 2 spaces for JS/CSS/HTML, and don't trim whitespace in Markdown files.
Why Use Both EditorConfig and Prettier?
EditorConfig handles basic editor behavior (tabs vs. spaces, line endings). Prettier handles complex code formatting (where to break lines, quote styles). They complement each other—EditorConfig sets the foundation, Prettier polishes the details.
Key Takeaway: EditorConfig creates a consistent baseline for file formatting across different editors by configuring indentation, line endings, and encoding at the editor level—before any code formatter runs.