Please file a bug. I lose emails.

On Sat, Jul 16, 2016 at 1:29 PM, Vince Prignano <vincenzo.prign...@gmail.com
> wrote:

> I just noticed that import paths that start with an uppercase letter don't
> get imported automatically after the update.
>
> Looking at the code and
> https://github.com/golang/tools/blob/master/imports/fix.go#L651,
> I tried to change the behavior, using strings.ToLower on
> `lastTwoComponents` like:
>
> for _, pkg := range dirScan {
> if
> !strings.Contains(strings.ToLower(lastTwoComponents(pkg.importPathShort)),
> pkgName) {
> // Speed optimization to minimize disk I/O:
> // the last two components on disk must contain the
> // package name somewhere.
> //
> // This permits mismatch naming like directory
> // "go-foo" being package "foo", or "pkg.v3" being "pkg",
> // or directory "google.golang.org/api/cloudbilling/v1"
> // being package "cloudbilling", but doesn't
> // permit a directory "foo" to be package
> // "bar", which is strongly discouraged
> // anyway. There's no reason goimports needs
> // to be slow just to accomodate that.
> continue
> }
> if !canUse(filename, pkg.dir) {
> continue
> }
> candidates = append(candidates, pkg)
> }
>
> and the imports work again like before.
>
>
> This is the test case:
>
> func TestFindImportGoPath(t *testing.T) {
> goroot, err := ioutil.TempDir("", "goimports-")
> if err != nil {
> t.Fatal(err)
> }
> defer os.RemoveAll(goroot)
>
> origStdlib := stdlib
> defer func() {
> stdlib = origStdlib
> }()
> stdlib = nil
>
> withEmptyGoPath(func() {
> // Test against imaginary bits/bytes package in std lib
> bytesDir := filepath.Join(goroot, "src", "pkg", "bits", "Bytes")
> for _, tag := range build.Default.ReleaseTags {
> // Go 1.4 rearranged the GOROOT tree to remove the "pkg" path component.
> if tag == "go1.4" {
> bytesDir = filepath.Join(goroot, "src", "bits", "Bytes")
> }
> }
> if err := os.MkdirAll(bytesDir, 0755); err != nil {
> t.Fatal(err)
> }
> bytesSrcPath := filepath.Join(bytesDir, "bytes.go")
> bytesPkgPath := "bits/Bytes"
> bytesSrc := []byte(`package bytes
>
> type Buffer2 struct {}
> `)
> if err := ioutil.WriteFile(bytesSrcPath, bytesSrc, 0775); err != nil {
> t.Fatal(err)
> }
> build.Default.GOROOT = goroot
>
> got, rename, err := findImportGoPath("bytes", map[string]bool{"Buffer2":
> true}, "x.go")
> if err != nil {
> t.Fatal(err)
> }
> if got != bytesPkgPath || !rename {
> t.Errorf(`findImportGoPath("bytes", Buffer2 ...)=%q, %t, want "%s",
> false`, got, rename, bytesPkgPath)
> }
>
> got, rename, err = findImportGoPath("bytes", map[string]bool{"Missing":
> true}, "x.go")
> if err != nil {
> t.Fatal(err)
> }
> if got != "" || rename {
> t.Errorf(`findImportGoPath("bytes", Missing ...)=%q, %t, want "", false`,
> got, rename)
> }
> })
> }
>
>
>
> -Vince
>
> On Thursday, July 14, 2016 at 10:34:36 PM UTC-7, bradfitz wrote:
>
>> goimports has been updated.
>>
>> If you've been frustrated by its speed lately, run:
>>
>>    $ go get -u golang.org/x/tools/cmd/goimports
>>
>> ... and things should be much nicer.
>>
>> Details at https://golang.org/cl/24941
>>
>> If I broke something, file a bug: https://golang.org/issues/new
>>
>> The general speed tracking bug is https://golang.org/issue/16367 (don't
>> use for new bugs, only for speed)
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to