fix: disallow circular project references#686
fix: disallow circular project references#686no-yan wants to merge 2 commits intooxc-project:mainfrom
Conversation
…king Circular project references are not supported by TypeScript specification. Previously, we worked around this by using UseSourceOfProjectReference to include all source files, but this was incorrect. Now we properly detect circular project references and emit a diagnostic error instead of panicking.
a3a39be to
37dd987
Compare
| for _, f := range unmatchedFiles { | ||
| onInternalDiagnostic(diagnostic.Internal{ | ||
| Id: "circular-project-references", | ||
| Description: fmt.Sprintf("File was not found in program '%s'. This is likely caused by circular project references, which are not supported by TypeScript (TS6202).", configFileName), |
There was a problem hiding this comment.
why doesn't the tsconfig parsing/ error matching produce this error code?
There was a problem hiding this comment.
- This error appears only in "build mode" (tsgo -b).
- Since tsgolint does not use build mode, this error will not occur.
The reason of 1 is likely because references are a no-op in non-"build" mode.
It remains unclear why files are missing from the program created by tsgolint; there can be an issue within find_tsconfig.go.
There was a problem hiding this comment.
I investigated find_tsconfig.go and confirmed it works correctly. It maps files to the right tsconfig even with circular project references.
camc314
left a comment
There was a problem hiding this comment.
I'm a little confused here since the typechecking in the original repro worked?
|
I was notified since you commented in my other post, but I'm not following your PR. While I understand that when I run with tsc -b may face circular reference errors, would it mean that it would throw an error for such cases with tsgolint? |
|
@rubnogueira |
|
I'm not following. Since eslint/typescript-eslint works perfectly, why the need for tsgolint to display an error message and behave differently? |
|
Thanks for the feedback. I’m proposing this change because circular references are likely configuration errors. Project References are option which is used to speed up build. If there are valid use cases for composite projects with circular refs that I'm missing, please let me know. I'd love to hear your thoughts! |
Summary
Improves parsing performance by disabling
UseSourceOfProjectReferenceand adds proper error handling for circular project references.Background
Previously, we enabled
UseSourceOfProjectReferenceto fix panics caused by circular project references (#574). However, this option forces the parser to use source files instead of declaration files, which is inherently slow.Furthermore, upstream TypeScript and Tsgo don't support circular project references.
Indeed, running tsgo -b (build mode) on #574's repro produces this error.
Rather than supporting this case, we now detect circular references and emit a clear diagnostic to guide users.
Benchmark
1.29 times faster on aws-cdk
Details
Note
Disclosure: I used some AI tools: Codex for implement my plan and gemini for improve my english.