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

x/tools/imports: Removes comments if it doesn't see "package" #8637

gopherbot opened this issue Sep 3, 2014 · 1 comment


Copy link

commented Sep 3, 2014

$ printf '// i am precious\n' >i.go && goimports -d i.go
diff i.go gofmt/i.go
--- /home/tv/tmp/gofmt524290255 2014-09-03 11:33:53.118042810 -0700
+++ /home/tv/tmp/gofmt219767778 2014-09-03 11:33:53.118042810 -0700
@@ -1 +1 @@
-// i am precious
$ gofmt -d i.go 
i.go:1:18: expected 'package', found 'EOF'

$ printf '// i am precious\nfunc f() {}' >i.go && goimports -d i.go
diff i.go gofmt/i.go
--- /home/tv/tmp/gofmt433476709 2014-09-03 11:36:09.002716626 -0700
+++ /home/tv/tmp/gofmt636561536 2014-09-03 11:36:09.002716626 -0700
@@ -1,2 +1 @@
-// i am precious
 func f() {}
\ No newline at end of file

I'm ok with getting an error about invalid Go, or having a still-invalid file that
preserves the comments. I am not ok with losing my input.

This is extra annoying when goimports is hooked into editor save, and I move a
documented function into a new file.

This comment has been minimized.

Copy link

commented Sep 3, 2014

Comment 1:

Labels changed: added repo-tools, release-none.

@gopherbot gopherbot added new labels Sep 3, 2014

@bradfitz bradfitz removed the new label Dec 18, 2014

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc removed the release-none label Apr 10, 2015

@rsc rsc changed the title Removes comments if it doesn't see "package" x/tools/imports: Removes comments if it doesn't see "package" Apr 14, 2015

@rsc rsc modified the milestones: Unreleased, Unplanned Apr 14, 2015

@rsc rsc removed the repo-tools label Apr 14, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
4 participants
You can’t perform that action at this time.