其他分享
首页 > 其他分享> > 项目中的.editorconfig文件是什么?——EditorConfig插件

项目中的.editorconfig文件是什么?——EditorConfig插件

作者:互联网

EditorConfig简介

“EditorConfig帮助开发人员在不同的编辑器和IDE之间定义和维护一致的编码样式。
EditorConfig项目由用于定义编码样式的文件格式和一组文本编辑器插件组成,这些插件使编辑器能够读取文件格式并遵循定义的样式。
EditorConfig文件易于阅读,并且与版本控制系统配合使用。”

不同的开发人员,不同的编辑器,有不同的编码风格,而EditorConfig就是用来协同团队开发人员之间的代码的风格及样式规范化的一个工具,而.editorconfig正是它的默认配置文件。

1. 文件名通配符

通配符 解释
* 匹配任何字符串,路径分隔符(/)除外
** 匹配任何字符串
? 匹配任何单个字符
[name] 匹配名称中的任何单个字符
[!name] 匹配名称以外的任何单个字符
{s1,s2,s3} 匹配给定的任何字符串(用逗号分隔)(从EditorConfig Core 0.11.0开始可用)
{num1..num2} 匹配num1和num2之间的任何整数,其中num1和num2可以是正数或负数

2. 常用属性

3. 官网示例-注释翻译


# top-most EditorConfig file
# 最顶层的editorconfig配置文件
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文件,设置文件字符集为utf-8
[*.{js,py}]
charset = utf-8

# 4 space indentation
# 控制py文件类型的缩进大小为4
[*.py]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
# 设置某中文件的缩进风格为tab (Makefile未指明)
[Makefile]
indent_style = tab

# Indentation override for all JS under lib directory
# 设置在lib目录下所有JS的缩进为2
[lib/**.js]
indent_style = space
indent_size = 2

# Matches the exact files either package.json or .travis.yml
# 设置确切文件 package.json/.travis/.yml的缩进
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

4. 我的.editorconfig

# 告诉EditorConfig插件,这是根文件,不用继续往上查找
root = true

# 匹配全部文件
[*]
# 设置字符集
charset = utf-8
# 缩进风格,可选"space"、"tab"
indent_style = space
# 缩进的空格数
indent_size = 2
# 结尾换行符,可选"lf"、"cr"、"crlf"
end_of_line = lf
# 在文件结尾插入新行
insert_final_newline = true
# 删除一行中的前后空格
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

标签:文件,缩进,indent,插件,style,EditorConfig,true,editorconfig
来源: https://www.cnblogs.com/asahi-front/p/14409374.html