自用的 VSCode Eslint+Prettier+Vetur 配置(持续补充修改中)

一. VSCode安装插件
ESLint
Prettier
Vetur

二. 工程里创建文件.eslintrc.js

/*
 * @Author: your name
 * @Date: 2021-03-30 22:10:31
 * @LastEditTime: 2021-04-17 22:11:10
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \web_page\.eslintrc.js
 */
module.exports = {
    root: true,
    parserOptions: {
        parser: 'babel-eslint',
        sourceType: 'module'
    },
    // 配置的环境
    env: {
        browser: true,
        node: true,
        es6: true,
    },
    extends: ['plugin:vue/recommended', 'eslint:recommended'],
    rules: {
        // 开启 console
        'no-console': 'off',
        // 禁止不必要的 catch 子句
        'no-useless-catch': 'off',
        // 禁止使用异步函数作为 Promise executor
        'no-async-promise-executor': 'off',
        // 可以出现未使用过的变量
        'no-unused-vars': 'off',
        // vue项目中,判断是否为生产环境,如果是的话,就提醒,否则话可以使用debugger
        "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
        // tab缩进为4空格
        "indent": ["off", 4],
        // 关闭下列提醒
        "vue/html-self-closing": "off",
        "vue/html-closing-bracket-newline": "off",
        "vue/max-attributes-per-line": "off",
        "vue/html-indent": "off",
    }
}

三. 打开VSCode设置,配置settings.json
先按步骤打开 setting 界面,
Code --> preferences -->setting (也可以快捷键 command + ,(mac) 直接打开)现在看到的是界面配置模式,点击右上角的红色区域按钮(如下图),可以打开 settings.json 文件。在这里插入图片描述
附录1:我的VSCode配置(2020-08)
保存时自动修复
prettier使用eslint格式化
vetur使用prettier格式化

{
    // vscode默认启用了根据文件类型自动设置tabsize的选项
    "editor.detectIndentation": false,
    // 重新设定tabsize
    "editor.tabSize": 4,
    // #每次保存的时候自动格式化
    "editor.formatOnSave": true,
    // eslint配置项,保存时自动修复错误
    "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
    },
    // 添加 vue 支持
    "eslint.validate": [
        "javascript",
        "javascriptreact",
        "html",
        "vue"
    ],
    //  #让函数(名)和后面的括号之间加个空格
    "javascript.format.insertSpaceBeforeFunctionParenthesis": true,
    // 图标样式(需要安装插件)
    "workbench.iconTheme": "vscode-icons",
    //打开文件不覆盖
    "workbench.editor.enablePreview": false,
    // 设置不同文件使用的格式化配置
    "[html]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[javascript]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
    "[json]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[jsonc]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
    // 对vue的配置
    "[vue]": {
        "editor.defaultFormatter": "octref.vetur"
    },
    "vetur.format.defaultFormatter.css": "prettier",
    "vetur.format.defaultFormatter.postcss": "prettier",
    "vetur.format.defaultFormatter.scss": "prettier",
    "vetur.format.defaultFormatter.less": "prettier",
    "vetur.format.defaultFormatter.stylus": "stylus-supremacy",
    "vetur.format.defaultFormatter.ts": "prettier",
    // vetur 缩进是4
    "vetur.format.options.tabSize": 4,
    "vetur.format.options.useTabs": false,
    // #这个按用户自身习惯选择//格式化.vue中html
    "vetur.format.defaultFormatter.html": "js-beautify-html",
    // #vue组件中html代码格式化样式
    "vetur.format.defaultFormatterOptions": {
        "js-beautify-html": {
            //属性强制折行对齐
            "wrap_attributes": "force-aligned"
        }
    },
    "prettier.vueIndentScriptAndStyle": true,
}

eslint的官方说明

配置说明:https://eslint.bootcss.com/docs/user-guide/configuring#extending-configuration-files

Rules说明:https://eslint.bootcss.com/docs/rules/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值