.eslintrc.js 6.3 KB

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