2019 / 12 / 14
by John Yuan

EditorConfig 配置文件

为了保证整个项目缩进风格统一,每次新建项目时,我往往会添加一个 .editorconfig 文件,但总是记不住里面的配置项名称,导致每次都要去找官方文档或者查看以前的项目,所以在此记录一个,希望以后找起来会快一点。

以下是我常用的设置,支持的配置项请查看此文档或者官网

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true

[*.{html,js,css}]
tab_width = 4
indent_size = 4
indent_style = space
trim_trailing_whitespace = true

下面是官网给出的一个示例:

# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2