.eslintrc.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. module.exports = {
  2. extends: ['plugin:vue/essential'],
  3. plugins: ['vue-libs'],
  4. parserOptions: {
  5. parser: require.resolve('babel-eslint'),
  6. ecmaVersion: 2017,
  7. sourceType: 'module'
  8. },
  9. env: {
  10. es6: true,
  11. node: true
  12. },
  13. globals: {
  14. document: false,
  15. navigator: false,
  16. window: false
  17. },
  18. rules: {
  19. // 0 禁用此规则 1 不符合规则即给出警告 2 不符合规则即报错
  20. 'accessor-pairs': 2,// 在对象中使用getter/setter
  21. 'arrow-spacing': [2, { 'before': true, 'after': true }],// 箭头函数前后括号
  22. 'block-spacing': [2, 'always'],// 块级作用域缩进 https://eslint.org/docs/rules/block-spacing#rule-details
  23. 'brace-style': [2, '1tbs', { 'allowSingleLine': true }],// 大括号风格,允许写在一行 https://eslint.org/docs/rules/brace-style#require-brace-style-brace-style
  24. // 'camelcase': [2, { 'properties': 'never' }],// 强制驼峰命名法
  25. 'comma-dangle': [2, 'never'],// 对象字面量项尾不能有逗号
  26. 'comma-spacing': [2, { 'before': false, 'after': true }],// 逗号前后的空格
  27. 'comma-style': [2, 'last'],// 逗号风格,换行时在行首还是行尾
  28. 'constructor-super': 2,// 非派生类不能调用super,派生类必须调用super
  29. 'curly': [2, 'multi-line'],// 块级作用域可以不带大括号 https://eslint.org/docs/rules/curly#require-following-curly-brace-conventions-curly
  30. 'dot-location': [2, 'property'],// 对象访问符的位置,换行的时候在行首 https://eslint.org/docs/rules/dot-location#enforce-newline-before-and-after-dot-dot-location
  31. 'eol-last': 2,// 文件以单一的换行符结束
  32. 'eqeqeq': [0, 'allow-null'], // 必须使用全等
  33. 'generator-star-spacing': [2, { 'before': true, 'after': true }],// generate函数的前后空格
  34. 'handle-callback-err': [2, '^(err|error)$' ],// nodejs函数处理错误
  35. // 'indent': [2, 2, { 'SwitchCase': 1 }],// 缩进风格,switch缩进风格
  36. 'indent': ['error', "tab", {SwitchCase: 1, flatTernaryExpressions: false}],//一个缩进必须用四个空格替代
  37. 'jsx-quotes': [2, 'prefer-single'],// jsx使用单引号
  38. 'key-spacing': [2, { 'beforeColon': false, 'afterColon': true }],// 对象字面量中冒号添加后空格
  39. 'keyword-spacing': [2, { 'before': true, 'after': true }],// 关键字前后空格
  40. 'new-cap': [2, { 'newIsCap': true, 'capIsNew': false }],// 新建对象实例首字母必须大写
  41. 'new-parens': 2,// new时必须加小括号
  42. 'no-array-constructor': 2,// 禁止使用数组构造器 https://eslint.org/docs/rules/no-array-constructor#rule-details
  43. 'no-caller': 2, // 禁止使用arguments.caller或arguments.callee
  44. 'no-class-assign': 2, // 禁止给类赋值
  45. 'no-cond-assign': 2,// 禁止在条件表达式中使用赋值语句
  46. 'no-const-assign': 2,//禁止修改const声明的变量
  47. 'no-control-regex': 2,//禁止在正则表达式中使用控制字符
  48. 'no-delete-var': 2,//不能对var声明的变量使用delete操作符
  49. 'no-dupe-args': 2,//函数参数不能重复
  50. 'no-dupe-class-members': 2, //对象成员不能重复
  51. 'no-dupe-keys': 2,//在创建对象字面量时不允许键重复
  52. 'no-duplicate-case': 2,//switch中的case标签不能重复
  53. 'no-empty-character-class': 2,//正则表达式中的[]内容不能为空
  54. 'no-empty-pattern': 2,// https://eslint.org/docs/rules/no-empty-pattern#version
  55. 'no-eval': 2,//禁止使用eval
  56. 'no-ex-assign': 2,//禁止给catch语句中的异常参数赋值
  57. 'no-extend-native': 2,//禁止扩展native对象
  58. 'no-extra-bind': 2,//禁止不必要的函数绑定
  59. 'no-extra-boolean-cast': 2,//禁止不必要的bool转换
  60. 'no-extra-parens': [2, 'functions'],//禁止非必要的括号
  61. 'no-fallthrough': 2,//禁止switch穿透
  62. 'no-floating-decimal': 2,//禁止省略浮点数中的0 .5 3.
  63. 'no-func-assign': 2,//禁止重复的函数声明
  64. 'no-implied-eval': 2,////禁止使用隐式eval
  65. 'no-inner-declarations': [2, 'functions'],//禁止在块语句中使用声明(变量或函数)
  66. 'no-invalid-regexp': 2,//禁止无效的正则表达式
  67. 'no-irregular-whitespace': 2,//不能有不规则的空格
  68. 'no-iterator': 2,//禁止使用__iterator__ 属性
  69. 'no-label-var': 2,//label名不能与var声明的变量名相同
  70. 'no-labels': [2, { 'allowLoop': false, 'allowSwitch': false }],
  71. 'no-lone-blocks': 2,//禁止标签声明
  72. 'no-mixed-spaces-and-tabs': 0,//禁止混用tab和空格
  73. 'no-multi-spaces': [2, { "ignoreEOLComments": true }],//不能用多余的空格
  74. 'no-multi-str': 2,//字符串不能用\换行
  75. 'no-multiple-empty-lines': [2, { 'max': 1 }],//空行最多不能超过2行
  76. 'no-native-reassign': 2,//不能重写native对象
  77. 'no-negated-in-lhs': 2,//in 操作符的左边不能有!
  78. 'no-new-object': 2,//禁止使用new Object()
  79. 'no-new-require': 2,//禁止使用new require
  80. 'no-new-symbol': 2,// 使用Symbol()而不能使用new
  81. 'no-new-wrappers': 2,// https://eslint.org/docs/rules/no-new-wrappers#disallow-primitive-wrapper-instances-no-new-wrappers
  82. 'no-obj-calls': 2,//不能调用内置的全局对象,比如Math() JSON()
  83. 'no-octal': 2,//禁止使用八进制数字
  84. 'no-octal-escape': 2,//禁止使用八进制转义序列
  85. 'no-path-concat': 2,//node中不能使用__dirname或__filename做路径拼接
  86. 'no-proto': 2,//禁止使用__proto__属性
  87. 'no-redeclare': 0,//禁止重复声明变量
  88. 'no-regex-spaces': 2,//禁止在正则表达式字面量中使用多个空格
  89. 'no-return-assign': [2, 'except-parens'],//return 语句中不能有赋值表达式
  90. 'no-self-assign': 2,// 不能自声明
  91. 'no-self-compare': 2,// 不能自比较
  92. 'no-sequences': 2,//禁止使用逗号运算符
  93. 'no-shadow-restricted-names': 2,//严格模式中规定的限制标识符不能作为声明时的变量名使用
  94. 'no-spaced-func': 2,// 函数调用时 函数名与()之间不能有空格
  95. 'no-sparse-arrays': 2,//禁止稀疏数组, [1,,2]
  96. 'no-this-before-super': 2,//在调用super()之前不能使用this或super
  97. 'no-throw-literal': 2,//禁止抛出字面量错误 throw "error";
  98. 'no-trailing-spaces': 2,//一行结束后面不要有空格
  99. 'no-undef': 0,//不能有未定义的变量
  100. 'no-undef-init': 2,//变量初始化时不能直接给它赋值为undefined
  101. 'no-unexpected-multiline': 2,//避免多行表达式
  102. 'no-unmodified-loop-condition': 2,//不使用未定义的循环条件
  103. 'no-unneeded-ternary': [2, { 'defaultAssignment': false }],//禁止不必要的嵌套 https://eslint.org/docs/rules/no-unneeded-ternary#disallow-ternary-operators-when-simpler-alternatives-exist-no-unneeded-ternary
  104. 'no-unreachable':0,//不能有无法执行的代码
  105. 'no-unsafe-finally': 2,// finally中不能执行有歧义的代码
  106. 'no-unused-vars': [0, { 'vars': 'all', 'args': 'none' }],//不声明未使用的变量
  107. 'no-useless-call': 2,//禁止不必要的call和apply
  108. 'no-useless-computed-key': 2,//不声明无用的键
  109. 'no-useless-constructor': 2,// https://eslint.org/docs/rules/no-useless-constructor#disallow-unnecessary-constructor-no-useless-constructor
  110. 'no-useless-escape': 0,// https://eslint.org/docs/rules/no-useless-escape#disallow-unnecessary-escape-usage-no-useless-escape
  111. 'no-whitespace-before-property': 2,// 对象键之前无空格
  112. 'no-with': 2,//禁用with
  113. 'one-var': [0, { 'initialized': 'never' }],//禁用连续声明
  114. 'operator-linebreak': [2, 'after', { 'overrides': { '?': 'before', ':': 'before' } }],//换行时运算符在行尾还是行首
  115. 'padded-blocks': [2, 'never'],//块语句内行首行尾不能空行
  116. 'quotes': [2, 'single', { 'avoidEscape': true, 'allowTemplateLiterals': true }],//使用单引号
  117. 'semi': [2, 'never'],//不使用语句强制分号结尾
  118. 'semi-spacing': [2, { 'before': false, 'after': true }],//分号前后空格
  119. 'space-before-blocks': [2, 'always'],//不以新行开始的块{前面需要有空格
  120. 'space-before-function-paren': [2, 'never'],//函数定义时括号前面需要有空格
  121. 'space-in-parens': [2, 'never'],//小括号里面不需要有空格
  122. 'space-infix-ops': 2,//中缀操作符周围需要有空格'
  123. 'vue/no-parsing-error':[0,{
  124. "x-invalid-end-tag": false
  125. }],
  126. 'vue/no-side-effects-in-computed-properties':0,
  127. 'no-inner-declarations':0,
  128. 'no-dupe-keys':0,
  129. 'vue/no-dupe-keys':0,
  130. 'vue/no-unused-vars':0,
  131. 'space-unary-ops': [2, { 'words': true, 'nonwords': false }],//一元运算符的前/后要不要加空格
  132. 'spaced-comment': [2, 'always', { 'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ','] }],//注释风格需要有空格
  133. 'template-curly-spacing': [2, 'never'],//模板中{}包裹的变量不需要空格
  134. 'use-isnan': 2,//禁止比较时使用NaN,只能用isNaN()
  135. 'valid-typeof': 2,//必须使用合法的typeof的值
  136. 'wrap-iife': [2, 'any'],//立即执行函数表达式的小括号风格任意一种都可以
  137. 'yield-star-spacing': [2, 'both'],// generate 函数 yeild风格
  138. 'yoda': [2, 'never'],//禁止尤达条件
  139. 'prefer-const': 0,//优先使用const
  140. 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,//禁止使用debugger,开发环境允许使用
  141. 'object-curly-spacing': [2, 'always', { objectsInObjects: false }],//大括号内是否允许不必要的空格
  142. 'array-bracket-spacing': [2, 'never'],//是否允许非空数组里面有多余的空格
  143. 'vue-libs/jsx-uses-vars': 2,
  144. 'vue/require-v-for-key': 0
  145. }
  146. }