-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cli): Add validation rule for recursively-defined types (Issue #4135) #4224
Conversation
5069ed6
to
c416e63
Compare
} | ||
|
||
/** | ||
* This function will return the first found path to a named child type from a given type. It will only search within the file of the given type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will only search within the file of the given type.
Seems like a big limitation, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/fern-api/fern/blob/main/packages/cli/yaml/validator/src/rules/no-duplicate-declarations/no-duplicate-declarations.ts#L15 Is an example of a rule that is able to check for name conflicts across files (admittedly much easier)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will only search within the file of the given type.
Seems like a big limitation, no?
Hey, thanks for taking a look at this. I had actually ran into that while coding, but we should be covered by the existing validation rule for cyclic imports.
The only way to create a cycle across multiple files is if each file has a reference to the type defined in the other file, as seen above. That would inherently require a cyclic import, so the validation would fail it and prevent any cyclic types from being declared across files.
Since that narrows our search to only cycles defined within a single file, we can skip walking to any other files in each check and allow the rule to catch them when the main visitor for the rules reaches them normally.
As an example, we can ignore the jump from file 1 to file 2 here, allow the visitor to traverse the types in the second file, and then catch the cycle starting from type-3 or type-4.
packages/cli/generation/ir-generator/src/utils/getCyclicTypes.ts
Outdated
Show resolved
Hide resolved
packages/cli/generation/ir-generator/src/utils/getCyclicTypes.ts
Outdated
Show resolved
Hide resolved
4eb9f86
to
9180bd7
Compare
Adds logic and validations to detect cycles within type defintions. code review changes
Adds rule and related utilities for detecting & marking cyclicly-defined types.