美文网首页
vscode eslint配置

vscode eslint配置

作者: 有你有团 | 来源:发表于2021-06-01 09:25 被阅读0次

    vscode使用vetur/eslint插件实现代码的自动化格式和修复

    文件 -》 首选项 -》设置 -》用户 -》setting.json

    {
      "eslint.options": {
        "extensions": [
          ".js",
          ".vue",
          ".html",
          ".ts"
        ]
      },
      "eslint.validate": [
        "javascript",
        "html",
        "vue",
        "typescript"
      ],
      "eslint.codeAction.disableRuleComment": {},
      "eslint.alwaysShowStatus": true,
      // 开启eslint检测
      "eslint.codeAction.showDocumentation": {
        "enable": true
      },
      "emmet.excludeLanguages": [
        "markdown"
      ],
      // 保存fix
      "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
      },
      // 代码缩进
      "editor.tabSize": 2,
      // 保存自动格式化
      "editor.formatOnSave": true,
      // 自动换行
      "editor.wordWrap": "on",
      // 在方法括号间添加空格
      "javascript.format.insertSpaceBeforeFunctionParenthesis": true,
      // html代码格式化
      "vetur.format.defaultFormatter.html": "js-beautify-html",
      "vetur.format.defaultFormatterOptions": {
        "js-beautify-html": {
          "wrap_attributes": "auto"
        },
        "prettyhtml": {
          "printWidth": 100,
          "singleQuote": true,
          "wrapAttributes": false,
          "sortAttributes": false
        },
        "prettier": {
          // 结尾不添加分号
          "semi": false,
          // 强制单引号
          "singleQuote": true,
          // 数组对象结尾不要添加逗号
          "trailingComma": "none"
        }
      }
    }
    
    

    .eslintrc.js配置文件

    module.exports = {
      root: true,
      env: {
        node: true
      },
      extends: [
        'plugin:vue/essential',
        '@vue/standard',
        '@vue/typescript/recommended'
      ],
      parserOptions: {
        ecmaVersion: 2020
      },
      rules: {
        'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
        'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
        'space-before-function-paren': 0,
        // 强制单引号
        'quotes': [2, 'single'],
        // 强制语句末尾的分号
        'semi': [2, 'always'],
        // 强制缩进为2个空格
        'indent': [2, 2],
        // 数组,对象最后不要添加逗号
        'comma-dangle': ['error', 'never'],
        // 最后一行换行结束
        'eol-last': ['error', 'always'],
        //不能有声明后未被使用的变量或参数
        'no-unused-vars': [0, { 'vars': 'all', 'args': 'after-used' }],
        // callback允许使用参数
        'standard/no-callback-literal': 0
      }
    }
    
    

    相关文章

      网友评论

          本文标题:vscode eslint配置

          本文链接:https://www.haomeiwen.com/subject/uyassltx.html