Skip to content

cmd/go: print file name when showing an import cycle #66078

@purpleidea

Description

@purpleidea

We've all hit the common:

package foo
	imports whatever1
	imports whatever2
	imports whatever3
	imports bar: import cycle not allowed

It would great if it showed the actual file name of the imports, so that when there are multiple files in a package, it's easier to narrow down which one is the offender.

Eg:

package foo: blah.go
	imports whatever1: file1.go
	imports whatever2: something.go
	imports whatever3: thing.go
	imports bar: import cycle not allowed

Of course a more symmetrical approach might look like:

import cycle not allowed
imports foo: blah.go
imports whatever1: file1.go
imports whatever2: something.go
imports whatever3: thing.go
imports package foo

But whatever the formatting the code idea is that we make it easier for the user to know which file was part of the loop.

What about the situation of more than one file offending? Well this is a topological sort, so we already only guarantee that we print a single loop, even when there are more than one paths.

Of note, we don't want a full absolute path printed, we already know where things should be based on package name, we do care about the relative file path in that package.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.GoCommandcmd/goNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions