1
0
mirror of https://github.com/golang/go synced 2024-10-01 07:28:35 -06:00
Commit Graph

21 Commits

Author SHA1 Message Date
Robert Griesemer
35f54f0ea0 imports: adjust tests to check vendored packages again (fix build)
Change-Id: I616dccc07c255bb7ca1146ad0d37d05999eeb772
Reviewed-on: https://go-review.googlesource.com/21142
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-03-25 17:11:48 +00:00
Ahmy Yulrizka
6e94e8a89f imports: cleanup test due to assignment copies of sync.Once
go vet detected that the value of pkgIndexOnce
is copied through assignments in the test.
This patch fixes that by converting it to *sync.Once instead.

Change-Id: I90b2252942625b2f8a93eb5da24d16c6a8a56e4e
Reviewed-on: https://go-review.googlesource.com/20910
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-20 22:53:05 +00:00
Robert Griesemer
95e5e62424 imports: fix TestFindImportVendor for 1.5 (fix build)
TBR=adonovan

Change-Id: I7edeb180bdf09648e7539b9371db0d14272b9030
Reviewed-on: https://go-review.googlesource.com/20697
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-03-15 04:38:51 +00:00
Robert Griesemer
8852e49d27 imports: adjust tests to fix build
These changes will need to be reverted once we use
vendoring in the stdlib again, but it's trivial to
do so when the time comes.

TBR=adonovan

Fixes #14823.

Change-Id: I2173c48d5466874492affc679332f6484bf96592
Reviewed-on: https://go-review.googlesource.com/20695
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-03-15 04:38:37 +00:00
David R. Jenni
e852fdd89f go/ast/astutil: add function DeleteNamedImport.
DeleteNamedImport deletes the import with a given
name and path from a parsed file, if present.

imports uses this function to delete named imports.

Fixes golang/go#8149.

Change-Id: I84539d5627191c45f06db2d008507aee4d3b1eb2
Reviewed-on: https://go-review.googlesource.com/19951
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-02-26 17:37:10 +00:00
Russ Cox
bf084ef758 imports: add support for vendor directories
Editor modes that invoke the goimports command on temporary copies
of actual source files will need to invoke goimports -srcdir now to say
where the real source directory is. Otherwise goimports will not consider
vendored or internal packages when looking for new imports.

In lieu of a test for cmd/goimports (because it has no tests),
a command transcript:

	$ cd /tmp
	$ cat x.go
	package p
	var _ = hpack.HuffmanDecode
	$

	$ GOPATH= goimports < x.go
	package p

	var _ = hpack.HuffmanDecode
	$ GOPATH= goimports x.go
	package p

	var _ = hpack.HuffmanDecode
	$

But with the new flag:

	$ GOPATH= goimports -srcdir $GOROOT/src/math < x.go
	package p

	import "golang.org/x/net/http2/hpack"

	var _ = hpack.HuffmanDecode
	$ GOPATH= goimports -srcdir $GOROOT/src/math x.go
	package p

	import "golang.org/x/net/http2/hpack"

	var _ = hpack.HuffmanDecode
	$

The tests in this CL and the above transcript assume that
$GOROOT/src/vendor/golang.org/x/net/http2/hpack exists.
It did in 40a26c9, but it does not today.
It will again soon (once Go 1.7 opens).

For golang/go#12278 (original request).

Change-Id: I27b136041f54edcde4bf474215b48ebb0417f34d
Reviewed-on: https://go-review.googlesource.com/17728
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-02-18 16:47:46 +00:00
David R. Jenni
4f50f44d7a imports: fix bug, where unused named import is mistaken for unnamed import.
Fixes #8149.

Change-Id: Ia3d318f70981b2032a71d3fd32eaffba20cfbcbd
Reviewed-on: https://go-review.googlesource.com/13371
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-12 17:18:37 +00:00
Josh Bleecher Snyder
57d2ff39c7 go/ast/astutil: match prefix segments when adding imports
AddImport and AddNamedImport attempt to place new
imports in roughly the correct place--and thus the
correct group--by matching prefixes. Matching prefixes
byte-by-byte led to "regexp" being grouped with "rsc.io/p".
Instead, match prefixes by segments.

Fixes golang/go#9961.

Change-Id: I52b7c58a9a2fbe85c2b5297e50c87d409364bda3
Reviewed-on: https://go-review.googlesource.com/8090
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-03-30 17:57:25 +00:00
David Symonds
0513cb08b6 go.tools/imports: Permit fix_test.go to work pre-Go 1.4.
LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/156980043
2014-10-13 08:44:37 +11:00
Alan Donovan
159879b336 go.tools/imports: src/pkg -> src
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/141260043
2014-09-08 14:20:12 -04:00
Josh Bleecher Snyder
cc1e254c18 go.tools/astutil: delete all matching imports in DeleteImport
Fixes golang/go#8459.

