.eslintrc.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. module.exports = {
  2. root: true,
  3. parserOptions: {
  4. parser: 'babel-eslint',
  5. sourceType: 'module'
  6. },
  7. env: {
  8. browser: true,
  9. node: true,
  10. es6: true
  11. },
  12. extends: ['plugin:vue/recommended', 'eslint:recommended'],
  13. // add your custom rules here
  14. // it is base on https://github.com/vuejs/eslint-config-vue
  15. rules: {
  16. // 强制每行的最大属性数
  17. 'vue/max-attributes-per-line': [2, {
  18. // 单行时可以接收最大数量
  19. 'singleline': 10,
  20. // 多行时可以接收最大数量
  21. 'multiline': {
  22. 'max': 1,
  23. 'allowFirstLine': false
  24. }
  25. }],
  26. 'vue/return-in-computed-property': [2, {
  27. 'treatUndefinedAsUnspecified': true
  28. }],
  29. // 在单行元素的内容前后需要换行符
  30. 'vue/singleline-html-element-content-newline': 'off',
  31. // 在多行元素的内容前后需要换行符
  32. 'vue/multiline-html-element-content-newline': 'off',
  33. 'vue/name-property-casing': ['error', 'PascalCase'],
  34. // 禁止使用 v-html 防止 XSS 攻击
  35. 'vue/no-v-html': 'off',
  36. // 定义对象的set存取器属性时,强制定义get
  37. 'accessor-pairs': 2,
  38. // =>的前/后括号
  39. 'arrow-spacing': [2, {
  40. 'before': true,
  41. 'after': true
  42. }],
  43. // 禁止或强制在代码块中开括号前和闭括号后有空格
  44. 'block-spacing': [2, 'always'],
  45. // 强制在代码块中使用一致的大括号风格
  46. 'brace-style': [2, '1tbs', {
  47. 'allowSingleLine': true
  48. }],
  49. // 双峰驼命名格式
  50. 'camelcase': [0, {
  51. 'properties': 'always'
  52. }],
  53. // 数组和对象键值对最后一个逗号, never参数:不能带末尾的逗号, always参数:必须带末尾的逗号,
  54. // always-multiline:多行模式必须带逗号,单行模式不能带逗号
  55. 'comma-dangle': [2, 'never'],
  56. // 控制逗号前后的空格
  57. 'comma-spacing': [2, {
  58. 'before': false,
  59. 'after': true
  60. }],
  61. // 控制逗号在行尾出现还是在行首出现
  62. 'comma-style': [2, 'last'],
  63. // 强制在子类构造函数中用super()调用父类构造函数,TypeScrip的编译器也会提示
  64. 'constructor-super': 2,
  65. // if else while for do后面的代码块是否需要{ }包围,参数:
  66. // multi 只有块中有多行语句时才需要{ }包围
  67. // multi-line 只有块中有多行语句时才需要{ }包围, 但是块中的执行语句只有一行时,
  68. // 块中的语句只能跟和if语句在同一行。if (foo) foo++; else doSomething();
  69. // multi-or-nest 只有块中有多行语句时才需要{ }包围, 如果块中的执行语句只有一行,执行语句可以零另起一行也可以跟在if语句后面
  70. // [2, "multi", "consistent"] 保持前后语句的{ }一致
  71. // default: [2, "all"] 全都需要{ }包围
  72. 'curly': [2, 'multi-line'],
  73. // 强制object.key 中 . 的位置,参数:
  74. // property,'.'号应与属性在同一行
  75. // object, '.' 号应与对象名在同一行
  76. 'dot-location': [2, 'property'],
  77. // 文件末尾强制换行
  78. 'eol-last': 2,
  79. // 使用 === 替代 ==
  80. 'eqeqeq': [2, 'always', { 'null': 'ignore' }],
  81. // 强制 generator 函数中 * 号周围使用一致的空格
  82. 'generator-star-spacing': [2, {
  83. 'before': true,
  84. 'after': true
  85. }],
  86. // 要求回调函数中有容错处理
  87. 'handle-callback-err': [2, '^(err|error)$'],
  88. // 强制使用一致的缩进
  89. 'indent': [2, 2, {
  90. 'SwitchCase': 1
  91. }],
  92. 'jsx-quotes': [2, 'prefer-single'],
  93. // 强制在对象字面量的属性中键和值之间使用一致的间距
  94. 'key-spacing': [2, {
  95. 'beforeColon': false,
  96. 'afterColon': true
  97. }],
  98. // 强制在关键字前后使用一致的空格
  99. 'keyword-spacing': [2, {
  100. 'before': true,
  101. 'after': true
  102. }],
  103. // 要求构造函数首字母大写
  104. 'new-cap': [2, {
  105. 'newIsCap': true,
  106. 'capIsNew': false
  107. }],
  108. // 强制或禁止调用无参构造函数时有圆括号
  109. 'new-parens': 2,
  110. // 禁止使用数组构造器
  111. 'no-array-constructor': 2,
  112. // 禁止使用arguments.caller或arguments.callee
  113. 'no-caller': 2,
  114. // 禁止使用console
  115. 'no-console': 0,
  116. // 禁止给类赋值
  117. 'no-class-assign': 2,
  118. // 禁止在条件表达式中使用赋值语句
  119. 'no-cond-assign': 2,
  120. // 禁止修改const声明的变量
  121. 'no-const-assign': 2,
  122. // 禁止在正则表达式中使用控制字符
  123. 'no-control-regex': 0,
  124. // 不能对var声明的变量使用delete操作符
  125. 'no-delete-var': 2,
  126. // 函数参数不能重复
  127. 'no-dupe-args': 2,
  128. // no-dupe-class-members
  129. 'no-dupe-class-members': 2,
  130. // 在创建对象字面量时不允许键重复 {a:1,a:1}
  131. 'no-dupe-keys': 2,
  132. // switch中的case标签不能重复
  133. 'no-duplicate-case': 2,
  134. // 正则表达式中的[]内容不能为空
  135. 'no-empty-character-class': 2,
  136. // no-empty-pattern
  137. 'no-empty-pattern': 2,
  138. // 禁止使用eval
  139. 'no-eval': 2,
  140. // 禁止给catch语句中的异常参数赋值
  141. 'no-ex-assign': 2,
  142. // 禁止扩展native对象
  143. 'no-extend-native': 2,
  144. // 禁止不必要的函数绑定
  145. 'no-extra-bind': 2,
  146. // 禁止不必要的bool转换
  147. 'no-extra-boolean-cast': 2,
  148. // 禁止非必要的括号
  149. 'no-extra-parens': [2, 'functions'],
  150. // 禁止switch穿透
  151. 'no-fallthrough': 2,
  152. // 禁止省略浮点数中的0 .5 3.
  153. 'no-floating-decimal': 2,
  154. // 禁止重复的函数声明
  155. 'no-func-assign': 2,
  156. // 禁止使用隐式eval
  157. 'no-implied-eval': 2,
  158. // 禁止在块语句中使用声明(变量或函数)
  159. 'no-inner-declarations': [2, 'functions'],
  160. // 禁止无效的正则表达式
  161. 'no-invalid-regexp': 2,
  162. // 不能有不规则的空格
  163. 'no-irregular-whitespace': 2,
  164. // 禁止使用__iterator__ 属性
  165. 'no-iterator': 2,
  166. // label名不能与var声明的变量名相同
  167. 'no-label-var': 2,
  168. // 禁止使用空label
  169. 'no-labels': [2, {
  170. 'allowLoop': false,
  171. 'allowSwitch': false
  172. }],
  173. // 禁止不必要的嵌套块
  174. 'no-lone-blocks': 2,
  175. // 禁止混用tab和空格
  176. 'no-mixed-spaces-and-tabs': 2,
  177. // 不能用多余的空格
  178. 'no-multi-spaces': 2,
  179. // 字符串不能用\换行
  180. 'no-multi-str': 2,
  181. // 空行最多不能超过2行
  182. 'no-multiple-empty-lines': [2, {
  183. 'max': 2
  184. }],
  185. // 禁止对原生对象或只读的全局对象进行赋值
  186. 'no-global-assign': 2,
  187. // 禁止对关系运算符的左操作数使用否定操作符
  188. 'no-unsafe-negation': 2,
  189. // 禁止使用new Object()
  190. 'no-new-object': 2,
  191. // 禁止使用new require
  192. 'no-new-require': 2,
  193. // 禁止 Symbolnew 操作符和 new 一起使用
  194. 'no-new-symbol': 2,
  195. // 禁止使用new创建包装实例,new String new Boolean new Number
  196. 'no-new-wrappers': 2,
  197. // 不能调用内置的全局对象,比如Math() JSON()
  198. 'no-obj-calls': 2,
  199. // 禁止使用八进制数字
  200. 'no-octal': 2,
  201. // 禁止使用八进制转义序列
  202. 'no-octal-escape': 2,
  203. // node中不能使用__dirname或__filename做路径拼接
  204. 'no-path-concat': 2,
  205. // 禁止使用__proto__属性
  206. 'no-proto': 2,
  207. // 禁止重复声明变量
  208. 'no-redeclare': 2,
  209. // 禁止在正则表达式字面量中使用多个空格 /foo bar/
  210. 'no-regex-spaces': 2,
  211. // return 语句中不能有赋值表达式
  212. 'no-return-assign': [2, 'except-parens'],
  213. // 禁止自我赋值
  214. 'no-self-assign': 2,
  215. // 不能比较自身
  216. 'no-self-compare': 2,
  217. // 禁止使用逗号运算符
  218. 'no-sequences': 2,
  219. // 严格模式中规定的限制标识符不能作为声明时的变量名使用
  220. 'no-shadow-restricted-names': 2,
  221. // 要求或禁止在函数标识符和其调用之间有空格
  222. 'func-call-spacing': 2,
  223. // 禁止稀疏数组, [1,,2]
  224. 'no-sparse-arrays': 2,
  225. // 在调用super()之前不能使用this或super
  226. 'no-this-before-super': 2,
  227. // 禁止抛出字面量错误 throw "error";
  228. 'no-throw-literal': 2,
  229. // 一行结束后面不要有空格
  230. 'no-trailing-spaces': 2,
  231. // 不能有未定义的变量
  232. 'no-undef': 2,
  233. // 变量初始化时不能直接给它赋值为undefined
  234. 'no-undef-init': 2,
  235. // 避免多行表达式
  236. 'no-unexpected-multiline': 2,
  237. // 禁用一成不变的循环条件
  238. 'no-unmodified-loop-condition': 2,
  239. // 禁止不必要的嵌套 var isYes = answer === 1 ? true : false;
  240. 'no-unneeded-ternary': [2, {
  241. 'defaultAssignment': false
  242. }],
  243. // 不能有无法执行的代码
  244. 'no-unreachable': 2,
  245. // 禁止在 finally 语句块中出现控制流语句
  246. 'no-unsafe-finally': 2,
  247. // 禁止无用的表达式
  248. 'no-unused-expressions': 2,
  249. // 不能有声明后未被使用的变量或参数
  250. 'no-unused-vars': [2, {
  251. 'vars': 'all',
  252. 'args': 'none'
  253. }],
  254. // 未定义前不能使用
  255. 'no-use-before-define': 2,
  256. // 禁止不必要的call和apply
  257. 'no-useless-call': 2,
  258. // 禁止在对象中使用不必要的计算属性
  259. 'no-useless-computed-key': 2,
  260. // 禁用不必要的构造函数
  261. 'no-useless-constructor': 2,
  262. // 禁用不必要的转义字符
  263. 'no-useless-escape': 0,
  264. // 禁止属性前有空白
  265. 'no-whitespace-before-property': 2,
  266. // 禁用with
  267. 'no-with': 2,
  268. // 连续声明
  269. 'one-var': [2, {
  270. 'initialized': 'never'
  271. }],
  272. // 换行时运算符在行尾还是行首
  273. 'operator-linebreak': [2, 'after', {
  274. 'overrides': {
  275. '?': 'before',
  276. ':': 'before'
  277. }
  278. }],
  279. // 块语句内行首行尾是否要空行
  280. 'padded-blocks': [2, 'never'],
  281. // 引号类型 `` "" ''
  282. 'quotes': [2, 'single', {
  283. 'avoidEscape': true,
  284. 'allowTemplateLiterals': true
  285. }],
  286. // 语句强制分号结尾
  287. 'semi': [2, 'never'],
  288. // 分号前后空格
  289. 'semi-spacing': [2, {
  290. 'before': false,
  291. 'after': true
  292. }],
  293. // 不以新行开始的块{前面要不要有空格
  294. 'space-before-blocks': [2, 'always'],
  295. // 函数定义时括号前面要不要有空格
  296. 'space-before-function-paren': [2, 'never'],
  297. // 小括号里面要不要有空格
  298. 'space-in-parens': [2, 'never'],
  299. // 中缀操作符周围要不要有空格
  300. 'space-infix-ops': 2,
  301. // 一元运算符的前/后要不要加空格
  302. 'space-unary-ops': [2, {
  303. 'words': true,
  304. 'nonwords': false
  305. }],
  306. // 注释风格不要有空格什么的
  307. 'spaced-comment': [2, 'always', {
  308. 'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ',']
  309. }],
  310. // 使用严格模式
  311. 'strict': 2,
  312. // 要求或禁止模板字符串中的嵌入表达式周围空格的使用
  313. 'template-curly-spacing': [2, 'never'],
  314. // 禁止比较时使用NaN,只能用isNaN()
  315. 'use-isnan': 2,
  316. // 必须使用合法的typeof的值
  317. 'valid-typeof': 2,
  318. // 要求 IIFE 使用括号括起来
  319. 'wrap-iife': [2, 'any'],
  320. // 强制在 yield* 表达式中 * 周围使用空格
  321. 'yield-star-spacing': [2, 'both'],
  322. // 禁止尤达条件
  323. 'yoda': [2, 'never'],
  324. // 首选const
  325. 'prefer-const': 2,
  326. // 禁止使用debugger
  327. 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
  328. // 大括号内是否允许不必要的空格
  329. 'object-curly-spacing': [2, 'always', {
  330. objectsInObjects: false
  331. }],
  332. // 指定数组的元素之间要以空格隔开(,后面), never参数:[ 之前和 ] 之后不能带空格,always参数:[ 之前和 ] 之后必须带空格
  333. 'array-bracket-spacing': [2, 'never']
  334. }
  335. }