第四章-项目约束文件EditorConfig
1.介绍
该章的主角是EditorConfig。就是告诉你的ide这么约束你的项目的。
EditorConfig官网
EditorConfig完整配置属性说明表
好奇,项目根目录下的.editorconfig文件
2.安装EditorConfig插件
不同的IDE都有这个插件,安装上去就好了。
vsCode的EditorConfig for VS Code
3.创建约束文件
在根目录下创建.editorconfig文件
3.1.原代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| root = true
[*] charset=utf-8 end_of_line=lf insert_final_newline=true indent_style=space indent_size=2 max_line_length = 100
[*.{yml,yaml,json}] indent_style = space indent_size = 2
[*.md] trim_trailing_whitespace = false
[Makefile] indent_style = tab
|
3.2.带注释代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| # ↓告诉EditorConfig插件,这是根文件,不用继续往上查找。 root = true
# ↓匹配全部文件。 [*] # ↓使用`utf-8`字符集。 charset=utf-8 # ↓结尾换行符,可选`lf`、`cr`、`crlf`。 end_of_line=lf # ↓在文件结尾插入新行。 insert_final_newline=true # ↓缩进的样式为空格。 indent_style=space # ↓缩进为2。 indent_size=2 # ↓行最大长度为100。 max_line_length = 100
# ↓匹配以`.yml`、`.yaml`、`.json`结尾的文件。 [*.{yml,yaml,json}] indent_style = space indent_size = 2
# ↓匹配以`.md`结尾的文件。 [*.md] # ↓ trim_trailing_whitespace = false
[Makefile] indent_style = tab
|