.eslintrc.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. module.exports = {
  2. root: true,
  3. // 为什么是这样的parser配置?https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser
  4. parser: 'vue-eslint-parser',
  5. parserOptions: {
  6. parser: '@babel/eslint-parser',
  7. sourceType: 'module',
  8. ecmaVersion: 7,
  9. ecmaFeatures: {
  10. impliedStrict: true
  11. }
  12. },
  13. env: {
  14. node: true,
  15. browser: true
  16. },
  17. extends: [
  18. 'eslint:recommended',
  19. 'plugin:vue/recommended',
  20. 'plugin:prettier/recommended',
  21. '@vue/eslint-config-prettier'
  22. ],
  23. plugins: [
  24. // 注意这里不能配置 html 选项,为什么?https://eslint.vuejs.org/user-guide/#why-doesn-t-it-work-on-vue-files
  25. 'vue',
  26. 'prettier'
  27. ],
  28. rules: {
  29. 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
  30. 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
  31. 'vue/multi-word-component-names': 0,
  32. 'vue/max-attributes-per-line': [
  33. 2,
  34. {
  35. singleline: 8,
  36. multiline: {
  37. max: 1
  38. }
  39. }
  40. ],
  41. 'vue/html-self-closing': [
  42. 1,
  43. {
  44. html: {
  45. void: 'always',
  46. normal: 'never',
  47. component: 'always'
  48. },
  49. svg: 'always',
  50. math: 'always'
  51. }
  52. ],
  53. 'accessor-pairs': 2,
  54. 'arrow-spacing': [
  55. 2,
  56. {
  57. before: true,
  58. after: true
  59. }
  60. ],
  61. 'block-spacing': [2, 'always'],
  62. 'brace-style': [
  63. 2,
  64. '1tbs',
  65. {
  66. allowSingleLine: true
  67. }
  68. ],
  69. camelcase: [
  70. 0,
  71. {
  72. properties: 'always'
  73. }
  74. ],
  75. 'comma-dangle': [2, 'never'],
  76. 'comma-spacing': [
  77. 2,
  78. {
  79. before: false,
  80. after: true
  81. }
  82. ],
  83. 'comma-style': [2, 'last'],
  84. curly: [2, 'multi-line'],
  85. 'dot-location': [2, 'property'],
  86. 'eol-last': 2,
  87. eqeqeq: [2, 'always'],
  88. 'generator-star-spacing': [
  89. 2,
  90. {
  91. before: false,
  92. after: true
  93. }
  94. ],
  95. indent: [
  96. 2,
  97. 2,
  98. {
  99. SwitchCase: 1
  100. }
  101. ],
  102. 'jsx-quotes': [2, 'prefer-single'],
  103. 'key-spacing': [
  104. 2,
  105. {
  106. beforeColon: false,
  107. afterColon: true
  108. }
  109. ],
  110. 'keyword-spacing': [
  111. 2,
  112. {
  113. before: true,
  114. after: true
  115. }
  116. ],
  117. 'new-cap': [
  118. 2,
  119. {
  120. newIsCap: true,
  121. capIsNew: false
  122. }
  123. ],
  124. 'no-caller': 2,
  125. 'no-eval': 2,
  126. 'no-labels': [
  127. 2,
  128. {
  129. allowLoop: false,
  130. allowSwitch: false
  131. }
  132. ],
  133. 'no-multi-spaces': 2,
  134. 'no-multiple-empty-lines': [
  135. 2,
  136. {
  137. max: 1
  138. }
  139. ],
  140. 'no-return-assign': [2, 'except-parens'],
  141. 'no-sequences': 2,
  142. 'no-trailing-spaces': 2,
  143. 'no-unmodified-loop-condition': 2,
  144. 'no-unneeded-ternary': [
  145. 2,
  146. {
  147. defaultAssignment: false
  148. }
  149. ],
  150. 'no-unused-vars': [1],
  151. 'no-useless-computed-key': 2,
  152. 'no-useless-constructor': 2,
  153. 'no-whitespace-before-property': 2,
  154. 'one-var': [
  155. 2,
  156. {
  157. initialized: 'never'
  158. }
  159. ],
  160. 'operator-linebreak': [
  161. 2,
  162. 'after',
  163. {
  164. overrides: {
  165. '?': 'before',
  166. ':': 'before'
  167. }
  168. }
  169. ],
  170. 'padded-blocks': [2, 'never'],
  171. quotes: [
  172. 2,
  173. 'single',
  174. {
  175. avoidEscape: true,
  176. allowTemplateLiterals: true
  177. }
  178. ],
  179. semi: [2, 'always'],
  180. 'semi-spacing': [
  181. 2,
  182. {
  183. before: false,
  184. after: true
  185. }
  186. ],
  187. 'space-before-blocks': [2, 'always'],
  188. 'space-in-parens': [2, 'never'],
  189. 'space-infix-ops': 2,
  190. 'space-unary-ops': [
  191. 2,
  192. {
  193. words: true,
  194. nonwords: false
  195. }
  196. ],
  197. 'spaced-comment': [
  198. 2,
  199. 'always',
  200. {
  201. markers: ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ',']
  202. }
  203. ],
  204. 'template-curly-spacing': [2, 'never'],
  205. 'wrap-iife': [2, 'any'],
  206. 'yield-star-spacing': [2, 'both'],
  207. 'object-curly-spacing': [2, 'always'],
  208. 'no-alert': process.env.NODE_ENV === 'production' ? 1 : 0,
  209. 'no-array-constructor': 2,
  210. 'no-bitwise': 1,
  211. 'no-div-regex': 1,
  212. 'no-else-return': 2,
  213. 'no-empty': 1,
  214. 'no-eq-null': 2,
  215. 'no-extend-native': 2,
  216. 'no-multi-assign': 1,
  217. 'no-negated-condition': 2,
  218. 'no-duplicate-imports': 2,
  219. 'no-extra-bind': 2,
  220. 'no-tabs': 2,
  221. 'no-extra-parens': [2, 'functions'],
  222. 'no-floating-decimal': 2,
  223. 'no-implicit-coercion': 1,
  224. 'no-implied-eval': 2,
  225. 'no-inline-comments': 0,
  226. 'no-invalid-this': 2,
  227. 'no-iterator': 2,
  228. 'no-label-var': 2,
  229. 'no-lone-blocks': 2,
  230. 'no-lonely-if': 2,
  231. 'linebreak-style': [0, 'windows'],
  232. 'no-multi-str': 2,
  233. 'no-nested-ternary': 0,
  234. 'no-new': 1,
  235. 'no-new-func': 1,
  236. 'no-new-object': 2,
  237. 'no-new-wrappers': 2,
  238. 'no-octal-escape': 2,
  239. 'no-param-reassign': 2,
  240. 'no-plusplus': [1, { allowForLoopAfterthoughts: true }],
  241. 'no-proto': 2,
  242. 'no-self-compare': 2,
  243. 'func-call-spacing': 2,
  244. 'no-ternary': 0,
  245. 'no-throw-literal': 2,
  246. 'no-undef-init': 2,
  247. 'no-use-before-define': 2,
  248. 'no-useless-call': 2,
  249. 'no-void': 2,
  250. 'no-var': 2,
  251. 'prefer-rest-params': 2,
  252. 'prefer-template': 2,
  253. 'no-warning-comments': [
  254. 1,
  255. {
  256. terms: ['todo', 'fix', '!', '?'],
  257. location: 'start'
  258. }
  259. ],
  260. 'array-bracket-spacing': [2, 'never'],
  261. 'computed-property-spacing': [1, 'never'],
  262. 'consistent-return': 0,
  263. 'default-case': 1,
  264. 'func-names': 1,
  265. 'func-style': 0,
  266. 'guard-for-in': 0,
  267. 'id-length': 0,
  268. 'init-declarations': 1,
  269. 'lines-around-comment': 0,
  270. 'max-depth': [1, 4],
  271. 'max-len': [1, { code: 120, ignoreUrls: true, ignoreTemplateLiterals: true, ignoreRegExpLiterals: true }],
  272. 'max-nested-callbacks': 1,
  273. 'max-params': [1, 6],
  274. 'max-statements': [1, 40],
  275. 'new-parens': 2,
  276. 'object-shorthand': 1,
  277. 'operator-assignment': 1,
  278. 'prefer-spread': 1,
  279. 'quote-props': [1, 'as-needed'],
  280. radix: [1, 'as-needed'],
  281. 'id-match': 0,
  282. 'sort-vars': [1, { ignoreCase: true }],
  283. strict: 2,
  284. 'vars-on-top': 2,
  285. 'wrap-regex': 0,
  286. yoda: [2, 'never']
  287. },
  288. // jest 测试配置
  289. overrides: [
  290. {
  291. files: ['**/__tests__/*.{j,t}s?(x)', '**/tests/unit/**/*.spec.{j,t}s?(x)'],
  292. env: {
  293. jest: true
  294. }
  295. }
  296. ]
  297. };