美文网首页
关于.editorconfig文件

关于.editorconfig文件

作者: 爱发抖的小喵喵 | 来源:发表于2020-03-09 22:22 被阅读0次

一、.editorconfig简介

格式化编译代码的格式化风格

.editorconfig格式化高于编译器的格式化规则

二、安装

全局安装

npm install -g editorconfig

项目安装

npm install -D editorconfig
不安装的可能会导致.editorconfig无法正常解析,尚未验证

三、注释语法

使用井号(#)或分号(;)为注释符号,注释需要与注释符号在通一行内

四、匹配文件语法

1.语法

[需要匹配的文件]

2.通配符

*                匹配除/之外的任意字符串
**               匹配任意字符串
?                匹配任意单个字符
[name]           匹配name中的任意一个单一字符
[!name]          匹配不存在name中的任意一个单一字符
{s1,s2,s3}       匹配给定的字符串中的任意一个(用逗号分隔) 
{num1..num2}    匹配num1到num2之间的任意一个整数, 这里的num1和num2可以为正整数也可以为负整数

五、属性和属性值语法

属性 属性值 描述
indent_style tab是硬缩进,space为软缩进 设置缩进风格
indent_size 如果indent_style为tab,则此属性默认为tab_width 用一个整数定义的列数来设置缩进的宽度
tab_width 默认是indent_size 用一个整数来设置tab缩进的列数
end_of_line 值为lf、cr和crlf 设置换行符
charset latin1、utf - 8、utf - 8 - bom(不建议)、utf - 16be和utf - 16le 设置编码
trim_trailing_whitespace boolean 是否去除换行行首的任意空白字符
insert_final_newline 设为true表示使文件以一个空白行结尾
root boolean 是否最顶层

六、vscode编译器使用

vscode默认是不执行.editorconfig, 需要安装 ** EditorConfig for VS Code ** 插件

七、.editoeconfig例子

# editorconfig顶级配置文件,停止向上寻找配置文件
root = true

# 匹配所有文件
[*]
# 缩进样式=空格     【space:空格,tab:tab键】
indent_style = space
# 缩进大小=2
indent_size = 2
# 换行符类型 = lf   【lf,cr,crlf】
end_of_line = lf
# 字符集=utf-8      【latin1、utf - 8、utf - 8 - bom(不建议)、utf - 16be和utf - 16le】
charset = utf-8
# 删除行尾空格 = 是
trim_trailing_whitespace = true
# 插入最后一行=真
insert_final_newline = true

# 匹配markdown文件
[*.md]
# 删除行尾空格 = 否
trim_trailing_whitespace = false

# 匹配package.json文件
[package.json]
# 缩进样式=空格
indent_style = space
# 缩进大小=2
indent_size = 2

相关文章

网友评论

      本文标题:关于.editorconfig文件

      本文链接:https://www.haomeiwen.com/subject/mrzmdhtx.html