Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EditorConfig 使用和配置 #17

Open
shaozj opened this issue Sep 22, 2017 · 0 comments
Open

EditorConfig 使用和配置 #17

shaozj opened this issue Sep 22, 2017 · 0 comments

Comments

@shaozj
Copy link
Owner

shaozj commented Sep 22, 2017

EditorConfig 使用和配置

EditorConfig 是一套用于统一代码格式的解决方案。简单来说,EditorConfig 可以让代码在不同的编辑器保持一致的代码格式。支持各种主流编辑器和 IDE。

安装

以 sublime 为例,安装 EditorConfig 插件。

当打开一个文件时,EditorConfig插件会在打开文件的目录和其每一级父目录查找.editorconfig文件,直到有一个配置文件root=true。EditorConfig配置文件从上往下读取,并且路径最近的文件最后被读取。匹配的配置属性按照属性应用在代码上,所以最接近代码文件的属性优先级最高。

注意:Windows 用户在项目根目录创建.editorconfig文件,可以先创建“.editorconfig.”文件,系统会自动重名为.editorconfig。

配置文件解析

文件格式

EditorConfig文件使用INI格式。斜杠(/)作为路径分隔符,#或者;作为注释。EditorConfig文件使用UTF-8格式、CRLF或LF作为换行符。

通配符

通配符:

    • 匹配除/之外的任意字符串
  • ** 匹配任意字符串
  • 匹配任意单个字符
  • [name] 匹配name字符
  • [!name] 匹配非name字符
  • {s1,s2,s3} 匹配任意给定的字符串(since 0.11.0)

属性

  • root: 表明是最顶层的配置文件,发现设为true时,才会停止查找.editorconfig文件。

  • indent_style: 设置缩进风格,tab或者空格。tab是hard tabs,space为soft tabs。

  • indent_size: 缩进的宽度,即列数,整数。如果indent_style为tab,则此属性默认为tab_width。

  • tab_width: 设置tab的列数。默认是indent_size。

  • end_of_line: 换行符,lf、cr和crlf

  • charset: 编码,latin1、utf-8、utf-8-bom、utf-16be和utf-16le,不建议使用utf-8-bom。

  • trim_trailing_whitespace: 设为true表示会除去行尾的任意空白字符。

  • insert_final_newline: 设为true表明使文件以一个空白行结尾

推荐配置

root = true

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

[*.md]
trim_trailing_whitespace = false

官网

http://editorconfig.org/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant