1
0
mirror of https://github.com/golang/go synced 2024-10-01 04:08:32 -06:00
Commit Graph

283 Commits

Author SHA1 Message Date
Dmitri Shuralyov
cccd43354a cmd/vet: fix bug where incorrect exit code was returned
Fixes golang/go#8792.

This is a simple change that fixes the issue. It may be desireable
to opt for a larger code change that makes this problem less likely
to be inadvertedly reintroduced in the future. For instance, a vetMain()
func can be used similar to gofmtMain(), or the os.Exit call can be
deferred.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/150850043
2014-10-02 10:33:35 -07:00
Josh Bleecher Snyder
e62e5f9885 go.tools/cmd/vet: remove duplicate test file
In CL 145360043, I hg cp'd copylock.go to copylock_func.go instead of hg mv. Oops.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/143660043
2014-09-26 15:09:18 -07:00
Robert Griesemer
315249fc55 cmd/vet: provide access to externally defined types
Preliminaries for fixing issue 6212.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/145370043
2014-09-24 13:54:50 -07:00
Josh Bleecher Snyder
2cd071c190 go.tools/cmd/vet: warn about copying locks in range statements
Fixes golang/go#8356.

LGTM=r
R=r, dsymonds
CC=golang-codereviews
https://golang.org/cl/145360043
2014-09-24 12:35:15 -07:00
Alan Donovan
e94ae77171 refactor: minor no-op fixes
- fix typos and mistakes in docstrings, usage message and comments.
- remove 'backup' parameter to rewriteFile

LGTM=sameer
R=sameer
CC=golang-codereviews
https://golang.org/cl/147980043
2014-09-23 15:17:49 -04:00
Alan Donovan
74021b4175 cmd/gorename: a precise, type-aware renaming tool for Go identifiers.
See the usage message in main.go for orientation.

To the best of my knowledge, the tool implements all required
soundness checks, except:
- the dynamic behaviour of reflection is obviously undecidable.
- it rejects method renamings that change the "implements" relation.
  It should probably be more aggressive.
- actually it only checks the part of the "implements" relation
  needed for compilation.  Understanding the dynamic behaviour
  of interfaces is obviously undecidable.
- a couple of minor gaps are indicated by TODO comments.

Also:
- Emacs integration.
- tests of all safety checks and (some) successful rewrites.

