mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
Revert "imports: support repairing import grouping/ordering"
This reverts commit CL 116795 12a7c317e894c0a622b5ed27f0a102fcdd56d1ad. Reason for revert: mangles comments in imports. See comments on issue golang/go#20818. Updates golang/go#20818 Change-Id: Iff82f8dc310dceb982b48d82b26176ea279fef10 Reviewed-on: https://go-review.googlesource.com/c/144339 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
parent
40a48ad93f
commit
a2dc47679d
@ -514,6 +514,7 @@ c = fmt.Printf
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gu"
|
"gu"
|
||||||
|
|
||||||
"github.com/foo/bar"
|
"github.com/foo/bar"
|
||||||
@ -604,11 +605,15 @@ var _, _, _, _, _ = fmt.Errorf, io.Copy, strings.Contains, renamed_bar.A, B
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
renamed_bar "github.com/foo/bar"
|
renamed_bar "github.com/foo/bar"
|
||||||
|
|
||||||
|
"io"
|
||||||
|
|
||||||
. "github.com/foo/baz"
|
. "github.com/foo/baz"
|
||||||
|
|
||||||
|
"strings"
|
||||||
|
|
||||||
_ "github.com/foo/qux"
|
_ "github.com/foo/qux"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1044,149 +1049,6 @@ var _ = fmt.Printf
|
|||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
// golang.org/issue/20818
|
|
||||||
{
|
|
||||||
name: "sort_all_groups",
|
|
||||||
in: `package p
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"context"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _, _, _ = testing.T, logrus.Entry, context.Context
|
|
||||||
`,
|
|
||||||
out: `package p
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _, _, _ = testing.T, logrus.Entry, context.Context
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// golang.org/issue/20818
|
|
||||||
{
|
|
||||||
name: "sort_many_groups",
|
|
||||||
in: `package p
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
|
||||||
|
|
||||||
"fmt"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
"golang.org/x/tools/cover"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"context"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _, _, _, _, _, _ = testing.T, logrus.Entry, context.Context, meta.AnyGroup, fmt.Printf, errors.Frame
|
|
||||||
`,
|
|
||||||
out: `package p
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _, _, _, _, _, _ = testing.T, logrus.Entry, context.Context, meta.AnyGroup, fmt.Printf, errors.Frame
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// golang.org/issue/20818
|
|
||||||
{
|
|
||||||
name: "sort_all_groups_with_blanks_and_comments",
|
|
||||||
in: `package p
|
|
||||||
import (
|
|
||||||
|
|
||||||
|
|
||||||
"testing"
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
|
||||||
|
|
||||||
// a comment for the "fmt" package (#26921: they are broken, should be fixed)
|
|
||||||
"fmt"
|
|
||||||
"github.com/pkg/errors" // some comment
|
|
||||||
|
|
||||||
|
|
||||||
"golang.org/x/tools/cover"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"context"
|
|
||||||
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
var _, _, _, _, _, _ = testing.T, logrus.Entry, context.Context, meta.AnyGroup, fmt.Printf, errors.Frame
|
|
||||||
`,
|
|
||||||
out: `package p
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/pkg/errors" // some comment
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta" // a comment for the "fmt" package (#26921: they are broken, should be fixed)
|
|
||||||
)
|
|
||||||
|
|
||||||
var _, _, _, _, _, _ = testing.T, logrus.Entry, context.Context, meta.AnyGroup, fmt.Printf, errors.Frame
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: "sort_all_groups_with_local_packages",
|
|
||||||
in: `package p
|
|
||||||
import (
|
|
||||||
"local/foo"
|
|
||||||
"testing"
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
|
||||||
|
|
||||||
"fmt"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
"github.com/local/bar"
|
|
||||||
"golang.org/x/tools/cover"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"context"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _, _, _, _, _, _ = testing.T, logrus.Entry, context.Context, meta.AnyGroup, fmt.Printf, errors.Frame
|
|
||||||
var _, _ = foo.Foo, bar.Bar
|
|
||||||
`,
|
|
||||||
out: `package p
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
|
||||||
|
|
||||||
"github.com/local/bar"
|
|
||||||
"local/foo"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _, _, _, _, _, _ = testing.T, logrus.Entry, context.Context, meta.AnyGroup, fmt.Printf, errors.Frame
|
|
||||||
var _, _ = foo.Foo, bar.Bar
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
{
|
||||||
name: "cryptorand_preferred_easy_possible",
|
name: "cryptorand_preferred_easy_possible",
|
||||||
in: `package p
|
in: `package p
|
||||||
|
@ -34,8 +34,18 @@ func sortImports(fset *token.FileSet, f *ast.File) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort and regroup all imports.
|
// Identify and sort runs of specs on successive lines.
|
||||||
sortSpecs(fset, f, d.Specs)
|
i := 0
|
||||||
|
specs := d.Specs[:0]
|
||||||
|
for j, s := range d.Specs {
|
||||||
|
if j > i && fset.Position(s.Pos()).Line > 1+fset.Position(d.Specs[j-1].End()).Line {
|
||||||
|
// j begins a new run. End this one.
|
||||||
|
specs = append(specs, sortSpecs(fset, f, d.Specs[i:j])...)
|
||||||
|
i = j
|
||||||
|
}
|
||||||
|
}
|
||||||
|
specs = append(specs, sortSpecs(fset, f, d.Specs[i:])...)
|
||||||
|
d.Specs = specs
|
||||||
|
|
||||||
// Deduping can leave a blank line before the rparen; clean that up.
|
// Deduping can leave a blank line before the rparen; clean that up.
|
||||||
if len(d.Specs) > 0 {
|
if len(d.Specs) > 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user