Dev tools and workflow · Beginner · 14 min
Share indentation and line-ending rules across editors with EditorConfig
By Padding · Updated 18 Nov 2026
node:26 (Debian) · Node.js 26.13 · editorconfig-checker 7.0.0 (core v4.0.2) · Prettier 3.10.1 · Git
You will have a mixed Python, JavaScript, Makefile and Markdown repository with one .editorconfig that every editor follows, an editorconfig-checker run that passes, and a .gitattributes file that keeps Git storing LF line endings.
On this page
One person's editor inserts tabs, another's inserts four spaces, a third saves files with Windows line endings, and every pull request fills up with whitespace changes nobody meant to make. EditorConfig fixes this with one small file, .editorconfig, at the top of the repository. It says how files of each type should be indented, which line ending to use, which character set, and whether to keep trailing spaces. Most editors read it as soon as you open the project; a few need a plugin.
A file of rules only helps if something checks it, so you will also run editorconfig-checker, a command-line tool that reads the same .editorconfig and reports every file that breaks it. Finally you will add a .gitattributes file so Git agrees on line endings even for someone whose editor ignores EditorConfig.
You will practise in a throwaway repository with a Python script, some JavaScript, a Makefile and a README, with two problems planted in it. The tools run through npx, so nothing is installed globally.
Step 1 · Make a small mixed repository
Create the demo folder and start a Git repository in it:
mkdir -p ~/editorconfig-demo/web ~/editorconfig-demo/scripts
cd ~/editorconfig-demo
git initAdd the files. Some are written with printf so that tabs, trailing spaces and Windows line endings arrive exactly as intended, rather than whatever your terminal does to pasted whitespace:
cat > web/main.js <<'JS'
export function greet(name) {
return `Hello, ${name}`;
}
JS
cat > app.py <<'PY'
def total(prices):
return sum(prices)
PY
printf 'print(total([2, 3])) \n' >> app.py
printf 'build:\n\tnode web/main.js\n' > Makefile
printf '# Demo\n\nFirst line with a hard break \nE kú àárọ̀. Ẹ káàbọ̀.\n' > README.md
printf 'console.log("build");\r\nconsole.log("done");\r\n' > scripts/build.js
git add -AThe last line of app.py ends in three spaces, and scripts/build.js uses CRLF (Windows) line endings. The README line that ends in two spaces is deliberate: in Markdown, two trailing spaces make a line break. The Yorùbá greeting is there to show why the character set matters; text in Yorùbá, Igbo, Amharic or French only survives every editor and laptop intact if the whole team saves as UTF-8.
git add -A matters for the next steps: editorconfig-checker looks at the files Git tracks.
Check it worked
git ls-files
od -c scripts/build.js | head -n 2git ls-files lists the five files. The od -c output shows \r \n at the end of each line of scripts/build.js: that \r is the carriage return a CRLF file carries.
Step 2 · Write the .editorconfig
Create .editorconfig in the repository root:
cat > .editorconfig <<'EC'
# Stop editors looking for .editorconfig files in parent folders
root = true
# Defaults for every file
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
[*.py]
indent_size = 4
# make requires real tab characters before recipe lines
[Makefile]
indent_style = tab
# Two trailing spaces are a line break in Markdown
[*.md]
trim_trailing_whitespace = false
# Older code that the team has not reformatted yet
[legacy/**.js]
indent_size = 4
EC
git add .editorconfigHow it is read:
- An editor opening a file walks up from the file's folder, reading every
.editorconfigit finds, until it reaches one withroot = true. Puttingroot = truein the top file stops a stray.editorconfigin someone's home folder from leaking into the project. - Each
[section]is a glob matched against the file's path. Every matching section applies, from top to bottom, and a later section overrides an earlier one. A Python file gets everything from[*], thenindent_size = 4replaces the 2. - A glob with no
/in it, such as*.py, matches at any depth. A glob with a/, such aslegacy/**.js, is relative to the folder the.editorconfigsits in. end_of_line = lfmeans every line ends with a single line-feed character, which is what Linux, macOS, most tools and most CI runners expect. Windows editors that honour EditorConfig save LF too.
Check it worked
grep -c '^\[' .editorconfigThe command prints 5, one for each section. Open app.py in an editor that reads EditorConfig (see the last step) and press Enter at the end of def total(prices):; the cursor lands four spaces in. In web/main.js it lands two spaces in.
Step 3 · Check the repository with editorconfig-checker
editorconfig-checker is a single Go program. The npm package of the same name is a small wrapper that downloads the right binary for your machine the first time it runs, and passes every argument through to it. The package version (7.0.0) and the core version are separate: EC_VERSION pins the core, so every person and every CI run uses the same checks. Without it the wrapper fetches the newest core.
export EC_VERSION=v4.0.2The export lasts for this terminal session. In a new terminal, run it again.
First ask it which files it would check, without checking them:
npx --yes editorconfig-checker@7.0.0 -version
npx --yes editorconfig-checker@7.0.0 -dry-run-version prints the core version, 4.0.2 or v4.0.2. -dry-run lists the tracked files, including .editorconfig itself. Now run the check:
npx --yes editorconfig-checker@7.0.0The output groups problems by file, with the line numbers and a message for each, something like this:
app.py:
3: Trailing whitespace
scripts/build.js:
1: Wrong line endings or no final newline
2: Wrong line endings or no final newlineThe exact wording can change between core releases; what matters is which files and lines it names. The README is not reported because Markdown is allowed its trailing spaces, and the Makefile is not reported because its recipe line uses a tab, which is what its section asks for.
Check it worked
Run echo $? straight after the check. It prints 1: the checker exits with a non-zero status when it finds a problem, which is what makes it useful in CI.
Step 4 · Fix the problems the checker found
The checker can fix the problems that have one safe answer: trailing whitespace, line endings and the final newline. Indentation, line length and character set problems stay check-only, because fixing them means choosing what the code should look like. Pass the two files so nothing else is touched:
npx --yes editorconfig-checker@7.0.0 -fix app.py scripts/build.js
git add -AIf you prefer to see the change happen, tr -d '\r' < scripts/build.js > build.tmp && mv build.tmp scripts/build.js removes the carriage returns by hand on Linux and macOS.
Run the full check again:
npx --yes editorconfig-checker@7.0.0Check it worked
The check prints nothing and echo $? prints 0. Look at the bytes again:
od -c scripts/build.js | head -n 2The \r characters are gone; each line now ends in \n only.
Step 5 · Make Git agree with a .gitattributes file
EditorConfig only works in editors that read it. Someone on Windows with Git's core.autocrlf set, or with an editor that ignores the file, can still commit CRLF endings. .gitattributes makes Git itself normalise line endings, whatever the person's settings are:
cat > .gitattributes <<'GA'
# Store text files with LF in the repository and check them out with LF
* text=auto eol=lf
# Never touch these
*.png binary
*.jpg binary
*.woff2 binary
GA
git add .gitattributes
git add --renormalize .text=auto lets Git decide per file whether it is text or binary, and normalises text files to LF when they are added. eol=lf also checks them out with LF on every operating system. The binary lines are a safety net for file types Git might misjudge. git add --renormalize . re-applies the new rules to files that were added before the file existed; run it once whenever you change .gitattributes.
If a file genuinely needs CRLF, such as a Windows .bat script, give it its own line: *.bat text eol=crlf.
Check it worked
git ls-files --eolEvery text file shows i/lf (as stored in the index), w/lf (as in your working folder) and attr/text=auto eol=lf. Now try to sneak a CRLF file in:
printf 'export const x = 1;\r\n' > web/extra.js
git add web/extra.js
git ls-files --eol web/extra.jsGit may warn that CRLF will be replaced by LF. The line shows i/lf w/crlf: Git stored LF even though your copy still has CRLF. Replace your copy with the stored one and look again:
rm web/extra.js
git checkout -- web/extra.js
git ls-files --eol web/extra.js
npx --yes editorconfig-checker@7.0.0The line now shows i/lf w/lf, and the checker passes again.
Step 6 · See Prettier follow the same rules
Prettier, the JavaScript, CSS and Markdown formatter, reads .editorconfig when no .prettierrc sets the same option. It maps end_of_line to endOfLine, indent_style to useTabs, indent_size (or tab_width) to tabWidth, and max_line_length to printWidth. A .prettierrc overrides those values, so if a project has both, keep them in step or let .editorconfig be the only place they live.
Add a file under legacy/, where the .editorconfig asks for four spaces, and let Prettier print a formatted copy without changing the file:
mkdir -p legacy
printf 'function add(a,b){return a+b}\n' > legacy/add.js
npx --yes prettier@3.10.1 legacy/add.js
npx --yes prettier@3.10.1 --no-editorconfig legacy/add.jsCheck it worked
The first command prints return a + b; indented by four spaces, because the [legacy/**.js] section applies. The second, with --no-editorconfig, uses Prettier's own default of two spaces. Your editor, the checker and the formatter now take their settings from one file.
Note that Prettier stops looking for .editorconfig at the project root (the folder with .git), even when root = true is missing.
Step 7 · Get every editor on the team reading it
Many editors and code hosts read .editorconfig with no plugin, including JetBrains IDEs (IntelliJ IDEA, PyCharm, WebStorm, Rider), Visual Studio, Xcode, Neovim, Vim, Emacs, Helix, Nova and BBEdit. GitHub and GitLab use it when they display files, so tab widths look right in code review.
Visual Studio Code, VSCodium, Sublime Text, Notepad++ and Eclipse need a plugin. For VS Code, install the official extension from the Extensions view, or from a terminal:
code --install-extension EditorConfig.EditorConfigTo prompt teammates to install it, list EditorConfig.EditorConfig in the project's .vscode/extensions.json, as the VS Code team setup tutorial shows.
Settings in .editorconfig win over the editor's own preferences for the files they match, so nobody needs to change their personal settings. Add the same npx check to CI so a file that slips through an editor without support is caught before it is merged. If teammates work on low-end laptops or prepaid data, the checker is a single small binary downloaded once and cached, so it costs little to run on every push.
Check it worked
Open the Makefile in your editor, put the cursor at the start of the node web/main.js line, and press Tab: your editor inserts a tab character (in VS Code the status bar shows "Tab Size" rather than "Spaces"). In app.py, Tab inserts four spaces. If either does not happen, your editor is not reading the file and needs the plugin above.
When you have finished, remove the demo:
cd ~
rm -rf ~/editorconfig-demoNext steps
- Share settings, tasks and recommended extensions for a team in Set up VS Code for a team project.
- Add linting and formatting on top of the shared whitespace rules in Lint and format JavaScript and TypeScript with ESLint and Prettier.
- Run
npx editorconfig-checkeron every push with your first GitHub Actions workflow. - Check your own Git settings, including
core.autocrlf, in Install and configure Git.
Related tutorials
- Set up VS Code for a team project with workspace settings, tasks and recommended extensionsYou will have a small Node.js project whose committed .vscode folder gives every teammate the same formatter, extension prompts, test and lint tasks and a working debug configuration.
- Lint and format JavaScript and TypeScript with ESLint 10 and PrettierYou will have a small TypeScript project where ESLint 10 with type-aware rules catches a real unawaited-promise bug, Prettier owns the formatting, npm scripts run both, and a Git hook checks only the files you stage.
- How to Install and Configure GitYou will install Git 2.53 from Ubuntu 26.04's own packages, set your name and email, make main the default branch, choose an editor and a few safe defaults, use a different email for work projects, and create an SSH key to use with GitHub.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials