EditorConfig for PHP Projects
debt(d7/e1/b3/t5)
Closest to 'only careful code review or runtime testing' (d7). Mixed tabs/spaces and CRLF/LF issues are silent during development and only surface during code review when spurious diffs appear, or when CI linting runs phpcs/php-cs-fixer. The detection_hints list editorconfig, phpcs, and php-cs-fixer as tools, but these require deliberate setup — without them, the issue is invisible until a diff review catches whitespace noise.
Closest to 'one-line patch or single-call swap' (e1). The quick_fix explicitly states: add a .editorconfig file to the repository root. This is a single file addition that immediately enforces consistent settings across all editors. The common_mistakes (not committing it, missing plugins) are equally trivial to fix.
Closest to 'localised tax' (b3). The .editorconfig file lives at the project root and imposes a one-time setup cost (committing the file, installing plugins for editors that need them). The ongoing tax is minimal — it passively enforces style without requiring changes to workflow. It applies to web and cli contexts but doesn't shape architecture or slow down work streams.
Closest to 'notable trap — a documented gotcha most devs eventually learn' (t5). The misconception field explicitly states the canonical wrong belief: 'EditorConfig is redundant if the team uses the same IDE.' This is a well-documented gotcha — teams discover it only when a new team member joins with a different OS or editor and introduces CRLF noise or tab/space mixing into diffs.
Also Known As
TL;DR
Explanation
EditorConfig defines per-file-type settings (indent_style, indent_size, end_of_line, charset, trim_trailing_whitespace, insert_final_newline) in a .editorconfig at the project root. Most editors support it natively (PhpStorm, VS Code) or via plugin. For PHP projects: indent_style = space, indent_size = 4 (PSR-12), end_of_line = lf, charset = utf-8. EditorConfig catches whitespace inconsistencies before they reach the linter — a developer on Windows won't accidentally commit CRLF line endings. Pair with .gitattributes text=auto for consistent line endings in the repository itself regardless of developer OS.
Common Misconception
Why It Matters
Common Mistakes
- Not committing .editorconfig — only the developer who created it benefits.
- Not installing the EditorConfig plugin for editors that require it (VS Code, Vim, Emacs).
- Mixing tabs and spaces in a project without .editorconfig enforcing one style.
- Windows CRLF line endings in a Unix project causing spurious diffs — .editorconfig enforces LF.
Code Examples
# No .editorconfig — every developer uses different settings:
# Dev A: 4-space indent, LF
# Dev B: 2-space indent, CRLF
# Dev C: tabs, LF
# git diff shows whitespace changes mixed with real changes in every PR
# .editorconfig:
root = true
[*.php]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
# .editorconfig — consistent editor settings across all contributors
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.php]
indent_style = space
indent_size = 4
[*.{yml,yaml}]
indent_style = space
indent_size = 2
[*.json]
indent_style = space
indent_size = 2
[Makefile]
indent_style = tab
[*.md]
trim_trailing_whitespace = false # markdown uses trailing spaces for line breaks
# Supported by: VS Code (EditorConfig extension), PhpStorm (built-in), Vim, Emacs, Sublime