.eslintrc.js 6.4 KB

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