EditorConfig Explainer · Guide
Why an .editorconfig section does not match, and where editors disagree
An .editorconfig section that does nothing fails silently: the editor opens the file with its own defaults and says nothing. Four rules explain most of these, and three kinds of line are read differently by different EditorConfig cores, so they work in one editor and not in the next.
1. Braces need a comma
[*.{md}] looks like "every .md file". It is not: braces are a list only when they hold a comma. With one item, {md} is the literal text {md}, braces and all, so the section matches only a name like notes.{md}.
[*.{md}] # matches notes.{md} only
[*.md] # every .md file
[*.{md,mdx}] # .md and .mdx
Numbers are the exception: {1..10} is a range. But only low to high; {10..1} is invalid under the specification and matches nothing, while the npm editorconfig core counts down and matches 1 to 10. Letters have no ranges, so {a..z} is literal text.
2. * stops at a folder
[src/*.js] matches src/index.js and not src/components/button.js, because a single * never crosses a /. Two stars do: [src/**.js] or [src/**/*.js].
3. A slash anchors the name
A name with no /, like [*.js] or [Makefile], matches at any depth below the .editorconfig. A name with a / anywhere is anchored to that file's own folder, so [src/*.js] in the top-level file never matches packages/app/src/a.js. A leading / changes nothing once there is a slash in the middle. A name ending in / matches no file at all: write [dir/**] for everything inside a folder.
4. root = true goes at the very top
Above the first section, root = true tells the editor to stop looking for .editorconfig files in parent folders. Inside a section it is just another key: the core reports root=true for matching files and keeps reading upward. And in a nested file it works all too well: everything under that folder stops reading the files above it, [*] included.
Three lines editors read differently
EditorConfig is a format with several independent implementations (cores). We ran the same random .editorconfig trees through editorconfig-core-py 0.17.1 (the PyPI package) and the npm editorconfig package 4.0.1, and compared both with the specification and its official test suite.
A comment after a value
[*.py] indent_size = 4 # PEP 8
Since specification 0.15 there are no inline comments: everything after the = is the value. The npm core reports indent_size=4 # pep 8, which is not a number, so editors drop the setting. editorconfig-core-py 0.17.1 still strips the comment and reports indent_size=4. Same file, two answers.
A comment after a section header
[*.out] # make editor neutral to .out files insert_final_newline = unset
A section line has to end with ], so this line is invalid. editorconfig-core-py applies the section anyway. The npm core stops reading the file at that line, so the section and every section after it are lost. We found this in a well-known project's .editorconfig (see the sample below).
A backslash before a wildcard
[\*.c] means a file literally named *.c under the specification and in the npm core; editorconfig-core-py 0.17.1 still treats the * as a wildcard and matches every .c file.
How often does this happen?
Across 23,149 random cases the npm core agreed with the specification-following engine behind the explainer on 23,100; every difference was a reversed range. editorconfig-core-py agreed on 22,005; the differences were inline comments (637), escaped wildcards (452) and a negated bracket like [!a] matching a / (55), a point the specification does not settle. Details and the scripts are in the README.
Questions
Why does [*.{md}] match no Markdown files?
Braces need a comma to be a list. With one item, {md} is the literal text {md}, braces included, so the section only matches names like notes.{md}. Write [*.md], or [*.{md,mdx}] for two extensions.
Why does [src/*.js] miss files in subfolders of src?
A single * never crosses a /, so src/*.js only matches files directly in src. Use [src/**.js] or [src/**/*.js]. A name with a slash is also anchored to the folder of its .editorconfig, so [src/*.js] in the top-level file never matches packages/app/src/a.js; [**/src/*.js] does.
Is a # after a value a comment in .editorconfig?
Not since version 0.15 of the specification: it is part of the value. indent_size = 4 # four sets indent_size to 4 # four, which editors ignore. editorconfig-core-py 0.17.1 still strips the comment and reads 4, so the same line works in one editor and not another. Put comments on their own line.
Check yours: paste your .editorconfig files and git ls-files into the EditorConfig Explainer. Each file's settings come back with the line that set them, and each section that matches nothing comes back with a glob that would.