.eslintrc.cjs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* eslint-disable no-restricted-globals */
  2. const DOMGlobals = ['window', 'document']
  3. const NodeGlobals = ['module', 'require']
  4. module.exports = {
  5. parser: '@typescript-eslint/parser',
  6. parserOptions: {
  7. sourceType: 'module'
  8. },
  9. plugins: ['jest'],
  10. rules: {
  11. 'no-debugger': 'error',
  12. // most of the codebase are expected to be env agnostic
  13. 'no-restricted-globals': ['error', ...DOMGlobals, ...NodeGlobals],
  14. 'no-restricted-syntax': [
  15. 'error',
  16. // since we target ES2015 for baseline support, we need to forbid object
  17. // rest spread usage in destructure as it compiles into a verbose helper.
  18. 'ObjectPattern > RestElement',
  19. // tsc compiles assignment spread into Object.assign() calls, but esbuild
  20. // still generates verbose helpers, so spread assignment is also prohiboted
  21. 'ObjectExpression > SpreadElement',
  22. 'AwaitExpression'
  23. ]
  24. },
  25. overrides: [
  26. // tests, no restrictions (runs in Node / jest with jsdom)
  27. {
  28. files: ['**/__tests__/**', 'packages/dts-test/**'],
  29. rules: {
  30. 'no-restricted-globals': 'off',
  31. 'no-restricted-syntax': 'off',
  32. 'jest/no-disabled-tests': 'error',
  33. 'jest/no-focused-tests': 'error'
  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: ['packages/{compiler-sfc,compiler-ssr,server-renderer}/**'],
  53. rules: {
  54. 'no-restricted-globals': ['error', ...DOMGlobals],
  55. 'no-restricted-syntax': 'off'
  56. }
  57. },
  58. // Private package, browser only + no syntax restrictions
  59. {
  60. files: ['packages/template-explorer/**', 'packages/sfc-playground/**'],
  61. rules: {
  62. 'no-restricted-globals': ['error', ...NodeGlobals],
  63. 'no-restricted-syntax': 'off'
  64. }
  65. },
  66. // JavaScript files
  67. {
  68. files: ['*.js', '*.cjs'],
  69. rules: {
  70. // We only do `no-unused-vars` checks for js files, TS files are checked by TypeScript itself.
  71. 'no-unused-vars': ['error', { vars: 'all', args: 'none' }]
  72. }
  73. },
  74. // Node scripts
  75. {
  76. files: ['scripts/**', '*.{js,ts}', 'packages/**/index.js'],
  77. rules: {
  78. 'no-restricted-globals': 'off',
  79. 'no-restricted-syntax': 'off'
  80. }
  81. }
  82. ]
  83. }