exclude __tests__ from tsc#2628
Conversation
|
Thanks for opening this pull request and contributing to the project! The next step is for the maintainers to review your changes. If everything looks good, it will be approved and merged into the main branch. In the meantime, anyone in the community is encouraged to test this pull request and provide feedback. ✅ How to confirm it worksIf you’ve tested this PR, please comment below with: This helps us speed up the review and merge process. 📦 To test this PR locally:If you encounter any issues or have feedback, feel free to comment as well. |
📝 WalkthroughWalkthroughThe PR modifies ChangesTypeScript Build Configuration
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tsconfig.json`:
- Line 38: The tsconfig.json currently excludes "src/__tests__/**", which breaks
type-aware ESLint because parserOptions.project points at tsconfig.json while
lint targets src/**/*.ts; create a separate ESLint TS config (e.g.,
tsconfig.eslint.json) that extends "./tsconfig.json", sets "include":
["src/**/*.ts"] and removes the tests exclusion (keep only "node_modules" in
"exclude"), then update ESLint's parserOptions.project to point to this new
tsconfig so tests are included for linting while the original tsconfig keeps the
exclusion for tsc.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
| }, | ||
| "include": ["src/**/*.ts"], | ||
| "exclude": ["node_modules"] | ||
| "exclude": ["node_modules", "src/__tests__/**"] |
There was a problem hiding this comment.
Type-aware ESLint will likely break for test files with this exclusion.
Because ESLint uses parserOptions.project: "./tsconfig.json" while lint targets src/**/*.ts, excluding src/__tests__/** here can cause parser project-inclusion errors on test files during npm run lint. Keep this exclusion for tsc, but add a dedicated ESLint tsconfig that includes tests (or point ESLint to a separate project file).
Suggested config split
# tsconfig.json (typecheck/build)
"exclude": ["node_modules", "src/__tests__/**"]// tsconfig.eslint.json (new)
{
"extends": "./tsconfig.json",
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}# eslint.config.mts
parserOptions: {
- project: "./tsconfig.json",
+ project: "./tsconfig.eslint.json",
},🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tsconfig.json` at line 38, The tsconfig.json currently excludes
"src/__tests__/**", which breaks type-aware ESLint because parserOptions.project
points at tsconfig.json while lint targets src/**/*.ts; create a separate ESLint
TS config (e.g., tsconfig.eslint.json) that extends "./tsconfig.json", sets
"include": ["src/**/*.ts"] and removes the tests exclusion (keep only
"node_modules" in "exclude"), then update ESLint's parserOptions.project to
point to this new tsconfig so tests are included for linting while the original
tsconfig keeps the exclusion for tsc.
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tsconfig.json">
<violation number="1" location="tsconfig.json:38">
P2: Excluding `src/__tests__/**` from tsconfig.json will break type-aware ESLint linting for test files if ESLint is configured with `parserOptions.project` pointing to this tsconfig. Files excluded from the tsconfig cannot be parsed by typescript-eslint's type-aware rules, resulting in "TSConfig does not include this file" errors.
Consider creating a separate `tsconfig.eslint.json` that extends this config but removes the test exclusion, and point ESLint's `parserOptions.project` at it instead.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| }, | ||
| "include": ["src/**/*.ts"], | ||
| "exclude": ["node_modules"] | ||
| "exclude": ["node_modules", "src/__tests__/**"] |
There was a problem hiding this comment.
P2: Excluding src/__tests__/** from tsconfig.json will break type-aware ESLint linting for test files if ESLint is configured with parserOptions.project pointing to this tsconfig. Files excluded from the tsconfig cannot be parsed by typescript-eslint's type-aware rules, resulting in "TSConfig does not include this file" errors.
Consider creating a separate tsconfig.eslint.json that extends this config but removes the test exclusion, and point ESLint's parserOptions.project at it instead.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tsconfig.json, line 38:
<comment>Excluding `src/__tests__/**` from tsconfig.json will break type-aware ESLint linting for test files if ESLint is configured with `parserOptions.project` pointing to this tsconfig. Files excluded from the tsconfig cannot be parsed by typescript-eslint's type-aware rules, resulting in "TSConfig does not include this file" errors.
Consider creating a separate `tsconfig.eslint.json` that extends this config but removes the test exclusion, and point ESLint's `parserOptions.project` at it instead.</comment>
<file context>
@@ -35,5 +35,5 @@
},
"include": ["src/**/*.ts"],
- "exclude": ["node_modules"]
+ "exclude": ["node_modules", "src/__tests__/**"]
}
</file context>
without this, tsc goes crazy, as detects tests as a typescript directory. excluding it will make tsc compile the current code without errors
Summary by cubic
Exclude
src/__tests__/**from TypeScript compilation sotscno longer treats test files as source. This stops false type errors from tests and lets builds pass.Written for commit f6d3f2f. Summary will update on new commits.
Summary by CodeRabbit