EditorConfig是什么
EditorConfig有助于维护跨多种编辑器和IDE的开发项目,有助于开发人员在项目开发过程中保持编码风格一致。EditorConfig包含一个用于定义编码样式的文件以及一个使编辑器可以遵循所定义的文本样式读取文件的文本编辑器插件集合 。EditorConfig 文件具有较好的可读性以及易于与版本控制系统很好地协同工作。
下面是一个例子,用于规定Python和JavaScript文件的行尾和缩进样式。
# 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
EditorConfig文件的操作过程
当打开文件时,EditorConfig插件会在打开的文件的目录中以及每个父目录中查找名为.editorconfig的文件。如果到达根文件路径或找到root = true的EditorConfig文件,将停止对.editorconfig文件的搜索。
从顶部到底部读取EditorConfig文件,按照就近原则,新发现的规则优先。 所匹配的部分EditorConfig中的属性将按读取顺序应用,因此,较近文件中的属性优先。
对于Windows用户:要在Windows资源管理器中创建.editorconfig文件,首先需要创建一个名为.editorconfig的文件,Windows资源管理器将自动将其重命名为.editorconfig。
具体属性标识详见官网链接:EditorConfig官网