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

internal/imports: use first quote when matching import path #365

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions internal/imports/fix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,37 @@ var _, _, _, _, _ = fmt.Errorf, io.Copy, strings.Contains, renamed_packagea.A, B
`,
},

// Blank line can be added even when first import of group has comment with quote
{
name: "new_section_where_trailing_comment_has_quote",
in: `package main

import (
"context"
bar "local.com/bar"
baz "local.com/baz"
buzz "local.com/buzz"
"github.com/golang/snappy" // this is a "typical" import
)

var _, _, _, _, _ = context.Background, bar.B, baz.B, buzz.B, snappy.ErrCorrupt
`,
out: `package main

import (
"context"

"github.com/golang/snappy" // this is a "typical" import

bar "local.com/bar"
baz "local.com/baz"
buzz "local.com/buzz"
)

var _, _, _, _, _ = context.Background, bar.B, baz.B, buzz.B, snappy.ErrCorrupt
`,
},

// Non-idempotent comment formatting
// golang.org/issue/8035
{
Expand Down
2 changes: 1 addition & 1 deletion internal/imports/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func matchSpace(orig []byte, src []byte) []byte {
return b.Bytes()
}

var impLine = regexp.MustCompile(`^\s+(?:[\w\.]+\s+)?"(.+)"`)
var impLine = regexp.MustCompile(`^\s+(?:[\w\.]+\s+)?"(.+?)"`)

func addImportSpaces(r io.Reader, breaks []string) ([]byte, error) {
var out bytes.Buffer
Expand Down