.eslintrc.js 6.6 KB

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