• Vue项目中配置eslint


    安装

    1. 使用vue/cli创建项目时勾选Linter/Formatter选项。
    2. npm i @babel/core @babel/eslint-parser @vue/cli-plugin-eslint eslint eslint-config-prettier eslint-plugin-prettier eslint-plugin-vue prettier -D
      在这里插入图片描述

    .prettierrc

    {
      "semi": false,
      "arrowParens": "always",
      "singleQuote": true,
      "endOfLine": "auto"
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    .eslintrc.js

    module.exports = {
      root: true,
      env: {
        node: true,
      },
      extends: [
        'plugin:vue/essential',
        'eslint:recommended',
        'plugin:prettier/recommended',
      ],
      parserOptions: {
        parser: '@babel/eslint-parser',
      },
      rules: {
        'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
        'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
        endOfLine: 0,
        'vue/multi-word-component-names': 'off',
        'vue/order-in-components': ['error'],
        'vue/attributes-order': [
          'error',
          {
            order: [
              'DEFINITION',
              'LIST_RENDERING',
              'CONDITIONALS',
              'RENDER_MODIFIERS',
              'GLOBAL',
              'UNIQUE',
              'TWO_WAY_BINDING',
              'OTHER_DIRECTIVES',
              'OTHER_ATTR',
              'EVENTS',
              'CONTENT',
            ],
            alphabetical: false,
          },
        ],
      },
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

    .vscode/settings.json

    根据自己需要进行配置,可以在vscode保存时自动格式化代码,不建议设置全局vscode的settings.json

    {
      "vetur.format.defaultFormatter.html": "prettyhtml",
      "vetur.format.defaultFormatterOptions": {
        "prettyhtml": {
          "printWidth": 100,
          "singleQuote": false,
        }
      },
      "[scss]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
      },
      "[css]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
      },
      "[javascript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
      },
      "[json]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
      },
      "[jsonc]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
      },
      "editor.tabSize": 2,
      "editor.formatOnSave": false,
      "files.autoSave": "off",
      "vetur.validation.template": false,
      "git.enableSmartCommit": true,
      "eslint.autoFixOnSave": true,
      "eslint.validate": [
        "javascript",
        "javascriptreact",
        "html",
        {
          "language": "html",
          "autoFix": true
        },
        {
          "language": "vue",
          "autoFix": true
        },
      ],
      "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
  • 相关阅读:
    【容器网络】跨主通信网络实现方法之VXLAN实现原理
    python之图形用户界面,如何安装wxPython
    SpringBoot项目创建及运行
    【VsCode】VsCode的安装与42个插件大全
    2023/09/10
    【Python编程】四、python字符串
    Mac 环境变量配置(待补充)
    V90伺服驱动器控制(PN版本)
    javacpp 映射
    选择边缘计算网关的五大优势
  • 原文地址:https://blog.csdn.net/Wind_AN/article/details/125510891