.eslintrc.js 6.5 KB

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