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

Closed
tooolbox opened this issue May 30, 2020 · 3 comments
Closed

gofmt: Convert URLs to import paths #39324

tooolbox opened this issue May 30, 2020 · 3 comments

Comments

@tooolbox
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?

Yes.

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

go env Output
$ go env
GOARCH="amd64"
GOOS="darwin"

What did you do?

Visit https://github.com/spf13/viper, copy the URL from my address bar and paste it into an import block:

package main

import (
    "https://github.com/spf13/viper"
)

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 https://pkg.go.dev 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.

@mvdan
Copy link
Member

@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 https://github.com/mvdan/sh, but its module path is actually mvdan.cc/sh/v3. 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
@tooolbox
Copy link
Author

@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.

@tooolbox
Copy link
Author

@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
Projects
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.