crefft Source 2026.10.4

EditorConfig Guide

Source index and context

EditorConfig provides consistent coding styles across editors and IDEs. Create a .editorconfig file in your project root.

Standard Configuration

# EditorConfig - https://editorconfig.org
root = true

# Default for all files
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space

# Python
[*.py]
indent_size = 4
max_line_length = 100

# Ruby
[*.rb]
indent_size = 2
max_line_length = 100

# Go (tabs required)
[*.go]
indent_style = tab
indent_size = 4

# Rust
[*.rs]
indent_size = 4
max_line_length = 100

# C#
[*.cs]
indent_size = 4
max_line_length = 100

# JavaScript/TypeScript
[*.{js,jsx,ts,tsx}]
indent_size = 2
max_line_length = 100

# Web (HTML, CSS)
[*.{html,css,scss,less}]
indent_size = 2

# Data formats
[*.{json,yaml,yml,toml}]
indent_size = 2

# Markdown
[*.md]
indent_size = 4
max_line_length = 80
trim_trailing_whitespace = false

# Shell scripts
[*.sh]
indent_size = 2
max_line_length = 80

# SQL
[*.sql]
indent_size = 2
max_line_length = 80

# Makefiles (tabs required)
[Makefile]
indent_style = tab

# Dockerfiles
[Dockerfile*]
indent_size = 4

# Git config
[.git*]
indent_size = 4

Properties Reference

PropertyValuesDescription
roottrueStop searching for .editorconfig
indent_styletab, spaceHard tabs or soft tabs
indent_sizeintegerNumber of spaces per indent
tab_widthintegerWidth of a tab character
end_of_linelf, cr, crlfLine ending style
charsetutf-8, latin1, etc.Character encoding
trim_trailing_whitespacetrue, falseRemove trailing spaces
insert_final_newlinetrue, falseFile ends with newline
max_line_lengthinteger, offSoft line length limit

Editor Support

EditorConfig is supported natively or via plugins:

EditorSupport
VS CodeNative (settings enable)
JetBrains IDEsNative
Vim/NeovimPlugin: editorconfig-vim
EmacsPlugin: editorconfig-emacs
Sublime TextPlugin: EditorConfig
AtomPlugin: editorconfig

VS Code Settings

Add to .vscode/settings.json:

{
  "editor.formatOnSave": true,
  "files.trimTrailingWhitespace": true,
  "files.insertFinalNewline": true,
  "files.eol": "\n"
}

Relationship with Other Tools

EditorConfig works alongside language-specific formatters:

ToolPurposeEditorConfig Relationship
PrettierFormattingRespects .editorconfig
RuffPython formattingHas own config, sync manually
rustfmtRust formattingHas own config, sync manually
gofmtGo formattingHardcoded (tabs), no config
dotnet formatC# formattingRespects .editorconfig

Syncing with Formatters

Keep EditorConfig and formatter configs in sync:

# pyproject.toml (Ruff)
[tool.ruff]
line-length = 100  # Match .editorconfig max_line_length

[tool.ruff.format]
indent-style = "space"  # Match .editorconfig indent_style

Best Practices

  1. Always set root = true in project root to prevent inheriting from parent directories.

  2. Use LF line endings (end_of_line = lf) for consistency across platforms. Handle Windows in .gitattributes.

  3. Always insert final newline - POSIX standard, prevents diff noise.

  4. Trim trailing whitespace - except in Markdown where trailing spaces can mean line breaks.

  5. Match formatter configs - EditorConfig sets editor behavior, but formatters enforce on save/commit.