EditorConfig

转载于EditorConfig官网

前言

EditorConfig工具有助于跨各种编辑器和IDE从事同一项目的多个开发人员维护一致的编码风格。

官网:链接

模板

.editorconfig文件模板,存放于项目根目录:

# 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

使用说明

很多IDE自带EditorConfig支持,无需下载安装该插件,部分IDE需下载插件进行支持,详情请参见官网。以下使用说明摘自官网。

配置文件存放位置:
.editorconfig配置文件存放于项目根目录。

当打开一个文件时,EditorConfig插件会在打开文件的目录和每个父目录中查找一个名为.editorconfig的文件。如果找到根文件路径,或者找到一个root=true.editorconfig文件,那么对.editorconfig文件的搜索将停止。

匹配原则:

*	Matches any string of characters, except path separators (/)
**	Matches any string of characters
?	Matches any single character
[name]	Matches any single character in name
[!name]	Matches any single character not in name
{s1,s2,s3}	Matches any of the strings given (separated by commas) (Available since EditorConfig Core 0.11.0)
{num1..num2}	Matches any integer numbers between num1 and num2, where num1 and num2 can be either positive or negative

关键字释义:
indent_style: set to tab or space to use hard tabs or soft tabs respectively.

indent_size: a whole number defining the number of columns used for each indentation level and the width of soft tabs (when supported). When set to tab, the value of tab_width (if specified) will be used.

tab_width: a whole number defining the number of columns used to represent a tab character. This defaults to the value of indent_size and doesn’t usually need to be specified.

end_of_line: set to lf, cr, or crlf to control how line breaks are represented.

charset: set to latin1, utf-8, utf-8-bom, utf-16be or utf-16le to control the character set.

trim_trailing_whitespace: set to true to remove any whitespace characters preceding newline characters and false to ensure it doesn’t.

insert_final_newline: set to true to ensure file ends with a newline when saving and false to ensure it doesn’t.

root: special property that should be specified at the top of the file outside of any sections. Set to true to stop .editorconfig files search on current file.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值