---
name: configuring-editorconfig
description: Add or fix an .editorconfig file, so every editor uses the same indentation, line endings, charset, and final newline. Use when setting up a repository, when saves change only whitespace, or when the editor and Prettier disagree.
license: MIT
metadata:
author: famiglio
category: tooling
---
# Configuring EditorConfig
Give every editor the same whitespace rules, so files do not change when someone else saves them.
## Prerequisites
- Read the formatter configuration of the project, such as Prettier, Ruff, or `rustfmt`. `.editorconfig` must use the same values.
## Procedure
1. **Read the existing `.editorconfig`.** Keep its values, and add only what is missing.
2. **Add the file.**
- In a project that uses the spellbook configs, run `pnpm dlx @famiglio/sbx init editorconfig`. It installs `@famiglio/editorconfig` and copies its file, or merges it into an existing one.
- Otherwise, copy the file in [`references/famiglio-editorconfig.md`](references/famiglio-editorconfig.md) to `.editorconfig` at the root of the repository, and remove the sections for languages that the project does not use.
3. **Keep these rules:**
- `root=true` at the top, so editors do not read `.editorconfig` files in parent folders.
- `charset=utf-8`, `end_of_line=lf`, `insert_final_newline=true`, and `trim_trailing_whitespace=true` for all files.
- `trim_trailing_whitespace=false` for Markdown, where two trailing spaces make a line break.
- `indent_style=tab` for `Makefile`, which requires tabs.
4. **Match the formatter.** Prettier reads `indent_style`, `indent_size`, `max_line_length`, and `end_of_line` from `.editorconfig`, but its own configuration wins. If the Prettier configuration sets `tabWidth`, `useTabs`, `printWidth`, or `endOfLine`, use the same values in both files.
5. **Tell VS Code users** to install the EditorConfig extension (`editorconfig.editorconfig`). Most other editors read the file without a plugin.
## Verification
```bash
head -n 5 .editorconfig
git diff --check
pnpm exec prettier --check .
```
`.editorconfig` has `root=true` near the top. `git diff --check` reports no trailing whitespace in the changes. Prettier, when the project uses it, finds no file to reformat.
<!-- ‹guest · 2026-12-05› -->
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.