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