VSCode、idea、WebStorm 保存自动按照eslint格式化

一. 跨编辑器格式化文件

  1. 给项目添加.editorconfig 配置文件
# https://editorconfig.org
root = true

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

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false

[*.xlsx]
insert_final_newline = false
trim_trailing_whitespace = false
  1. 看项目中package.json文件中是否安装过包eslint,babel-eslint,没有就运行一下npm install --save-dev eslint babel-eslint

二. 使用插件

  1. VSCode 下安装ESLint插件,后重启
    微信截图_20210701164302.png

    setting.json配置文件中的设置
{
    "eslint.validate": [
        "javascript",
        "javascriptreact",
        "html",
        "vue"
    ],
    "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
    }
}
  • WebStorm 安装插件Save Actions并重启,idea 安装插件Save Actionsvue.js并重启
    webstrom插件
idea插件
  • 配置设置file=>setting中


    微信截图_20210702092100.png

    微信截图_20210702092323.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容