.eslintrc.js 6.3 KB

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