.eslintrc.js 6.3 KB

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