ESLint校验规则

124 阅读3分钟

个人记录,仅供参考!!!

项目中个人整理的ESlint校验规则,个别规则需要调整,仅供参考

{
  "root": true,
  "env": {
    "browser": true,
    "es6": true,
    "node": true
  },
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:import/recommended"
  ],
  "settings": {
    "import/resolver": {
      "node": {
        "extensions": [".js", ".android.js", ".ios.js"]
      }
    }
  },
  "globals": {
    // 略
  },
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 2018,
    "sourceType": "module"
  },
  "plugins": [
    "react"
  ],
  "parser": "babel-eslint",
  "rules": {
    "mihome-plugin/no-deprecated-comment": "warn",
    "mihome-plugin/console-warn-only-dev": "warn",
    "no-unused-vars": "warn",
    "no-console": "off",
    "no-undef": "error",
    "no-unreachable": "error",
    "no-extra-semi": "error",
    "no-regex-spaces": "warn",
    "no-mixed-spaces-and-tabs": "warn",
    "no-inner-declarations": "error",
    "no-empty": "off",
    "no-constant-condition": "warn",
    "no-useless-escape": "off",
    "no-case-declarations": "error",
    "no-extra-boolean-cast": "warn",
    "no-prototype-builtins": "off",
    "spaced-comment": ["warn", "always", {
      "block": {
        "balanced": true
      }
    }],
    // "no-param-reassign": "off",
    "comma-dangle": ["warn", "never"],
    "prefer-promise-reject-errors": "off",
    "arrow-parens": ["warn", "as-needed"],
    "prefer-template": "warn",
    // "max-len": "off",
    // "no-shadow": "off",
    "no-else-return": ["warn", {
      "allowElseIf": false
    }],
    "object-curly-newline": "off",
    "no-underscore-dangle": "off",
    "no-use-before-define": ["error", {
      "functions": false,
      "classes": false,
      "variables": false
    }],
    "class-methods-use-this": "off",
    "brace-style": ["warn", "1tbs", {
      "allowSingleLine": true
    }],
    "no-unused-expressions": ["warn", {
      "allowShortCircuit": true,
      "allowTernary": true
    }],
    "padded-blocks": "off",
    "consistent-return": "off",
    "array-callback-return": ["error", {
      "allowImplicit": true
    }],
    "no-plusplus": "off",
    "guard-for-in": "off",
    "new-cap": ["warn", {
      "newIsCap": true,
      "capIsNew": false
    }],
    "indent": ["warn", 2, {
      "SwitchCase": 1
    }],
    "jsx-quotes": ["warn", "prefer-double"],
    "key-spacing": ["warn", {
      "beforeColon": false,
      "afterColon": true,
      "mode": "strict"
    }],
    "new-parens": ["error"],
    "no-whitespace-before-property": ["warn"],
    "no-restricted-syntax": ["error", "WithStatement"],
    "func-call-spacing": ["warn", "never"],
    "comma-spacing": ["warn", {
      "before": false,
      "after": true
    }],
    "computed-property-spacing": ["warn", "never"],
    "semi": ["warn", "always"],
    "no-var": ["warn"],
    "prefer-rest-params": ["error"],
    "object-curly-spacing": ["warn", "always"],
    "arrow-spacing": ["warn", {
      "before": true,
      "after": true
    }],
    "rest-spread-spacing": ["error", "never"],
    "template-curly-spacing": ["warn", "always"],
    "space-before-blocks": ["warn", "always"],
    "space-before-function-paren": ["warn", "never"],
    "space-in-parens": ["warn", "never"],
    "space-infix-ops": ["warn"],
    "space-unary-ops": ["warn", {
      "words": true,
      "nonwords": false
    }],
    "semi-spacing": ["warn", {
      "before": false,
      "after": true
    }],
    "keyword-spacing": ["warn", {
      "before": true,
      "after": true
    }],
    "block-spacing": ["warn", "always"],
    "array-bracket-spacing": ["warn", "never"],
    // "no-multi-spaces": "warn",
    "no-duplicate-imports": "warn",
    "import/no-duplicates": "off",
    "import/no-extraneous-dependencies": ["warn", {
      "packageDir": "./"
    }],
    "import/default": "off",
    "import/no-cycle": "warn",
    "import/no-named-as-default-member": "warn",
    "react/forbid-prop-types": "off",
    "react/require-default-props": "off",
    "react/sort-comp": "off",
    "react/display-name": "off",
    "react/destructuring-assignment": "off",
    "react/prop-types": ["warn", {
      "ignore": ["children", "key", "ref", "navigation"]
    }],
    "react/jsx-filename-extension": "off",
    "react/no-deprecated": "warn",
    "react/no-string-refs": "error",
    "react/no-direct-mutation-state": "error",
    // 新增
    "block-scoped-var": "error",
    "complexity": "warn",
    "default-case": "warn",
    "dot-location": "warn",
    "dot-notation": "warn",
    "eqeqeq": "error",
    "max-classes-per-file": ["warn", 1],
    "no-alert": "error",
    "no-caller": "error",
    "no-empty-function": "warn",
    "no-eq-null": "warn",
    "no-eval": "error",
    "no-extend-native": ["error", { "exceptions": ["Object"] }],
    "no-extra-label": "error",
    "no-floating-decimal": "error",
    "no-invalid-this": "warn",
    "no-labels": "error",
    "no-lone-blocks": "warn",
    "no-multi-spaces": ["error", { "ignoreEOLComments": false }],
    "no-multi-str": "error",
    "no-new-func": "error",
    "no-param-reassign": "warn",
    "no-return-assign": "error",
    "no-return-await": "warn",
    "no-self-compare": "error",
    "no-throw-literal": "error",
    "no-unmodified-loop-condition": "error",
    "no-useless-concat": "warn",
    "no-useless-return": "error",
    "require-await": "error",
    "init-declarations": "error",
    "no-label-var": "error",
    "no-shadow": "error",
    "no-undefined": "warn",
    "implicit-arrow-linebreak": "warn",
    "max-depth": ["warn", 4],
    "max-len" : ["warn", {
      "code": 100, // 默认为80
      "ignoreComments": true,
      "ignoreTrailingComments": true ,
      "ignoreUrls": true 
    }],
    "max-lines": ["error", {
      "max": 800, // 默认为 300
      "skipBlankLines": true
    }],
    "max-lines-per-function": ["warn", {
      "max": 200, // 默认为50
      "skipBlankLines": false,
      "skipComments": false
      }],
    "max-nested-callbacks": ["warn", 10], // 默认10
    "no-lonely-if": "warn",
    "no-mixed-operators": "error",
    "no-multi-assign": "error",
    "no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1 }],
    "no-nested-ternary": "error",
    "no-trailing-spaces": ["error", {
      "skipBlankLines": true,
      "ignoreComments": true
    }],
    "no-unneeded-ternary": "error",
    "nonblock-statement-body-position": ["error", "beside"],
    "quotes": ["error", "single"],
    "max-statements-per-line": ["error", { "max": 1 }], // 默认为1
    "no-confusing-arrow": "error",
    "object-shorthand": "error",
    "prefer-arrow-callback": "error",
    "prefer-const": "error",
    "prefer-destructuring": "error",
    "prefer-spread": "warn",
    "sort-imports": ["warn", {
      "ignoreCase": true,
      "ignoreDeclarationSort": true,
      "ignoreMemberSort": true,
      "memberSyntaxSortOrder": ["none", "all", "multiple", "single"]
    }]
  }
}