vscode使用editorconfig

EditorConfig 是一个名称为.editorconfig的自定义文件。 文件中的设置用于在基本代码库中维持一致的编码风格和设置,例如缩进样式、选项卡宽度、行尾字符以及编码等,而无需考虑使用的编辑器或 IDE 。 该文件用来定义项目的编码规范,编辑器的行为会与.editorconfig 文件中定义的一致,并且其优先级比编辑器自身的设置要高,这在多人合作开发项目时十分有用而且必要 。 有些编辑器默认支持editorConfig,如webstorm;而有些编辑器则需要安装editorConfig插件,如ATOM、Sublime、VS Code等 。

配置.editorconfig

参考,本人vuex项目的配置

1
2
3
4
5
6
7
8
9
10
// .editorconfig 
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

安装 EditorConfig扩展

在vscode里面安装EditorConfig 插件:

EditorConfig扩展的作用是读取第一步创建的editorconfig文件中定义的规则,并覆盖user/workspace settings中的对应配置 。

全局安装或局部安装

editorconfig依赖包(npm install -g editorconfig | npm install -D editorconfig)
安装editorconfig依赖包主要是因为EditorConfig依赖于editorconfig包,不安装的可能会导致EditorConfig无法正常解析我们在第一步定义的editorconfig文件使用

使用

打开需要格式化的文件并手动格式化代码(shift+alt+f)

(安装完毕一般自动就进行使用)

:转载文章请注明出处,谢谢~