Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
purpleidea opened this issue Mar 3, 2024 · 3 comments
Open

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

purpleidea opened this issue Mar 3, 2024 · 3 comments
Labels
FeatureRequest GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@purpleidea
Copy link

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!

@seankhliao seankhliao changed the title Print file name when showing an import cycle cmd/go: print file name when showing an import cycle Mar 3, 2024
@mknyszek mknyszek added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. FeatureRequest GoCommand cmd/go labels Mar 4, 2024
@mknyszek mknyszek added this to the Backlog milestone Mar 4, 2024
@mknyszek
Copy link
Contributor

mknyszek commented Mar 4, 2024

CC @bcmills @matloob

@bcmills
Copy link
Contributor

bcmills commented Mar 5, 2024

As a minor nit, I think it would be slightly clearer like imports whatever1 (in file1.go), rather than just a :.

@purpleidea
Copy link
Author

As a minor nit, I think it would be slightly clearer like imports whatever1 (in file1.go), rather than just a :.

I don't think it's a nit, any suggestions to improve the formatting are appreciated! I don't have a good recommendation or a strong preference here. I mostly just care that the data is exposed to the user =D

One suggestion: make it easy for terminal users to copy paste out the filename. On the end is easy for most terminal emulators for example. Other ways are possible too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants