.eslintrc.js 6.7 KB

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