LGTM=crawshaw, bradfitz
R=bradfitz, crawshaw
CC=golang-codereviews
https://golang.org/cl/128220043
2014-08-14 11:51:51 -07:00
Josh Bleecher Snyder
3442faf3c1 go.tools/imports: go/format outbound code
Fixes golang/go#8035.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews, shurcool
https://golang.org/cl/120840044
2014-07-28 17:15:17 -07:00
Dmitri Shuralyov
1154a04eb0 go.tools/imports: fix case where output not gofmt-compatible
Fixes 7866. Adds a test case.

When trying to add newlines before certain imports via text manipulation,
a regex is used to iterate over all imports. The regex failed to match
dot imports because \w doesn't match a literal dot. This changes the regex
to accept a dot as well.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/99400043
2014-05-20 14:02:16 -07:00
Dmitri Shuralyov
c0060eca2c go.tools/astutil: fix edge case in DeleteImport causing merging of import sections.
The issue occurs only when deleting an import that has a blank line immediately preceding,
and other imports before that.

Currently, DeleteImport assumes there's a blank line-sized hole left behind
where the import was, and always deletes it. That blank line-sized hole is there in all cases
except the above edge case.

This fix checks for that edge case, and does not remove the blank line-sized hole.

The CL also adds a previously failing test case that catches this scenario. After the change to
DeleteImport, the new test passes (along with all other tests).

Fixes golang/go#7679.

Note that there is no attempt to ensure the result *ast.File and *token.FileSet are perfectly
matching to what you would get if you printed the AST and parsed it back. This is how the
rest of the package and the current tests work (i.e., they only check that printing the AST gives
the correct output).
Changing that is very hard, if not impossible, at least not
without resorting to manipulating AST via printing, text manipulation and parsing.
This is okay for most usages, but it does create potential problems. For example,
astutil.Imports() currently only works correctly on freshly parsed AST. If that AST
is manipulated via astutil funcs, then Imports() may not always generate correct
output. However, thas is a separate issue and should be treated as such.

LGTM=bradfitz
R=golang-codereviews, gobot, adonovan, bradfitz
CC=golang-codereviews
https://golang.org/cl/92250045
2014-05-19 14:04:30 -07:00
Stephen Weinberg
55d5722095 imports, cmd/goimports: add missing package main if func main exists
Assuming:
        1) package declaration does not exist
        2) the Fragment option is set
        3) a main function exists

We will assume it is a main package and add the declaration.

This change also sets the Fragment option in goimports.

LGTM=crawshaw, bradfitz
R=bradfitz, crawshaw
CC=golang-codereviews
https://golang.org/cl/96850044
2014-04-28 17:15:33 -04:00
Sameer Ajmani
a1c1cf19ba imports: extend findImports to return a boolean, rename, that tells
goimports to use the package name as a local qualifier in an import.
For example, if findImports("pkg", "X") returns ("foo/bar",
rename=true), then goimports adds the import line:
  import pkg "foo/bar"
to satisfy uses of pkg.X in the file.

This change doesn't add any implementations of rename=true, though one
is sketched in a TODO.

LGTM=crawshaw
R=crawshaw, rsc
CC=bradfitz, golang-codereviews
https://golang.org/cl/76400050
2014-03-25 09:37:10 -04:00
Brad Fitzpatrick
a0c2140b91 imports: fix a case where we weren't gofmt-compatible
Because goimports also sorts stdlib-vs-external differently
(whereas gofmt just sorts string-wise), we need to put a blank
line between imports of different classes. This happened in
some cases, but not all.

Fixes golang/go#7132

LGTM=kamil.kisiel
R=golang-codereviews, kamil.kisiel
CC=golang-codereviews
https://golang.org/cl/60870047
2014-02-07 17:03:34 -08:00
Brad Fitzpatrick
eda00ba4ec imports: bake in the standard library again
Fast path for the common case. Avoids scanning GOPATH usually.

LGTM=r, crawshaw
R=david.crawshaw, adg, r, crawshaw
CC=golang-codereviews
https://golang.org/cl/56820043
2014-01-26 09:47:31 -08:00
Brad Fitzpatrick
b6e674b8e7 go.tools/imports: fix fileset mismatch bug
Fixes golang/go#6884

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/43890043
2013-12-18 09:09:37 -08:00
David Crawshaw
64c6d0410b go.tools/imports: fix test broken in b33d2e25015b6793aac4f9dcef3d8a8d1c9243b3
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/41950048
2013-12-18 03:44:50 -08:00
David Crawshaw
c87866116c go.tools/imports: move goimports from github to go.tools.
From revision d0880223588919729793727c9d65f202a73cda77.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/35850048
2013-12-17 21:21:03 -05:00