📚 EditorConfig Deep Learning Guide
A comprehensive guide to mastering EditorConfig for consistent code styling across teams and editors.
📖 Table of Contents
- What is EditorConfig?
- Learning Roadmap
- Core Concepts
- Properties Reference
- Pattern Matching
- Real-World Examples
- Best Practices
- Advanced Techniques
- Troubleshooting
- Resources
🎯 What is EditorConfig?
EditorConfig is a configuration file format that helps maintain consistent coding styles across:
- Different editors (VS Code, IntelliJ, Vim, Sublime, etc.)
- Different developers on the same project
- Different operating systems (Windows, macOS, Linux)
Key Benefits
✅ Universal: Works across 40+ editors
✅ Simple: Human-readable INI format
✅ Automatic: No manual editor configuration needed
✅ Version-controlled: Configuration lives in your repository
✅ Hierarchical: Can override settings at directory levels
🧩 Core Concepts
1. File Structure
# Comment: Top-level EditorConfig file
root = true
# Universal settings (applies to all files)
[*]
property = value
# Language-specific settings
[*.py]
property = value
# Multiple extensions
[*.{js,jsx,ts,tsx}]
property = value
2. How It Works
Project Root
├── .editorconfig ← Root config
├── src/
│ ├── .editorconfig ← Overrides root for src/
│ └── components/
│ └── Button.tsx ← Uses both configs (merged)
└── tests/
└── test.py ← Uses only root config
Resolution Order:
- Editor reads file being edited
- Searches up directory tree for
.editorconfigfiles - Stops when it finds
root = true - Merges all configs (closer files override distant ones)
3. Property Precedence
root = true
[*]
indent_size = 4 # Priority: Low
[*.js]
indent_size = 2 # Priority: Medium (overrides [*])
[lib/**.js]
indent_size = 4 # Priority: High (most specific)
Rule: More specific patterns override general ones.
📋 Properties Reference
Standard Properties
indent_style
Controls indentation character type.
indent_style = space # Use spaces (recommended for most languages)
indent_style = tab # Use tabs (required for Makefiles, common in Go)
When to use tabs:
- Go (language standard)
- Makefiles (required)
- Some C/C++ projects
indent_size
Number of columns for each indentation level.
indent_size = 2 # JavaScript, Ruby, YAML
indent_size = 4 # Python, Java, C#
indent_size = 8 # Linux kernel style
Language Standards:
| Language | Standard | Rationale |
|---|---|---|
| Python | 4 | PEP 8 |
| JavaScript | 2 | Airbnb, Google, Standard JS |
| Java | 4 | Oracle Code Conventions |
| Ruby | 2 | Ruby Style Guide |
| Go | Tab | gofmt default |
tab_width
Display width of tab character (only applies when indent_style = tab).
[*.go]
indent_style = tab
tab_width = 4 # Tabs displayed as 4 spaces wide
end_of_line
Line ending character(s).
end_of_line = lf # Unix/Mac (recommended) - \n
end_of_line = crlf # Windows - \r\n
end_of_line = cr # Old Mac (rare) - \r
Best Practice: Use lf everywhere. Git can handle conversion with .gitattributes.
charset
File character encoding.
charset = utf-8 # Unicode (recommended for all projects)
charset = utf-8-bom # UTF-8 with BOM (avoid unless needed for Windows)
charset = latin1 # ISO-8859-1 (legacy)
charset = utf-16be # UTF-16 Big Endian
charset = utf-16le # UTF-16 Little Endian
Best Practice: Always use utf-8 for new projects.
trim_trailing_whitespace
Remove whitespace at end of lines.
trim_trailing_whitespace = true # Remove (recommended)
trim_trailing_whitespace = false # Keep (needed for Markdown)
Exception: Markdown uses trailing spaces for line breaks.
[*.md]
trim_trailing_whitespace = false
insert_final_newline
Ensure file ends with newline.
insert_final_newline = true # Add newline (POSIX standard)
insert_final_newline = false # Don't add
Why it matters: POSIX defines a text file as ending with newline. Many tools expect this.
max_line_length
Maximum line length (not enforced by all editors).
max_line_length = 80 # Traditional standard
max_line_length = 100 # Modern compromise
max_line_length = 120 # Widescreen-friendly
max_line_length = off # No limit
Language Standards:
- Python (PEP 8): 79 characters (code), 72 (docstrings)
- JavaScript: 80-100 (varies by style guide)
- Go: No strict limit (gofmt wraps intelligently)
🎨 Pattern Matching
Glob Patterns
EditorConfig uses glob patterns to match files.