Rule: Detect cyclic dependencies in code #4543
Replies: 2 comments
-
That's a bit outside the scope of Detekt. We don't have any capability at the moment to analyze more than one file. If we were do develop something like this, I believe it would be a separate tool and not a rule. |
Beta Was this translation helpful? Give feedback.
-
In addition to what Nico said, the Dependency Matrix tool works differently compared to detekt. The Dependency Matrix tool utilizes bytecode whereas detekt uses an abstract syntax tree. The analysis on bytecode level is necessary due to performance aspects, because the tool has to build a model of the complete source code with all of its dependencies. To my knowledge no such tool based on detekt exists. Bytecode fits better for the mentioned use cases. |
Beta Was this translation helpful? Give feedback.
-
Expected Behavior of the rule
I try to avoid cycles. In fact, I strive for all the code I write to have zero cycles e.g. some code A depends on code B which depends on A.
Cycles could be more complex as well: A -> B -> C -> ... -> A
It would be amazing if Detekt had a "CyclicDependencies" rule which detects cycles and triggers when it sees any type of cyclic dependency. By default at the module and package level, and optionally even at the file level.
Context
If you've ever used IntelliJ IDEA's "Analyze Code / Dependency Matrix..." function, you'll know what I'm talking about here -- that is an amazing tool to understand dependencies between code at different levels: files, packages, modules.
It very clearly shows where there are cycles in the code and provides the mechanism to understand them. Sometimes cycles sneak in though, and aren't detected until someone runs the tool.
Having detekt detect and report on this would be great.
Beta Was this translation helpful? Give feedback.
All reactions