.eslintrc.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 (both assign and destructure)
  19. 'no-restricted-syntax': [
  20. 'error',
  21. 'ObjectExpression > SpreadElement',
  22. 'ObjectPattern > RestElement',
  23. 'AwaitExpression'
  24. ]
  25. },
  26. overrides: [
  27. // tests, no restrictions (runs in Node / jest with jsdom)
  28. {
  29. files: ['**/__tests__/**', 'test-dts/**'],
  30. rules: {
  31. 'no-restricted-globals': 'off',
  32. 'no-restricted-syntax': 'off'
  33. }
  34. },
  35. // shared, may be used in any env
  36. {
  37. files: ['packages/shared/**'],
  38. rules: {
  39. 'no-restricted-globals': 'off'
  40. }
  41. },
  42. // Packages targeting DOM
  43. {
  44. files: ['packages/{vue,vue-compat,runtime-dom}/**'],
  45. rules: {
  46. 'no-restricted-globals': ['error', ...NodeGlobals]
  47. }
  48. },
  49. // Packages targeting Node
  50. {
  51. files: [
  52. 'packages/{compiler-sfc,compiler-ssr,server-renderer,ref-transform}/**'
  53. ],
  54. rules: {
  55. 'no-restricted-globals': ['error', ...DOMGlobals],
  56. 'no-restricted-syntax': 'off'
  57. }
  58. },
  59. // Private package, browser only + no syntax restrictions
  60. {
  61. files: ['packages/template-explorer/**', 'packages/sfc-playground/**'],
  62. rules: {
  63. 'no-restricted-globals': ['error', ...NodeGlobals],
  64. 'no-restricted-syntax': 'off'
  65. }
  66. }
  67. ]
  68. }