.eslintrc.js 6.4 KB

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