.eslintrc.js 6.5 KB

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