2024-05-05 18:30:39 +00:00
---
2024-05-16 22:15:37 +00:00
title: Editorconfig
2024-05-05 21:16:00 +00:00
description: Using .editorconfig
2024-05-05 18:30:39 +00:00
published: true
2024-08-02 23:25:05 +00:00
date: 2024-08-02T23:15:00.000Z
tags:
2024-05-05 18:30:39 +00:00
editor: markdown
dateCreated: 2024-05-05T18:30:37.455Z
---
2024-05-05 21:02:57 +00:00
# Global
2024-08-02 23:25:05 +00:00
2024-05-05 21:02:57 +00:00
Start your `.editorconfig` file with this:
2024-08-02 23:25:05 +00:00
2024-05-05 18:30:39 +00:00
```editorconfig
root = true
[*]
2024-05-05 18:36:10 +00:00
charset = utf-8
2024-05-05 18:30:39 +00:00
trim_trailing_whitespace = true
end_of_line = lf
2024-05-05 19:07:12 +00:00
insert_final_newline = true
2024-05-06 20:22:27 +00:00
indent_style = tabs
2024-05-05 18:36:10 +00:00
```
2024-08-02 19:54:33 +00:00
> The formatting tool `prettier` adjust auto-formatting styles according to `.editorconfig` but ignores some attributes. This includes `insert_final_newline` which is hard-coded to `true`. See [prettier issue #6360](https://github.com/prettier/prettier/issues/6360#issuecomment-520368783)
> Please ensure you are not setting `insert_final_newline` in any of your language specific settings.
2024-08-02 23:25:05 +00:00
> {.is-info}
2024-08-02 19:54:33 +00:00
2024-05-05 21:03:30 +00:00
And add any additional types you need from below, making sure to separate each section with a new line.
2024-05-05 21:02:57 +00:00
2024-05-05 18:36:10 +00:00
---
2024-05-05 19:07:12 +00:00
2024-05-05 19:16:21 +00:00
# Programming Languages
2024-05-05 18:36:10 +00:00
## Nix
2024-08-02 23:25:05 +00:00
2024-05-05 19:07:12 +00:00
Using nixfmt-rfc-style
2024-08-02 23:25:05 +00:00
2024-05-05 18:36:10 +00:00
```editorconfig
[*.nix]
2024-05-05 19:07:12 +00:00
indent_size = 2
2024-05-06 20:22:27 +00:00
indent_style = space
2024-05-05 19:07:12 +00:00
```
## Python
2024-08-02 23:25:05 +00:00
2024-05-05 19:07:12 +00:00
Using pycodestyle
2024-08-02 23:25:05 +00:00
2024-05-05 19:07:12 +00:00
```editorconfig
[*.{py,py3}]
indent_size = 4
2024-05-06 20:22:27 +00:00
indent_style = space
2024-05-05 19:07:12 +00:00
```
## Node.js
2024-08-02 23:25:05 +00:00
2024-05-05 19:07:12 +00:00
Using prettier
2024-08-02 23:25:05 +00:00
2024-05-05 19:07:12 +00:00
```editorconfig
[*.{cjs,mjs,js,ts,jsx,tsx}]
indent_size = 2
```
## Rust
2024-08-02 23:25:05 +00:00
2024-05-05 19:07:12 +00:00
Using cargo fmt
2024-08-02 23:25:05 +00:00
2024-05-05 19:07:12 +00:00
```editorconfig
[*.rs,Cargo.toml]
indent_size = 4
```
2024-05-06 20:27:57 +00:00
## Go
2024-08-02 23:25:05 +00:00
2024-05-06 20:27:57 +00:00
Using gofmt
2024-08-02 23:25:05 +00:00
2024-05-06 20:27:57 +00:00
```editorconfig
[*.{go,mod}]
indent_size = 4
```
2024-05-05 20:22:31 +00:00
## C and Related
2024-08-02 23:25:05 +00:00
2024-05-05 20:22:31 +00:00
```editorconfig
[*.{c,cpp,cs,h,hpp,C,H,cxx,hxx}]
indent_size = 4
[*.{sln,csproj,vbproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2
```
## Shell Script
2024-08-02 23:25:05 +00:00
2024-05-05 20:22:31 +00:00
```editorconfig
[*.{sh,zsh,bash,bat,cmd,ps1,psm1}]
indent_size = 4
```
2024-05-05 19:16:21 +00:00
# Markup Languages
2024-05-05 19:15:05 +00:00
## Markdown
2024-08-02 23:25:05 +00:00
2024-05-05 19:15:05 +00:00
```editorconfig
[*.md]
indent_size = 2
trim_trailing_whitespace = false
```
2024-05-05 19:16:21 +00:00
2024-05-05 20:22:31 +00:00
## Web
2024-08-02 23:25:05 +00:00
2024-05-05 20:22:31 +00:00
```editorconfig
[*.{htm,html,less,svg,vue}]
indent_size = 2
[*.{css.sass,scss,less}]
indent_size = 2
```
2024-05-05 19:07:12 +00:00
# Data Storage Files
2024-05-05 20:22:31 +00:00
## JSON, YAML
2024-08-02 23:25:05 +00:00
2024-05-05 20:22:31 +00:00
```editorconfig
2024-05-06 20:27:57 +00:00
[*.{json,json5,webmanifest}]
indent_size = 2
```
## YAML
2024-08-02 23:25:05 +00:00
2024-05-06 20:27:57 +00:00
```editorconfig
[*.{yaml,yml}]
indent_style = space
2024-05-05 20:22:31 +00:00
indent_size = 2
```
## TOML
2024-08-02 23:25:05 +00:00
2024-05-05 19:07:12 +00:00
```editorconfig
2024-05-05 20:22:31 +00:00
[*.toml]
indent_style = unset
indent_size = 0
```
## \*RC
2024-08-02 23:25:05 +00:00
2024-05-05 20:22:31 +00:00
```editorconfig
[.*rc]
2024-05-05 19:07:12 +00:00
indent_size = 2
```
## CSV
2024-08-02 23:25:05 +00:00
2024-05-05 19:07:12 +00:00
```editorconfig
[*.csv]
2024-05-05 20:22:31 +00:00
end_of_line = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
2024-05-05 19:07:12 +00:00
indent_size = 0
2024-05-05 20:22:31 +00:00
indent_style = unset
```
## Lockfile
2024-08-02 23:25:05 +00:00
2024-05-05 20:22:31 +00:00
```editorconfig
[*.lock]
indent_style = unset
insert_final_newline = unset
```
## Git
2024-08-02 23:25:05 +00:00
2024-05-05 20:22:31 +00:00
```editorconfig
[*.{diff,patch}]
end_of_line = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
indent_size = unset
indent_style = unset
[.{gitignore,gitreview,gitmodules}]
indent_style = unset
indent_size = 0
```
## Keys
2024-08-02 23:25:05 +00:00
2024-05-05 20:22:31 +00:00
```editorconfig
[*.{asc,key,ovpn,pem}]
end_of_line = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
2024-05-05 19:24:32 +00:00
```
# Build Tool Files
## Make
2024-05-05 20:57:45 +00:00
```editorconfig
2024-05-05 19:24:32 +00:00
[Makefile]
2024-05-06 20:27:57 +00:00
indent_size = 2
2024-08-02 23:25:05 +00:00
```