Skip to content

Inconsistencies in circular dependency detection #447

@yoz

Description

@yoz

madge does not detect all circular dependencies or even all files with circular dependencies. I think this is a fundamental issue with the algorithm in cyclic.js. (There may be some good suggestions in here: https://stackoverflow.com/questions/546655/finding-all-cycles-in-a-directed-graph)

I created some minimal test cases here (including graphviz diagrams in case that helps):

yoz@847668f

Explanation:

  • "defg" case: There are two cycles: d -> e -> g -> d and d -> f -> g -> d. However, madge never reports the d -> f -> g case (or indeed that f belongs to a cycle), regardless of which file(s) we use as the starting input.
  • "bcdeg" case: There are two cycles: d -> c -> g -> d and d -> e -> g -> d.
    • This is equivalent to the "defg" case (but with 'c' instead of 'f'). Yet the madge output is different - it finds all the cycles.
    • But if we add a dependency b -> d and start at b, madge no longer reports one of the cycles.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions