unreachable method
Library files that no entry point can reach.
Walks edges from every file in roots and from every file outside a
lib/ — tests, tools, examples are entry points by nature — and reports
the library files never visited. Unlike unreferenced this sees through
a dead barrel to the files it exports, and through a pair of dead files
that import each other. It is only as good as roots: an entry point
the caller failed to name is reported along with everything only it
reaches.
Implementation
List<String> unreachable({required Set<String> roots}) {
final queue = <String>[
...roots.where(edges.containsKey),
...edges.keys.where((f) => !isLibraryFile(f)),
];
final visited = queue.toSet();
var head = 0;
while (head < queue.length) {
for (final next in edges[queue[head++]] ?? const <String>{}) {
if (visited.add(next)) queue.add(next);
}
}
return edges.keys
.where((file) => isLibraryFile(file) && !visited.contains(file))
.toList()
..sort();
}