.eslintrc.js 规则

常用规则
module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: [
    "plugin:vue/recommended",
    "plugin:vue/vue3-recommended",
    "plugin:vue/vue3-essential",
    "eslint:recommended",
    "@vue/typescript/recommended",
  ],
  parserOptions: {
    ecmaVersion: 2020
  },
  rules: {
    'prettier/prettier': 0,
    "@typescript-eslint/no-explicit-any": 0,
    "vue/attributes-order": 2,
    "vue/max-attributes-per-line": [2, { // 强制标签每行最大属性数
      "singleline": 10,
      "multiline": {
        "max": 1,
        "allowFirstLine": false
      }
    }],
    "vue/html-self-closing": [2, { // 强制使用闭合标签
      "html": {
        "void": "any",
        "normal": "any",
        "component": "any"
      },
      "svg": "any",
      "math": "any"
    }],
    "vue/singleline-html-element-content-newline": 0, //单行元素换行符
    "vue/multiline-html-element-content-newline": 0, //多行元素换行符
    "vue/name-property-casing": [2, "PascalCase"], // vue组件name强制使用驼峰命名
    "vue/html-closing-bracket-newline": 0, // 可以在便签右便签使用换行符
    "vue/no-side-effects-in-computed-properties": 0, // 允许计算属性中出现副作用
    "vue/no-use-v-if-with-v-for": 0, // 允许v-for 和 v-if 作用在同一元素上
    'accessor-pairs': 2, // 强制 getter 和 setter 在对象中成对出现
    'arrow-spacing': [2, {
      'before': true,
      'after': true
    }], // 强制箭头函数的箭头前后使用一致的空格
    'block-spacing': [2, 'always'], // 禁止或强制在代码块中开括号前和闭括号后有空格 (要求使用一个或多个空格)
    'brace-style': [2, '1tbs', {
      'allowSingleLine': true
    }], // if while function 后面的{必须与if在同一行,java风格。
    'camelcase': [2, {
      'properties': 'always'
    }], //强制驼峰法命名
    'comma-spacing': [2, {
      'before': false,
      'after': true
    }], // 控制逗号前后的空格
    'comma-style': [2, 'last'], // 控制逗号在行尾出现还是在行首出现
    'dot-location': [2, 'property'],
    'eol-last': 2, // 文件末尾强制换行
    'eqeqeq': [2, 'allow-null'], // 使用 === 替代 ==
    'indent': [2, 2, {
      'SwitchCase': 1
    }], //缩进风格
    // JSX 属性中一致使用双引号或单引号
    'jsx-quotes': [2, 'prefer-single'],
    //对象字面量中冒号的前后空格
    'key-spacing': [2, {
      'beforeColon': false,
      'afterColon': true
    }],
    'keyword-spacing': [2, {
      'before': true,
      'after': true
    }], // 强制在关键字前后使用一致的空格
    //函数名首行大写必须使用new方式调用,首行小写必须用不带new方式调用
    'new-cap': [2, {
      'newIsCap': true,
      'capIsNew': false
    }],
    'new-parens': 2, //new时必须加小括号
    'no-array-constructor': 2, //禁止使用数组构造器
    'no-caller': 2, //禁止使用arguments.caller或arguments.callee
    'no-console': 0, //可以使用console
    'no-debugger': 0, //禁止使用debugger
    'no-empty-character-class': 0, //正则表达式中的[]内容不能为空
    'no-empty-pattern': 0,
    'no-eval': 0, //禁止使用eval
    'no-extend-native': 2, //禁止扩展native对象
    'no-extra-bind': 2, //禁止不必要的函数绑定
    'no-extra-parens': [2, 'functions'], //禁止非必要的括号
    'no-floating-decimal': 2, //禁止省略浮点数中的0 .5 3.
    'no-implied-eval': 2, //禁止使用隐式eval
    'no-label-var': 2, //label名不能与var声明的变量名相同
    'no-lone-blocks': 2, //禁止不必要的嵌套块
    'no-multi-spaces': 2, //不能用多余的空格
    'no-multi-str': 2, // 禁止使用多行字符串
    'no-multiple-empty-lines': [2, {
      'max': 2
    }], //空行最多不能超过2行
    'no-new-object': 2, //禁止使用new Object()
    'no-new-require': 2, //禁止使用new require
    'no-new-wrappers': 2, // 禁止对 String,Number 和 Boolean 使用 new 操作符
    'no-obj-calls': 0, //不能调用内置的全局对象,比如Math() JSON()
    'no-return-assign': [2, 'except-parens'], //return 语句中不能有赋值表达式
    'no-sequences': 2, //禁止使用逗号运算符
    'no-spaced-func': 2, //函数调用时 函数名与()之间不能有空格
    'no-sparse-arrays': 0, //禁止稀疏数组, [1,,2]
    'no-trailing-spaces': 2, //一行结束后面不要有空格
    'no-unexpected-multiline': 0, //避免多行表达式
    'no-unmodified-loop-condition': 0, //检查引用是否在循环中被修改
    'no-unneeded-ternary': 2, //禁止不必要的三元表达式 var isYes = answer === 1 ? true : false;
    'no-unsafe-finally': 0, // 禁止在 finally 语句块中出现控制流语句
    'no-useless-call': 2, //禁止不必要的call和apply
    'no-useless-computed-key': 0, // 禁止在对象中使用不必要的计算属性
    'no-useless-constructor': 2, //可以在不改变类的工作方式的情况下安全地移除的类构造函数
    'no-whitespace-before-property': 0,
    'one-var': 0, //禁止连续声明
    'operator-linebreak': [2, 'after', {
      'overrides': {
        '?': 'before',
        ':': 'before'
      }
    }], //换行时运算符在行尾还是行首
    'padded-blocks': 0, //块语句内行首行尾是否要空行
    'quotes': [2, 'single', {
      'avoidEscape': true,
      'allowTemplateLiterals': true
    }], // 强制使用一致的反勾号、双引号或单引号
    'semi': [2, 'never'], //语句强制分号结尾
    'semi-spacing': [2, {
      'before': false,
      'after': true
    }], //分号前后空格
    'space-before-blocks': [2, 'always'], //不以新行开始的块{前面要不要有空格
    'space-before-function-paren': [2, 'never'], //函数定义时括号前面要不要有空格
    'space-in-parens': [2, 'never'], //小括号里面要不要有空格
    'space-infix-ops': 2, //中缀操作符周围要不要有空格
    'space-unary-ops': [2, {
      'words': true,
      'nonwords': false
    }], //一元运算符的前/后要不要加空格
    'spaced-comment': [2, 'always'], // 强制在注释中 // 或 /* 使用一致的空格
    'template-curly-spacing': [2, 'never'], // 要求或禁止模板字符串中的嵌入表达式周围空格的使用
    'yoda': [2, 'never'], //禁止尤达条件
    'prefer-const': 2, // 要求使用 const 声明那些声明后不再被修改的变量
    'object-curly-spacing': [2, 'always', {
      objectsInObjects: false
    }], //大括号内是否允许不必要的空格
    'array-bracket-spacing': [2, 'never'] //是否允许非空数组里面有多余的空格
  }
};
项目曾用规则
module.exports = {
  root: true,
  parserOptions: {
    parser: "babel-eslint",
    sourceType: "module"
  },
  env: {
    browser: true,
    node: true,
    es6: true
  },
  extends: ["plugin:vue/recommended", "eslint:recommended"],

  // add your custom rules here
  //it is base on https://github.com/vuejs/eslint-config-vue
  rules: {
    "vue/max-attributes-per-line": [
      2,
      {
        singleline: 10,
        multiline: {
          max: 1,
          allowFirstLine: false
        }
      }
    ],// 强制标签每行最大属性数
    "vue/singleline-html-element-content-newline": "off",//单行元素换行符
    "vue/multiline-html-element-content-newline": "off",//多行元素换行符
    "vue/name-property-casing": ["error", "PascalCase"],// vue组件name强制使用驼峰命名
    "vue/no-v-html": "off",
    "accessor-pairs": 2, // 强制 getter 和 setter 在对象中成对出现
    "arrow-spacing": [
      2,
      {
        before: true,
        after: true
      }
    ],// 强制箭头函数的箭头前后使用一致的空格
    "block-spacing": [2, "always"], // 禁止或强制在代码块中开括号前和闭括号后有空格 (要求使用一个或多个空格)
    "brace-style": [
      2,
      "1tbs",
      {
        allowSingleLine: true
      }
    ],// if while function 后面的{必须与if在同一行,java风格。
    camelcase: [
      0,
      {
        properties: "always"
      }
    ], //强制驼峰法命名
    "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: ["error", "always", { null: "ignore" }], // 使用 === 替代 ==
    "generator-star-spacing": [
      2,
      {
        before: true,
        after: true
      }
    ],
    "handle-callback-err": [2, "^(err|error)$"],
    indent: [
      0,
      2,
      {
        SwitchCase: 1
      }
    ], //缩进风格
    "jsx-quotes": [2, "prefer-single"],
    "key-spacing": [
      2,
      {
        beforeColon: false,
        afterColon: true
      }
    ],//对象字面量中冒号的前后空格
    "keyword-spacing": [
      2,
      {
        before: true,
        after: true
      }
    ],// 强制在关键字前后使用一致的空格
    "new-cap": [
      2,
      {
        newIsCap: true,
        capIsNew: false
      }
    ],//函数名首行大写必须使用new方式调用,首行小写必须用不带new方式调用
    "new-parens": 2,//new时必须加小括号
    "no-array-constructor": 2,//禁止使用数组构造器
    "no-caller": 2,//禁止使用arguments.caller或arguments.callee
    "no-console": "off",//可以使用console
    "no-class-assign": 2,
    "no-cond-assign": 2,
    "no-const-assign": 2,
    "no-control-regex": 0,
    "no-delete-var": 2,
    "no-dupe-args": 2,
    "no-dupe-class-members": 2,
    "no-dupe-keys": 2,
    "no-duplicate-case": 2,
    "no-empty-character-class": 2,//正则表达式中的[]内容不能为空
    "no-empty-pattern": 2,
    "no-eval": 2,//禁止使用eval
    "no-ex-assign": 2,
    "no-extend-native": 2, //禁止扩展native对象
    "no-extra-bind": 2,//禁止不必要的函数绑定
    "no-extra-boolean-cast": 2,
    "no-extra-parens": [2, "functions"], //禁止非必要的括号
    "no-fallthrough": 2,
    "no-floating-decimal": 2,//禁止省略浮点数中的0 .5 3.
    "no-func-assign": 2,
    "no-implied-eval": 2,//禁止使用隐式eval
    "no-inner-declarations": [2, "functions"],
    "no-invalid-regexp": 2,
    "no-irregular-whitespace": 0,
    "no-iterator": 2,
    "no-label-var": 2, //label名不能与var声明的变量名相同
    "no-labels": [
      2,
      {
        allowLoop: false,
        allowSwitch: false
      }
    ],
    "no-lone-blocks": 2,//禁止不必要的嵌套块
    "no-mixed-spaces-and-tabs": 2,
    "no-multi-spaces": 2,//不能用多余的空格
    "no-multi-str": 2,// 禁止使用多行字符串
    "no-multiple-empty-lines": [
      2,
      {
        max: 1
      }
    ],//空行最多不能超过1行
    "no-native-reassign": 2,
    "no-negated-in-lhs": 2,
    "no-new-object": 2,//禁止使用new Object()
    "no-new-require": 2,//禁止使用new require
    "no-new-symbol": 2,
    "no-new-wrappers": 2,// 禁止对 String,Number 和 Boolean 使用 new 操作符
    "no-obj-calls": 2,//不能调用内置的全局对象,比如Math() JSON()
    "no-octal": 2,
    "no-octal-escape": 2,
    "no-path-concat": 2,
    "no-proto": 2,
    "no-redeclare": 2,
    "no-regex-spaces": 2,
    "no-return-assign": [2, "except-parens"],//return 语句中不能有赋值表达式
    "no-self-assign": 2,
    "no-self-compare": 2,
    "no-sequences": 2,//禁止使用逗号运算符
    "no-shadow-restricted-names": 2,
    "no-spaced-func": 2,//函数调用时 函数名与()之间不能有空格
    "no-sparse-arrays": 2,//禁止稀疏数组, [1,,2]
    "no-this-before-super": 2,
    "no-throw-literal": 2,
    "no-trailing-spaces": 2,//一行结束后面不要有空格
    "no-undef": 2,
    "no-undef-init": 2,
    "no-unexpected-multiline": 2,//避免多行表达式
    "no-unmodified-loop-condition": 2, //检查引用是否在循环中被修改
    "no-unneeded-ternary": [
      2,
      {
        defaultAssignment: false
      }
    ],//禁止不必要的三元表达式 var isYes = answer === 1 ? true : false;
    "no-unreachable": 2,
    "no-unsafe-finally": 2,// 禁止在 finally 语句块中出现控制流语句
    "no-unused-vars": [
      2,
      {
        vars: "all",
        args: "none"
      }
    ],
    "no-useless-call": 2, //禁止不必要的call和apply
    "no-useless-computed-key": 2, // 禁止在对象中使用不必要的计算属性
    "no-useless-constructor": 2,//可以在不改变类的工作方式的情况下安全地移除的类构造函数
    "no-useless-escape": 0,
    "no-whitespace-before-property": 2,
    "no-with": 2,
    "one-var": [
      2,
      {
        initialized: "never"
      }
    ], //禁止连续声明
    "operator-linebreak": [
      2,
      "after",
      {
        overrides: {
          "?": "before",
          ":": "before"
        }
      }
    ], //换行时运算符在行尾还是行首
    "padded-blocks": [2, "never"], //块语句内行首行尾是否要空行
    quotes: [
      0,
      "single",
      {
        avoidEscape: true,
        allowTemplateLiterals: true
      }
    ], // 强制使用一致的反勾号、双引号或单引号
    semi: [0, "never"],
    "semi-spacing": [
      2,
      {
        before: false,
        after: true
      }
    ],//分号前后空格
    "space-before-blocks": [2, "always"],//不以新行开始的块{前面要不要有空格
    "space-before-function-paren": [2, "never"],//函数定义时括号前面要不要有空格
    "space-in-parens": [2, "never"],//小括号里面要不要有空格
    "space-infix-ops": 2,//中缀操作符周围要不要有空格
    "space-unary-ops": [
      2,
      {
        words: true,
        nonwords: false
      }
    ],//一元运算符的前/后要不要加空格
    "spaced-comment": [
      0,
      "always",
      {
        markers: [
          "global",
          "globals",
          "eslint",
          "eslint-disable",
          "*package",
          "!",
          ","
        ]
      }
    ], // 强制在注释中 // 或 /* 使用一致的空格
    "template-curly-spacing": [2, "never"],// 要求或禁止模板字符串中的嵌入表达式周围空格的使用
    "use-isnan": 2,
    "valid-typeof": 2,
    "wrap-iife": [2, "any"],
    "yield-star-spacing": [2, "both"],
    yoda: [2, "never"],//禁止尤达条件
    "prefer-const": 2,// 要求使用 const 声明那些声明后不再被修改的变量
    "no-debugger": process.env.NODE_ENV === "production" ? 2 : 0, //禁止使用debugger
    "object-curly-spacing": [
      2,
      "always",
      {
        objectsInObjects: false
      }
    ], //大括号内是否允许不必要的空格
    "array-bracket-spacing": [2, "never"], //是否允许非空数组里面有多余的空格
    "vue/html-closing-bracket-spacing": 0,// 强制使用闭合标签
    "vue/attribute-hyphenation": 0,
    "vue/html-self-closing": 0,// 强制使用闭合标签
    "vue/attributes-order": 0
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值