Editorconfig

My own

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
tab_width = 2
end_of_line = crlf
trim_trailing_whitespace = true
insert_final_newline = true

[*.{php,py}]
indent_size = 4
tab_width = 4

[*.blade.php]
indent_size = 2
tab_width = 2

Grammar

  • indent_style: 缩进风格
    • tab
    • space
    • indent_size: 缩进宽度
    • tab_width: tab 宽度,默认等同于 indent_size
  • end_of_line: 换行符
    • lf
    • cr
    • crlf
  • charset: 编码类型
    • latin1
    • utf-8
    • utf-8-bom
    • utf-16be
    • utf-16le
  • trim_trailing_whitespace: 设为 true 表示会除去换行行首的任意空白字符
  • insert_final_newline: 设为 true 表明使文件以一个空白行结尾
  • root: 表明是最顶层的配置文件,发现设为 true 时,才会停止查找 .editorconfig 文件

Example

通常建议项目最顶层的配置文件设置该值
root = true

表示以 Unix 风格的换行符结尾
[*]
end_of_line = lf
insert_final_newline = true

中括号中的通配符匹配多种类型的文件(这里是 js 和 py)
并设置文件的编码类型
[*.{js,py}]
charset = utf-8

四格缩进
[*.py]
indent_style = space
indent_size = 4

设置缩进类型为 tab
[Makefile]
indent_style = tab

覆盖 lib 目录下的所有 js 文件的缩进宽度为 2 空格
[lib/**.js]
indent_style = space
indent_size = 2

精确匹配 package.json 和 .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

results matching ""

    No results matching ""