LGTM=dominik.honnef, sameer
R=gri, sameer, dominik.honnef
CC=golang-codereviews
https://golang.org/cl/139150044
2014-09-23 10:23:04 -04:00
Alan Donovan
6c93dbff3e go.tools/godoc: deal with fallout from $GOROOT/src/pkg -> $GOROOT/src renaming.
To avoid breaking URLs, we redirect /src/pkg/* to /src/*.

The URL /pkg is now the "directory" /src, which triggers the
"Packages" index.

All other references to "src/pkg" are now gone,
except a number in the namespace documentation which are
probably still illustrative.

Tested: go test cmd/godoc godoc
        Manual inspection of src and src/pkg pages.
        with GOROOT and GOPATH packages
        -analysis
        /AUTHORS file URL still works

LGTM=bradfitz, adg
R=bradfitz, adg
CC=golang-codereviews
https://golang.org/cl/141770044
2014-09-10 09:02:54 -04:00
Rob Pike
e548cb3dfe go.tools/cmd/stringer: fix docs: stringer is not a "go tool"
Documentation change only. The binary will not be installed
using the "go tool" mechanism.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/133710046
2014-09-09 13:29:38 -07:00
Alan Donovan
9872f0d268 go.tools/*: replace $GOROOT/src/pkg with $GOROOT/src where appropriate.
(godoc is excluded from this CL since it will continue to use
/src/pkg in its URL namespace, making the necessary cleanup
more subtle.)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/141770043
2014-09-08 13:24:38 -04:00
Alex Brainman
d39af6c903 go.tools/cmd/stringer: add .exe suffix to executable name in TestEndToEnd
Fixes windows build

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/140360043
2014-09-08 13:55:05 +10:00
Rob Pike
d03e8a67df go.tools/cmd/stringer: delete needless subtraction of zero in generated code
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/136270043
2014-09-05 17:05:28 -07:00
Rob Pike
d0448f16e3 go.tools/cmd/stringer: add end-to-end test that compiles, runs, and verifies the generated method
In the process, fix a bug in one of the method generators.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/141130043
2014-09-05 15:42:23 -07:00
Rob Pike
75b67f833e go.tools/cmd/stringer: fix generated map code
Missed comment from previous code review.
Next up: execution tests so this won't happen again

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/134480043
2014-09-04 16:18:38 -07:00
Rob Pike
22ede605a7 go.tools/cmd/stringer: use const for names, slice for map strings
Improve the generated code by using a const instead of a var for the names string.
This requires some refactoring to get neat const() and var() blocks.
Also change the generate map code go use a single sliced string, to reduce the
size of the compiled representation (only one string value).

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/135450044
2014-09-04 16:06:51 -07:00
Rob Pike
9207f67279 go.tools/cmd/stringer: add tests
Refactor a little to make testing easier.
Add golden tests and a check fo splitIntoRuns, which is the subtlest piece.
Still to come: execution tests.

Also fix a few issues in the generated code.

LGTM=gri
R=gri
CC=golang-codereviews, josharian
https://golang.org/cl/134450044
2014-09-04 14:16:59 -07:00
Yasuhiro Matsumoto
0673c34537 go.tools/cmd/stringer: Fix build on 32bit OSs.
LGTM=r
R=golang-codereviews, gri, r
CC=golang-codereviews
https://golang.org/cl/138040043
2014-09-04 10:51:38 -07:00
Rob Pike
2c5c896732 go.tools/cmd/stringer: new tool
This tool creates String methods from constant definitions.
It's a time-saver designed to be used from go generate.
The methods generated are efficient, more so than one
is likely to create by hand.

Given

        package date

        type Day int

        const (
                Monday Day = iota
                Tuesday
                Wednesday
                Thursday
                Friday
                Saturday
                Sunday
        )

the command

        stringer -type Day

will create the file day_string.go containing

        package date

        import "fmt"

        var (
                _Day_indexes = []uint8{6, 13, 22, 30, 36, 44, 50}
                _Day_names   = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday"
        )

        func (i Day) String() string {
                if i < 0 || i >= Day(len(_Day_indexes)) {
                        return fmt.Sprintf("Day(%d)", i)
                }
                hi := _Day_indexes[i]
                lo := uint8(0)
                if i > 0 {
                        lo = _Day_indexes[i-1]
                }
                return _Day_names[lo:hi]
        }

There are several strategies for the created method chosen according to
the structure of the sequence of constants.

Handles integer types only, both signed and unsigned. That's probably
all that is needed.

Tests to follow, but the test structure will be large so sending this out
separately. The code has been heavily hand-tested but there are
some bugs. Don't depend on this until the tests are installed.

LGTM=gri
R=gri, josharian
CC=golang-codereviews
https://golang.org/cl/136180043
2014-09-03 17:27:48 -07:00
Rob Pike
1e11d05bd8 cmd/vet: simplify file-reading code per gri
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/140960043
2014-09-03 16:49:14 -07:00
Matt Jibson
59c8647562 go.tools/cmd/vet: detect suspicious shifts
LGTM=josharian, dsymonds, r
R=golang-codereviews, josharian, minux, dsymonds, dave, axwalk, adg, r
CC=golang-codereviews
https://golang.org/cl/134780043
2014-08-29 11:17:01 -07:00
David Symonds
2b15aa63b7 go.tools/cmd/vet: don't panic on zero arg Log method calls.
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/134000043
2014-08-29 08:56:35 +10:00
Robert Griesemer
5dca7d8bd1 go.tools/go/types: LookupFieldOrMethod checks method set
LookupFieldOrMethod now also decides whether a found
method is actually in the method set. Simplifies call
sites. Added corresponding API tests.

TODO (separate CL): Decide what the correct value for
the indirect result should be (as required for code
generation). For now, the result value for indirect
is unchanged from before if a field/method is found.

Fixes golang/go#8584.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/132260043
2014-08-28 13:03:13 -07:00
Alan Donovan
4abc8436bc cmd/eg: add -beforeedit flag, which specifies a command to run before editing a file.
e.g. chmod +w, checkout.

Also: add a TIPS section to the documentation.

LGTM=crawshaw
R=crawshaw, gri
CC=golang-codereviews
https://golang.org/cl/136780044
2014-08-26 15:52:40 -04:00
Rob Pike
cd9959d796 go.tools/cmd/vet: validate calls to t.Log and t.Logf
Be careful not to complain about math.Log and cmplx.Log.
Seems worthwhile since t.Log and t.Logf are often written but
rarely executed.

Nothing new turned up in the standard library.

Fixes golang/go#8504.

LGTM=josharian, dsymonds
R=golang-codereviews, josharian, dsymonds
CC=golang-codereviews
https://golang.org/cl/130490043
2014-08-25 12:31:49 -07:00
Rob Pike
671b9204b8 go.tools/cmd/vet: change message for range check
s/enclosed by function/captured by func literal/
Users complained. They often do.

LGTM=josharian, adg
R=golang-codereviews, josharian, nightlyone, minux, adg
CC=golang-codereviews
https://golang.org/cl/132080043
2014-08-24 17:26:18 -07:00
Fatih Arslan
ba91af23b8 cmd/cover: add start lines numbers to each function in -func mode
This CL aims to fix the problem described here:

https://groups.google.com/forum/#!topic/golang-nuts/R6ms1n9KjiY

This makes it easier to parse via external tools such as editors. Editors can
show each function in a list and jump directly to each function with this
additional information. This pattern can be seen in other Go tools such as "go
test" in the form of:

--- FAIL: TestCover (0.52 seconds)
        cover_test.go:43: example error

LGTM=adg
R=r, adg, josharian, dave
CC=golang-codereviews
https://golang.org/cl/131820043
2014-08-21 16:28:12 -07:00
Rob Pike
f11381f265 go.tools/cmd/cover: don't assume code is gofmt'd
We want to make an if look like two blocks and have the coverage
report for the else block decorate the "else" keyword with the right
color. To do this, we adjust the apparent starting point of the else
block to include the "else".

The previous code assumed the way to do this was to move the
width of "else " backwards from the else block's opening brace, but
that assumes there is a space there. Instead, we now just start the
else block exactly at the end of the if block. Simpler, cleaner, and
fixes a bug.

Fixes golang/go#8557.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/127620043
2014-08-20 11:14:50 -07:00
Francesc Campoy
e8a1924bfb html2article: Ignore empty anchor elements and obtain the original url from Google Docs
LGTM=adg
R=adg, campoy
CC=golang-codereviews
https://golang.org/cl/127560043
2014-08-19 17:55:46 -07:00
Andrew Gerrand
573fa9f0bd cmd/cover: show file coverage in HTML drop down
As requested on Stack Overflow: http://goo.gl/ams9fY
(Kudos to sberry for his JavaScript solution, provided there.
This change does the same thing on the server side.)

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/127030043
2014-08-12 09:22:11 +10:00
Francesc Campoy
11569f39ea go.tools/cmd/present: track page views for every slide.
LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/124720043
2014-08-05 16:02:39 -07:00
Alan Donovan
149e030318 go.tools/cmd/ssadump: print packages and functions to stdout, not stderr.
And serialize the printing of each item with a mutex.
It is the formatted output of this tool, after all.

Also: minor doc tweaks.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/114620044
2014-08-01 14:44:37 -04:00
David Symonds
105b764ad0 benchcmp: Fix invocation instructions.
`go test` takes -run and -bench; the -test.run and -test.bench flags
are only for the test binary itself.

LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/113390043
2014-07-22 17:50:39 +10:00
Keith Randall
562b65fda7 vet: LEA* opcodes don't need to have matching length source and destination.
LGTM=rsc
R=golang-codereviews, khr, rsc
CC=golang-codereviews
https://golang.org/cl/117950044
2014-07-21 21:15:39 -07:00
Robert Daniel Kortschak
09286920ba go.tools/cmd/present: move jquery ui code into static
LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/118760043
2014-07-16 16:33:46 +10:00
Francesc Campoy
bbb1c45ba5 go.tools/present: add support for figure captions
LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/110600043
2014-07-15 08:23:16 -07:00
Francesc Campoy
bb2f616e98 go.toosl/cmd/present: Remove border from iframes
If the author wants a border they can add it on their own.

LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/107590045
2014-07-09 13:14:06 +10:00
Robert Daniel Kortschak
f563a1f0f5 go.tools/cmd/present: move dirListTemplate into template file
This change allows the directory front page to be more easily configurable.

Templates are now read only at start-up and stored in a map rather than re-parsed for each page rendering.

LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/109080044
2014-07-08 15:27:33 +10:00
Josh Bleecher Snyder
3e7bc48329 go.tools/cmd/benchcmp: do not generate trailing whitespace
text/tabwriter cells are tab-terminated, not tab-separated. This creates trailing whitespace. However, with left-aligned columns, it is ok not to treat the final element as a cell. Demo: http://play.golang.org/p/m_ajG8SSZe

LGTM=gri
R=golang-codereviews, gobot, gri
CC=golang-codereviews, r
https://golang.org/cl/103650043
2014-07-07 11:55:26 -07:00
Josh Bleecher Snyder
7da5f193b7 go.tools/cmd/vet: detect stupid boolean conditions
This CL introduces two vet checks. Statistics and code below are from a recent 50mb corpus of public code.

1. Check for redundant conjunctions and disjunctions. This check caught 26 instances, of which 20 were clearly copy/paste bugs and 6 appeared to be mere duplication. A typical example:

if xResolution < 0 || xResolution < 0 {
        panic("SetSize(): width < 0 || height < 0")
}

2. Check for expressions of the form 'x != c1 || x != c2' or 'x == c1 && x == c2', with c1 and c2 constant expressions. This check caught 16 instances, of which all were bugs. A typical example:

if rf.uri.Scheme != "http" || rf.uri.Scheme != "ftp" {
        rf.uri.Scheme = "file"
}

Fixes golang/go#7622.

LGTM=rsc, r
R=golang-codereviews, jscrockett01, r, gri, rsc
CC=golang-codereviews
https://golang.org/cl/98120043
2014-07-02 10:39:57 -07:00
Rob Pike
ccb18ed35d go.tools/cmd/goimports: update doc.go to new emacs instructions
LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/103670045
2014-07-01 10:24:22 -07:00
Josh Bleecher Snyder
95a7aeb192 go.tools/cmd/vet: don't panic on commented-out asm
Really two fixes: Don't panic on bad instructions and don't complain about commented out instructions.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/110070044
2014-06-20 16:52:48 -07:00
Josh Bleecher Snyder
9d6cc5fd08 go.tools/cmd/vet: prevent panic on goto without label
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/107260043
2014-06-20 11:08:45 -07:00
Andrew Gerrand
4aa650cf80 go.tools/cmd/godoc: register redirect handler for /dl/
LGTM=minux
R=golang-codereviews, gobot, bradfitz, minux
CC=golang-codereviews
https://golang.org/cl/107050044
2014-06-18 15:44:09 +10:00
Mikio Hara
81fd812913 go.tools/cmd/present: update doc
LGTM=adg
R=golang-codereviews, dan.kortschak, gobot, adg
CC=golang-codereviews
https://golang.org/cl/106860043
2014-06-18 11:23:08 +10:00
Robert Griesemer
2bf6947d09 go.tools/cmd/gotype: fix call site (fix build)
TBR=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/101330046
2014-06-17 11:06:19 -07:00
Peter Collingbourne
02990bd494 go.tools/go/gccgoimporter: keep track of package and import priority
Clients such as compilers need this information in order
to correctly link against imported packages.

This also adds support for the condensed import data format
where the priority information is stored as a suffix of the
condensed import data, as well as support for archive files.

LGTM=gri
R=gri
CC=golang-codereviews, iant
https://golang.org/cl/78740043
2014-06-17 10:56:47 -07:00
Peter Collingbourne
4a6efa0a34 go.tools/go/ssa: add a flag for selecting bare init functions
Bare init functions omit calls to dependent init functions and the
use of an init guard. They are useful in cases where the client uses
a different calling convention for init functions, or cases where
it is easier for a client to analyze bare init functions.

LGTM=adonovan
R=adonovan
CC=golang-codereviews, iant
https://golang.org/cl/78780043
2014-06-16 21:34:51 -04:00
Josh Bleecher Snyder
d46b792624 cmd/vet: check for use of json/xml struct tags with unexported fields
This is a common source of bugs, particularly for those new to Go. Running this on a corpus of public code flagged 114 instances.

This check may need to be updated once issue 7363 is resolved.

LGTM=r
R=golang-codereviews, r
CC=bradfitz, golang-codereviews
https://golang.org/cl/91010047
2014-06-13 18:44:31 -07:00
Andrew Gerrand
5a5dc64a96 go.tools/godoc: fix index reading and writing
In command godoc, set IndexEnabled when the -write_index flag is set.
Previously you would need to (unintuitively) set the -http flag to
achieve this.

In package godoc, set up the FS tree before loading the index, and
then return before starting the index refresh loop. Previously the
index would be loaded and then immediately refreshed, negating the
benefits of the on-disk index.

TBR=bradfitz
R=golang-codereviews
CC=golang-codereviews
https://golang.org/cl/103370046
2014-06-13 16:49:32 +10:00
Andrew Gerrand
93b08999a7 go.tools/cmd/godoc: set corpus.MaxResults in appinit.go
LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/101220045
2014-06-13 15:20:15 +10:00
David Symonds
f895b43688 vet: Rearrange checkers to use a registration system.
This removes much of the AST logic out of main.go,
and makes it easier to build custom vet binaries

The trade-off in this change is for flexibility.
There's very little change in the per-check files,
a lot less code in main.go (specifically the AST walking
logic has shrunk), and it makes it much easier to build
custom vet binaries simply by dropping new source files
in the directory.

LGTM=josharian, r
R=r, josharian, kamil.kisiel
CC=golang-codereviews
https://golang.org/cl/83400043
2014-06-13 15:04:45 +10:00