Skip to content
Permalink
Browse files

gen: ensure that we follow gofumpt -s

This makes the tool's code consistent with itself, even the code that we
copy from gofmt and goimports.

While at it, update x/tools.
  • Loading branch information
mvdan committed Nov 17, 2019
1 parent eb44264 commit 6173d0b4ed28f72d637f7c9c902125ca95104528
Showing with 162 additions and 149 deletions.
  1. +7 −0 doc.go
  2. +1 −1 go.mod
  3. +2 −2 go.sum
  4. +0 −1 gofumports/internal/gopathwalk/walk.go
  5. +9 −2 gofumports/internal/imports/fix.go
  6. +143 −143 gofumports/internal/imports/zstdlib.go
7 doc.go
@@ -3,5 +3,12 @@

package main

// First, sync the files with x/tools and GOROOT.
//go:generate go run gen.go

// Then, add the missing imports to our added code.
//go:generate goimports -w .

// Finally, ensure all code follows 'gofumpt -s'. Use the current source, to not
// need an extra 'go install' step.
//go:generate go run . -s -w .
2 go.mod
@@ -4,6 +4,6 @@ go 1.12

require (
github.com/rogpeppe/go-internal v1.5.0
golang.org/x/tools v0.0.0-20191104232314-dc038396d1f0
golang.org/x/tools v0.0.0-20191116214431-80313e1ba718
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)
4 go.sum
@@ -10,8 +10,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191104232314-dc038396d1f0 h1:azkp5oIgy7LNGQ64URezZccjePaEGSYIHEgYTn/bfXI=
golang.org/x/tools v0.0.0-20191104232314-dc038396d1f0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191116214431-80313e1ba718 h1:cWviR33VVbwok1/RNvFm9XHNcdJCsaSocBflkEXrIdo=
golang.org/x/tools v0.0.0-20191116214431-80313e1ba718/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@@ -266,5 +266,4 @@ func (w *walker) shouldTraverse(dir string, fi os.FileInfo) bool {
}
path = parent
}

}
@@ -643,6 +643,13 @@ func getCandidatePkgs(pkgName, filename string, env *ProcessEnv) ([]*pkg, error)
return result, nil
}

func candidateImportName(pkg *pkg) string {
if importPathToAssumedName(pkg.importPathShort) != pkg.packageName {
return pkg.packageName
}
return ""
}

// getAllCandidates gets all of the candidates to be imported, regardless of if they are needed.
func getAllCandidates(filename string, env *ProcessEnv) ([]ImportFix, error) {
pkgs, err := getCandidatePkgs("", filename, env)
@@ -654,6 +661,7 @@ func getAllCandidates(filename string, env *ProcessEnv) ([]ImportFix, error) {
result = append(result, ImportFix{
StmtInfo: ImportInfo{
ImportPath: pkg.importPathShort,
Name: candidateImportName(pkg),
},
IdentName: pkg.packageName,
FixType: AddImport,
@@ -679,6 +687,7 @@ func getPackageExports(completePackage, filename string, env *ProcessEnv) ([]Pac
fix := &ImportFix{
StmtInfo: ImportInfo{
ImportPath: pkg.importPathShort,
Name: candidateImportName(pkg),
},
IdentName: pkg.packageName,
FixType: AddImport,
@@ -878,7 +887,6 @@ func (r *goPackagesResolver) loadPackageNames(importPaths []string, srcDir strin
names[path] = importPathToAssumedName(path)
}
return names, nil

}

func (r *goPackagesResolver) scan(refs references, _ bool, _ []gopathwalk.RootType) ([]*pkg, error) {
@@ -954,7 +962,6 @@ func addExternalCandidates(pass *pass, refs references, filename string) error {
defer wg.Done()

found, err := findImport(ctx, pass, dirScan, pkgName, symbols, filename)

if err != nil {
firstErrOnce.Do(func() {
firstErr = err

0 comments on commit 6173d0b

Please sign in to comment.
You can’t perform that action at this time.