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

gofmt: Convert URLs to import paths #39324

tooolbox opened this issue May 30, 2020 · 3 comments

gofmt: Convert URLs to import paths #39324

tooolbox opened this issue May 30, 2020 · 3 comments


Copy link

@tooolbox tooolbox commented May 30, 2020

This is really a feature request, so I'm tweaking the issue template slightly.

What version of Go are you using (go version)?

$ go version
go version go1.14.1 darwin/amd64

Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

Visit, copy the URL from my address bar and paste it into an import block:

package main

import (

func main() {
    // ...

Then I hit save (which auto-runs gofmt).

What did you see?

Sublime, (or a plugin, more accurately) threw down a red underline and told me I had an invalid import path.

What would you like to see?

I think it would be handy if gofmt could remove the https://, or any scheme, automatically. (I can't think of a scenario where a scheme is valid in an import block.). This way you can straight copy a URL from an address bar, paste it in, format and move on.

I know that has a little Copy button to get just the import path, which is great for pasting into an import block, but often I'm just browsing GitHub and want to pull in that repo, and this would facilitate.

Copy link

@mvdan mvdan commented May 30, 2020

gofmt deals with formatting, while "fixing" imports is an entirely different matter. So I don't think it fits the tool.

Also, going from a source repository URL to an import path isn't as simple as removing the https:// prefix. For example, one of my packages is on github as, but its module path is actually A tool to fix such URLs would need to have a good amount of code to deal with all the edge cases involved here.

@mvdan mvdan added the WaitingForInfo label Jun 1, 2020
Copy link

@tooolbox tooolbox commented Jun 2, 2020

I wasn't suggesting that the tool would attempt to divine import paths. That's why I solely suggested removing schemes, because it's one thing that's always wrong in that location. It may not be the only thing, but that for sure is wrong.

Sure, maybe the functionality is more suited to goimports. I only use gofmt so I wouldn't benefit, but I get what you're saying.

Copy link

@tooolbox tooolbox commented Jun 3, 2020

I get a feeling this won't go anywhere, so I'm going to close it. Thanks for your time :)

@tooolbox tooolbox closed this Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.