eslint.config.mjs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import stylistic from '@stylistic/eslint-plugin'
  2. import sonarjs from 'eslint-plugin-sonarjs'
  3. import tseslint from 'typescript-eslint'
  4. // Strict type-aware correctness rules plus repository formatting. Tests/examples relax deliberate
  5. // mock unsafety; vendored sources retain upstream style and receive only selected safety checks.
  6. export default tseslint.config(
  7. {
  8. ignores: [
  9. '**/lib/**',
  10. '**/node_modules/**',
  11. '**/.sessions/**',
  12. '.claude/**', // harness-local state (worktrees, skills) — other checkouts, not this one's sources
  13. '**/.doc-typecheck-*/**',
  14. '**/.node-next-types-*/**',
  15. 'website/.generated/**',
  16. 'vendor/**', // vendored source keeps upstream style and idioms
  17. 'native/**', // imported landlock-run subtree: self-contained workspace with its own gates (native/README.md)
  18. '**/*.js',
  19. '**/*.mjs',
  20. '*.config.ts', // root tool configs (vitest, tsdown) — no project service
  21. 'apps/*/*.config.ts', // app build configs — outside their project programs
  22. '**/tsdown.config.ts', // package build configs — in no tsconfig program, and TS syntax breaks the parserless fallback
  23. 'packages/client/tsdown.client.ts', // shared client build preset, same standing
  24. ],
  25. },
  26. // --- our packages: full strictness -------------------------------------
  27. {
  28. files: ['packages/*/*/src/**/*.ts', 'apps/*/src/**/*.ts', 'examples/**/*.ts', 'scripts/**/*.ts', 'website/**/*.ts'],
  29. extends: [
  30. ...tseslint.configs.strictTypeChecked,
  31. ],
  32. languageOptions: {
  33. parserOptions: {
  34. // One project service resolves each file to its owning tsconfig and shares dependency
  35. // graphs. Per-package programs duplicated path-mapped and Cordis closures, reaching ~5 GB.
  36. projectService: true,
  37. tsconfigRootDir: import.meta.dirname,
  38. },
  39. },
  40. rules: {
  41. // The bug class this repo cares most about: lost promises in the loop.
  42. '@typescript-eslint/no-floating-promises': 'error',
  43. '@typescript-eslint/no-misused-promises': 'error',
  44. '@typescript-eslint/require-await': 'error',
  45. '@typescript-eslint/switch-exhaustiveness-check': ['error', {
  46. considerDefaultExhaustiveForUnions: true,
  47. }],
  48. '@typescript-eslint/no-unnecessary-condition': ['error', {
  49. allowConstantLoopConditions: true,
  50. }],
  51. // `any` requires a justification comment — enforced as: no bare casts.
  52. '@typescript-eslint/no-explicit-any': 'error',
  53. // Style points where the codebase intentionally diverges from preset:
  54. '@typescript-eslint/no-namespace': 'off', // Cordis Config-namespace idiom
  55. '@typescript-eslint/no-empty-object-type': 'off', // merge-extensible maps
  56. '@typescript-eslint/no-invalid-void-type': 'off', // event signatures
  57. '@typescript-eslint/restrict-template-expressions': ['error', {
  58. allowNumber: true,
  59. allowBoolean: true,
  60. }],
  61. // `void foo()` in arrow listeners is our idiom for intentional fire-and-forget
  62. 'no-void': 'off',
  63. '@typescript-eslint/no-unused-vars': ['error', {
  64. argsIgnorePattern: '^_',
  65. varsIgnorePattern: '^_',
  66. caughtErrorsIgnorePattern: '^_',
  67. }],
  68. },
  69. },
  70. // --- examples: demo code conforms to async interfaces without awaiting ---
  71. {
  72. files: ['examples/**/*.ts'],
  73. rules: {
  74. '@typescript-eslint/require-await': 'off',
  75. },
  76. },
  77. // --- tests: same rules, minus the friction that fights test ergonomics --
  78. {
  79. files: ['packages/*/*/tests/**/*.ts', 'apps/*/tests/**/*.ts', 'examples/*/tests/**/*.ts', 'scripts/**/*.spec.ts'],
  80. extends: [
  81. ...tseslint.configs.strictTypeChecked,
  82. ],
  83. languageOptions: {
  84. parserOptions: {
  85. // Same shared project service as the src block: test files resolve
  86. // through the root solution to tsconfig.host.json (its include covers
  87. // every host tests/ tree).
  88. projectService: true,
  89. tsconfigRootDir: import.meta.dirname,
  90. },
  91. },
  92. rules: {
  93. '@typescript-eslint/no-floating-promises': 'error',
  94. '@typescript-eslint/no-misused-promises': 'error',
  95. '@typescript-eslint/no-explicit-any': 'error',
  96. '@typescript-eslint/no-non-null-assertion': 'off', // assertions follow expect()s
  97. '@typescript-eslint/no-unnecessary-condition': 'off',
  98. '@typescript-eslint/require-await': 'off', // mock execute() signatures
  99. '@typescript-eslint/no-empty-function': 'off', // stub agents
  100. '@typescript-eslint/only-throw-error': 'off', // testing non-Error throws
  101. '@typescript-eslint/no-namespace': 'off',
  102. '@typescript-eslint/no-empty-object-type': 'off',
  103. '@typescript-eslint/restrict-template-expressions': 'off',
  104. '@typescript-eslint/no-unused-vars': ['error', {
  105. argsIgnorePattern: '^_',
  106. varsIgnorePattern: '^_',
  107. caughtErrorsIgnorePattern: '^_',
  108. }],
  109. },
  110. },
  111. // --- client tests: the root program excludes packages/client (host/client
  112. // Context merges collide), so the shared project service cannot resolve
  113. // them — parse these through the client aggregate explicitly.
  114. {
  115. files: ['packages/client/*/tests/**/*.ts', 'scripts/client-bundle-purity.spec.ts'],
  116. languageOptions: {
  117. parserOptions: {
  118. projectService: false,
  119. project: ['./tsconfig.client.json'],
  120. tsconfigRootDir: import.meta.dirname,
  121. },
  122. },
  123. },
  124. // --- file-local duplication (all owned TypeScript) ---------------------
  125. {
  126. files: ['packages/**/*.ts', 'apps/**/*.ts', 'examples/**/*.ts', 'scripts/**/*.ts', 'website/**/*.ts'],
  127. plugins: { sonarjs },
  128. rules: {
  129. // Cross-file clones are covered separately by jscpd.
  130. 'sonarjs/duplicates-in-character-class': 'error',
  131. 'sonarjs/no-all-duplicated-branches': 'error',
  132. 'sonarjs/no-duplicate-in-composite': 'error',
  133. 'sonarjs/no-duplicate-test-title': 'error',
  134. 'sonarjs/no-identical-conditions': 'error',
  135. 'sonarjs/no-identical-expressions': 'error',
  136. 'sonarjs/no-identical-functions': 'error',
  137. 'sonarjs/no-duplicated-branches': 'error',
  138. },
  139. },
  140. // --- formatting (everything we own) -------------------------------------
  141. {
  142. files: ['packages/**/*.ts', 'apps/**/*.ts', 'examples/**/*.ts', 'scripts/**/*.ts', 'website/**/*.ts', 'eslint.config.mjs'],
  143. plugins: { '@stylistic': stylistic },
  144. rules: {
  145. '@stylistic/indent': ['error', 2],
  146. '@stylistic/semi': ['error', 'never'],
  147. '@stylistic/quotes': ['error', 'single', { avoidEscape: true }],
  148. '@stylistic/comma-dangle': ['error', 'always-multiline'],
  149. '@stylistic/eol-last': ['error', 'always'],
  150. '@stylistic/no-trailing-spaces': 'error',
  151. '@stylistic/object-curly-spacing': ['error', 'always'],
  152. '@stylistic/arrow-parens': ['error', 'as-needed', { requireForBlockBody: true }],
  153. '@stylistic/member-delimiter-style': ['error', {
  154. multiline: { delimiter: 'none' },
  155. singleline: { delimiter: 'semi', requireLast: false },
  156. }],
  157. '@stylistic/max-len': ['error', { code: 140, ignoreUrls: true, ignoreStrings: true, ignoreTemplateLiterals: true }],
  158. },
  159. },
  160. )