-
Notifications
You must be signed in to change notification settings - Fork 256
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
Issue: no-circular does not follow dependencyTypesNot: ['type-only'] over entire cycle #695
Comments
Hi @camillef thank you for raising this issue - I'm looking into it (using your excellent reproduction steps as a guide). |
hi @camillef - I've made a reproduction sample for the issue in the dependency-cruiser repro repo. There's a few things going on The I see you already edited the original issue to include these explicit flowchart LR
parent -->|type-only| child
child -->|type-only| grand-child
grand-child --> parent
That bug will need to be ironed out of the cycle flagging code. I have ideas how to do that, but I'll need a patch of spare time to work on that (no promises, but Christmas holidays are coming up ...). Options in the mean time:
sample rule with the preCompilationOnly attribute// ...
{
name: "no-circular",
severity: "error",
from: {},
to: {
circular: true,
preCompilationOnly: false,
},
},
// ... |
Hi @sverweij, Thank you for your thorough investigation - you're exactly correct that my reproduction was missing I think I'll stick with the |
@sverweij I'd be interested in working on this too since it's also affecting me (similar use case to @camillef's but for Remix loaders). If I understand correctly, the issue will be fixed if the |
…r API users) (#888) ## Description - makes getCycle to emit richer content - both a _name_ and _dependencyTypes_ for now, instead of a string. This is a breaking change on the API _only_ - rules keep the same interface and behavior. ## Motivation and Context So we can define rules on the additional attributes - prerequisite to fixing #695 ## How Has This Been Tested? - [x] green ci - [x] additional automated non-regression tests ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] Documentation only change - [ ] Refactor (non-breaking change which fixes an issue without changing functionality) - [x] New feature (non-breaking change which adds functionality) - [x] Breaking change (fix or feature that would cause existing functionality to change) - on the API only.
…te against dependency types (BREAKING for API users) (#894) ## Description - restructures the via* sub restrictions to also accept & validate against dependency types - deprecates the viaNot and viaSomeNot restrictions in favor of viaOnly.pathNot and via.pathNot restrictions respectively. You could still have them in dependency-cruiser configs, but internally they're rewritten into `viaOnly` and `via` rules when possible. This is a breaking change for the API only - in the input/ rules instead of a string | string[] the via and viaOnly restrictions can now also be an object with `path`, `pathNot`, `dependencyTypes` and `dependencyTypesNot` attributes - in the cruise result via and viaOnly are _only_ available as that object (in stead of string | string[]) - in the cruise result the `viaNot` and `viaSomeNot` have disappeared (rules in the input will have been rewritten as via or viaOnly rules). ## Motivation and Context There's a long outstanding and much upvoted request (#695) to be able to exclude e.g. type-only over a whole cycle instead to just the first dependency of the cycle. This PR enables that. ## How Has This Been Tested? - [x] green ci - [x] additional automated non-regression tests ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] Documentation only change - [ ] Refactor (non-breaking change which fixes an issue without changing functionality) - [x] New feature (non-breaking change which adds functionality) - [x] Breaking change (fix or feature that would cause existing functionality to change) => for API only
Hi @alvaro-cuesta thanks for your interest in picking this up! There were quite a few things that needed doing to enable this feature - and t.b.h. I didn't oversee exactly which ones.
Fixed: as of [email protected]Anyway - in // ...
// log an error for all circular dependencies which consist of only non-`type-only`
// dependencies, so e.g.
// violation : a -import-> b -import-> c -import-> a
// OK : a -import-> b -import,type-only-> c -import-> a
{
name: 'no-circular-at-runtime',
severity: 'error',
from: {
},
to: {
circular: true,
viaOnly: {
dependencyTypesNot: ['type-only']
}
}
},
// ... Documentation: rules-reference.md#circular. A similar exercise needs to be done for reachability rules, which should address #763. |
@camillef, @alvaro-cuesta (and all the people who upvoted this issue) |
I am using dependency-cruiser in a React app written in Typescript. I would like to exclude circular type-only references from being reported as errors by dependency-cruiser, so I have updated my "no-circular" rule to include
dependencyTypesNot: ["type-only"],
as follows:However, this still reports errors for both type-only circular dependencies, and if any part of the circular dependency path is not type-only.
Expected Behavior
"dependencyTypesNot": ["type-only"]
applied to a"no-circular"
rule should mean that circular dependencies involving type-only imports do not trigger an errorCurrent Behavior
dependencyTypesNot: ["type-only"]
has no effect whencircular: true
Possible Solution
Not sure. I wondered if
viaNot
might also be able to take into account the dependency type.Steps to Reproduce (for bugs)
parent.ts
file and achild.ts
file as followsdependency-cruiser.js
depcruise --config .dependency-cruiser.js
Context
My app uses Redux for state management, and redux-toolkit listener middleware for certain behaviours. The redux-toolkit docs suggest keeping the store and its types in a
store.ts
file:and specifically recommend creating the middleware instance in a separate file from the actual
configureStore()
call, along with various helper types that depend on theRootState
:Since the middleware must be added to the store when it is configured, the
./store
file includes an import from./listenerMiddleware
. But the./listenerMiddleware
includes a type import from the./store
.The only way I have around this, for now, is to exclude the
./store
file with aviaNot
.Your Environment
The text was updated successfully, but these errors were encountered: