2
0

.eslintrc.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const DOMGlobals = ['window', 'document']
  2. const NodeGlobals = ['module', 'require']
  3. module.exports = {
  4. parser: '@typescript-eslint/parser',
  5. parserOptions: {
  6. sourceType: 'module'
  7. },
  8. rules: {
  9. 'no-unused-vars': [
  10. 'error',
  11. // we are only using this rule to check for unused arguments since TS
  12. // catches unused variables but not args.
  13. { varsIgnorePattern: '.*', args: 'none' }
  14. ],
  15. // most of the codebase are expected to be env agnostic
  16. 'no-restricted-globals': ['error', ...DOMGlobals, ...NodeGlobals],
  17. // since we target ES2015 for baseline support, we need to forbid object
  18. // rest spread usage in destructure as it compiles into a verbose helper.
  19. // TS now compiles assignment spread into Object.assign() calls so that
  20. // is allowed.
  21. 'no-restricted-syntax': [
  22. 'error',
  23. 'ObjectPattern > RestElement',
  24. 'AwaitExpression'
  25. ]
  26. },
  27. overrides: [
  28. // tests, no restrictions (runs in Node / jest with jsdom)
  29. {
  30. files: ['**/__tests__/**', 'test-dts/**'],
  31. rules: {
  32. 'no-restricted-globals': 'off',
  33. 'no-restricted-syntax': 'off'
  34. }
  35. },
  36. // shared, may be used in any env
  37. {
  38. files: ['packages/shared/**'],
  39. rules: {
  40. 'no-restricted-globals': 'off'
  41. }
  42. },
  43. // Packages targeting DOM
  44. {
  45. files: ['packages/{vue,vue-compat,runtime-dom}/**'],
  46. rules: {
  47. 'no-restricted-globals': ['error', ...NodeGlobals]
  48. }
  49. },
  50. // Packages targeting Node
  51. {
  52. files: [
  53. 'packages/{compiler-sfc,compiler-ssr,server-renderer,reactivity-transform}/**'
  54. ],
  55. rules: {
  56. 'no-restricted-globals': ['error', ...DOMGlobals],
  57. 'no-restricted-syntax': 'off'
  58. }
  59. },
  60. // Private package, browser only + no syntax restrictions
  61. {
  62. files: ['packages/template-explorer/**', 'packages/sfc-playground/**'],
  63. rules: {
  64. 'no-restricted-globals': ['error', ...NodeGlobals],
  65. 'no-restricted-syntax': 'off'
  66. }
  67. }
  68. ]
  69. }