.eslintrc.js 6.3 KB

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