.eslintrc.js 6.3 KB

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