editorconfig 配置说明

170 阅读1分钟

editorconfig 配置说明

简介

让使用不同编辑器的开发者在共同开发一个项目时遵循编码规范(编码风格),就可以使用EditorConfig插件,会在根目录寻找.editorconfig文件并使用其中定义的编码风格 。

官网地址
配置说明文档

常用编码规范

EditorConfig 支持的常用的编码规范,如下

  • charset: 文件编码。可选值
    • latin1
    • utf-8 一般用这个
    • utf-16be
    • utf-16le
  • indent_style: 缩进类型。可选值
    • space
    • tab
  • indent_size: 缩进数量。可选值
    • 整数 一般设置 2 或 4
    • tab
  • insert_final_newline: 是否在文件的最后插入一个空行。可选值
    • true
    • false
  • end_of_line: 换行符格式。说明见 Wiki: 换行。可选值
    • lf 一般用这个
    • crlf
    • cr
  • trim_trailing_whitespace:是否删除行尾的空格。可选值
    • true
    • false

示例

# http://editorconfig.org

root = true

# 对所有文件生效
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

# 对后缀名为 md 的文件生效
[*.md]
trim_trailing_whitespace = false