dart-lang / linter

Linter for Dart.
https://dart.dev/tools/linter-rules
BSD 3-Clause "New" or "Revised" License
631 stars 170 forks source link

Lint cyclic dependencies between folders #617

Open alexeieleusis opened 7 years ago

alexeieleusis commented 7 years ago

If classes in two different folders within a package have dependencies, it should be linted. It is not necessary to be the two same classes.

The idea is to lint what in java or c# would be a cyclic package or namespace dependency respectively.

Ideally should be extended to cyclic dependencies between dart packages. Though hopefully that is not an issue.

bwilkerson commented 7 years ago

I need some clarification to understand the proposal.

If classes in two different folders within a package have dependencies ...

Is it really classes you care about? What about references from within top-level functions? (I suspect you really mean "library" rather than "class".)

Do you mean where both classes / libraries are in a single package?

Other than personal taste, is there a reason for this check? Dart supports cyclic dependencies between libraries without any problem. Why does it matter whether the libraries are in the same folder or a different folder? (Dart also supports cyclic dependencies between packages without problems.)

alexeieleusis commented 7 years ago

I took the idea from FxCop, SonarQube and the like and as you say is a matter of taste, I have noticed that most people don't really care about this.

There is a group of people though, that think that this makes code easier to reason about, easier to maintain, etc.

In a way with jars, dlls and bazel packages there is a level of enforcement to that effect, but for big projects that is not enough and I personally have worked on codebases where when following the logic I go through these kind of cycles and there comes a point where I just don't know at what level I am.

This kind of analysis probably does not belong in the linter, at least needs some discussion, but I keep forgetting to file it.