让vscode按照eslint进行格式化

hualala 2020-01-11

1.安装eslint依赖
在package.json中用npm安装eslint的依赖

"eslint": "^4.19.1",
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^2.0.0",
"eslint-plugin-html": "^4.0.3",

2.生成eslint配置文件
在项目根目录下建立 .eslintrc.js文件,复制下面的内容到里面

module.exports = {
  "env": {
    "browser": true,
    "commonjs": true,
    "es6": true
  },
  "extends": "eslint:recommended",
  // 在js里面有些时候用到一些全局变量,防止eslint无脑报错
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly",
    "process": false
  },
  "parserOptions": {
    "ecmaVersion": 2018
  },
  "rules": {
    "linebreak-style": [
      "error",
      "unix"
    ],

    "accessor-pairs": 2,
    "arrow-spacing": [2, { "before": true, "after": true }],
    "array-bracket-spacing": [2, "never"],
    "block-spacing": [2, "always"],
    "brace-style": [2, "1tbs", { "allowSingleLine": true }],
    "camelcase": [2, { "properties": "never" }],
    "comma-dangle": [2, "never"],
    "comma-spacing": [2, { "before": false, "after": true }],
    "comma-style": [2, "last"],
    "constructor-super": 2,
    "curly": [2, "multi-line"],
    "dot-location": [2, "property"],
    "eol-last": 2,
    "eqeqeq": [2, "allow-null"],
    "generator-star-spacing": [2, { "before": true, "after": true }],
    "handle-callback-err": [2, "^(err|error)$"],
    "indent": [2, 2, { "SwitchCase": 1 }],
    "jsx-quotes": [2, "prefer-single"],
    "key-spacing": [2, { "beforeColon": false, "afterColon":

相关推荐

hualala / 0评论 2020-03-07
学知不足业精于勤 / 0评论 2020-01-23
out有点man / 0评论 2019-11-05