vscode配置eslint

先在命令行中安装eslint

 npm install eslint --save-dev 

再在vscode中安装ESlint插件,我觉得是用来配合eslint检查出的错来对vscode中的代码做出提示

再配置setting.json,

"eslint.autoFixOnSave": true,
    "eslint.validate": [
        "javascript",
        "javascriptreact",
        { "language": "html", "autoFix": true },
        { "language": "vue", "autoFix": true }
    ]

然后可以在package.json中配置一些检查规则

"eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "rules": {
      "no-console": "off",
      "no-multiple-empty-lines": [
        1,
        {
          "max": 2
        }
      ],
      "no-mixed-spaces-and-tabs": [
        "error",
        "smart-tabs"
      ],
      "semi": [
        2,
        "always"
      ],
      "indent": [
        1,
        4
      ]
    },
    "parserOptions": {
      "parser": "babel-eslint"
    }
  },

一般来说这样就可以成功,若遇到问题,请自行google

你可能感兴趣的:(前端)