1.什么是editorconfig
editorconfig
是用来帮助开发者定义和维护代码风格(行尾结束符、缩进风格等)
editorconfig
支持哪些规则?
请自行参考 https://editorconfig.org/
如何在vscode
中使用editorconfig
?
- 在当前项目根目录下添加
.editorconfig
文件 - 安装
EditorConfig
扩展 - 全局安装或局部安装
editorconfig
依赖包(npm install -g editorconfig | npm install -D editorconfig
) - 打开需要格式化的文件并手动格式化代码(
shift alt f
)
简单说明下每一步的作用:
第一步的editorconfig
文件是定义一些格式化规则(此规则并不会被vscode直接解析)
第二步EditorConfig
扩展的作用是读取第一步创建的editorconfig
文件中定义的规则,并覆盖user/workspace settings
中的对应配置(从这我们也可以看出vscode
本身其实是并不直接支持editorconfig
的)
第三步安装editorconfig
依赖包主要是因为EditorConfig
依赖于editorconfig
包,不安装的可能会导致EditorConfig
无法正常解析我们在第一步定义的editorconfig
文件
第四步的作用就是让经过EditorConfig
扩展覆盖后的user/workspace settings
生效
可能会遇到的问题
当 user/workspace setting
中的 files.trimTrailingWhitespace=true
时trim_trailing_whitespace = false
就不会生效了
end_of_line
属性貌似不被支持(可直接修改user/workspace setting
中的files.eol
配置,直接配置成"files.eol": "\n"
即可)
网友评论