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

115 Commits

Author SHA1 Message Date
Josh Bleecher Snyder
85ad76014a cmd/vet: fix build
Broken by CLs 10994 and 10800.

Fixes golang/go#11194.

Change-Id: Ic071fae6bf7e8ac9518d84c74c98d1d7233c2025
Reviewed-on: https://go-review.googlesource.com/11004
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-06-12 23:48:11 +00:00
Robert Griesemer
a6d2a4254e cmd/vet: backport of https://go-review.googlesource.com/#/c/10777/3
Change-Id: I8d63575f2053eda2d7f0a63f3ff862bf0de88d31
Reviewed-on: https://go-review.googlesource.com/10807
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-06-09 16:33:12 +00:00
Robert Griesemer
f0b0213b21 cmd/vet: remove dependency on types.New
In preparation for removal of types.New.

Change-Id: Ieff0c41cf03351124cea32e9b96075a4801c051f
Reviewed-on: https://go-review.googlesource.com/10775
Reviewed-by: Rob Pike <r@golang.org>
2015-06-05 20:06:37 +00:00
Rob Pike
cc54cd6553 cmd/vet: don't use filepath.Join to build binary name in test
It cleans the string and removes the initial ./, which will cause the
test to fail if . is not in $PATH

Change-Id: Icc216f7ab4887c39ccda93d1c4093ccd03de44bc
Reviewed-on: https://go-review.googlesource.com/10696
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-06-04 21:29:42 +00:00
Rob Pike
3caa6cfbd2 cmd/vet: add -tags flag
This is needed to control which files to test in the usual manner.
A followup CL on the main repo will add the flag to the go vet command.

Updates golang/go#10228

Change-Id: I820d3c74657b58de5e92276627368dedf4e2096c
Reviewed-on: https://go-review.googlesource.com/10692
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-06-04 19:20:34 +00:00
Josh Bleecher Snyder
b1aed1a596 cmd/vet: add arm64 asmdecl support
Change-Id: I5ab54616488bc9bc41aefb27b45d72c36fc4fbde
Reviewed-on: https://go-review.googlesource.com/9211
Reviewed-by: Rob Pike <r@golang.org>
2015-04-22 01:25:24 +00:00
Robert Griesemer
14c815ee28 cmd/vet: remove (another) dependency on go/astutil
Missed this in a prior change.

Change-Id: I7358c17b73a1221cb8f9dff6b808fdea8b13ec06
Reviewed-on: https://go-review.googlesource.com/8916
Reviewed-by: Rob Pike <r@golang.org>
2015-04-14 16:22:22 +00:00
Robert Griesemer
850ba653f7 Revert "cmd/vet: switch to go/types from std repo"
This reverts commit 5b72e8e9bb.

Change-Id: I75270045022d69444b7812f290cdd5861af13feb
Reviewed-on: https://go-review.googlesource.com/8915
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-04-14 03:54:48 +00:00
Robert Griesemer
5b72e8e9bb cmd/vet: switch to go/types from std repo
Depends on https://golang.org/cl/8767/.

With this change, cmd/vet does not depend on x/tools anymore
and could be moved into the std repo if so desired.

Change-Id: Ia205c6e1a6a63eebb27776064e5c24491043b683
Reviewed-on: https://go-review.googlesource.com/8791
Reviewed-by: Rob Pike <r@golang.org>
2015-04-14 00:30:21 +00:00
Robert Griesemer
48e2a5be44 cmd/vet: remove dependency on go/ast/astutil
This package was only imported for the trivial Unparen function.

Change-Id: I0ead916a7fdb469a26b4fe99c6964a8ed1438c49
Reviewed-on: https://go-review.googlesource.com/8566
Reviewed-by: Rob Pike <r@golang.org>
2015-04-08 15:52:25 +00:00
Alan Donovan
4a08fb6fc3 cmd/vet: -unusedresult: report calls of pure functions in expression statements
Change-Id: Ib8b6eaecd56ae15c44fb8ac11c781244964428f1
Reviewed-on: https://go-review.googlesource.com/6661
Reviewed-by: David Symonds <dsymonds@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2015-04-06 21:44:23 +00:00
Rob Pike
ed1e7c5cf2 vet: fix documentation about recursive scanning
It used to do packages only when run by the go tool, but it was
fixed a while back to handle packages properly when doing a
directory walk. Remove the incorrect information from the
documentation.

Change-Id: I961340bb84e48474c94ee03bf88f9136492c0226
Reviewed-on: https://go-review.googlesource.com/7642
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-03-17 00:40:15 +00:00
Russ Cox
c7a00958ec cmd/vet: fix unnamed FP check
While we're here, silence a print about failure to import fmt.
When it prints, it looks like a problem, and in fact the result
is never used in vet.

Change-Id: I76121b335026a2b09637608b997517be94fd167c
Reviewed-on: https://go-review.googlesource.com/5573
Reviewed-by: Rob Pike <r@golang.org>
2015-02-23 19:33:41 +00:00
Nigel Tao
10d7cacb91 cmd/vet: add color.CMYK to the whitelist of frozen structs.
Change-Id: I5164ef9a998a0807f80668b9140eac4b2f889049
Reviewed-on: https://go-review.googlesource.com/4997
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-02-17 02:58:17 +00:00
Nigel Tao
9622599500 cmd/vet: allow spaces in struct tag values.
The validateStructTag code now closely mimics the StructTag.Get code in
package reflect.

This addresses the comment raised on issue #9500:
https://github.com/golang/go/issues/9500#issuecomment-70218780

See also https://go-review.googlesource.com/3953

Change-Id: I583f7447dbc5a2d7ecbb393d9bb6b1515cb10b18
Reviewed-on: https://go-review.googlesource.com/3952
Reviewed-by: Rob Pike <r@golang.org>
2015-02-06 02:26:15 +00:00
Joël Stemmer
913f41fc5f cmd/vet: warn about zero arg index in print format
Argument indexes in a format string are one-based, however vet would not
warn when using a zero-index unless the type of the argument referenced
was not a string. That warning was misleading as it would say the type
was not a string. Vet will now print a correct warning when using a zero
index.

Included are tests for both cases.

Fixes #9752

Change-Id: I285e99990a86a653b4668b0c279d5f5f1c34f7aa
Reviewed-on: https://go-review.googlesource.com/3692
Reviewed-by: Rob Pike <r@golang.org>
2015-02-04 18:31:58 +00:00
David Crawshaw
e0ba1bf74c cmd/vet: keep processing files after warning
This lets go vet produce useful results for syscall on darwin/amd64,
otherwise it gets caught on asm.s.

Change-Id: I3daa49cf61eeada52eb9d4e94e40c4d21d1d5b2d
Reviewed-on: https://go-review.googlesource.com/2741
Reviewed-by: Rob Pike <r@golang.org>
2015-01-13 19:51:41 +00:00
Peter Collingbourne
4f8578d2c0 astutil: move to go/ast/astutil
Change-Id: I9a45bfc07613eb2210081d306d71f0a4d152eda5
Reviewed-on: https://go-review.googlesource.com/2592
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-01-13 15:47:47 +00:00
Rob Pike
682ca03389 vet: improve validation of struct tags
Actually parse the strings to check them more accurately.
The particular problem it missed was that it didn't check
for control characters in the key. The only valid separator
is a space.

More tests.

Fixes #9500

Change-Id: Ib547e11c7e8d47d81eb8b1e8f1ab9c26174933df
Reviewed-on: https://go-review.googlesource.com/2685
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-12 23:15:16 +00:00
Alan Donovan
4f13714aca astutil: add Unparen utility, eliminating 7 copies.
Change-Id: I824328c275bd6198a57edd64bf72cb2cf0490a68
Reviewed-on: https://go-review.googlesource.com/2172
Reviewed-by: Chris Manghane <cmang@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2014-12-29 22:24:57 +00:00
David Symonds
24257c8cd2 tools: add import comments.
Change-Id: Idda6e64580432cb9a731e4ebf4005ee4ceb4202d
Reviewed-on: https://go-review.googlesource.com/1244
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-09 22:42:16 +00:00
Andrew Gerrand
5ebbcd132f go.tools: use golang.org/x/... import paths
Rewrite performed with this command:
  sed -i '' 's_code.google.com/p/go\._golang.org/x/_g' \
    $(grep -lr 'code.google.com/p/go.' *)

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/170920043
2014-11-10 08:50:40 +11:00
Austin Clements
348181cdd4 cmd/vet: tests for RET checking, SP checking, and leaf functions
Add tests for recently introduced asm error checks in vet.
This adds tests for the new warnings about functions that
don't store to their return slot before returning or that
store to SP-relative addresses in or beyond the argument
frame.  It also adds a test for leaf function handling on arm,
where the link register is not implicitly saved.

LGTM=rsc
R=rsc
CC=adg, golang-codereviews, r
https://golang.org/cl/166040044
2014-11-03 17:27:41 -05:00
Austin Clements
52f3c4bf8a cmd/vet: update test patterns to include asm function name
vet now includes function names in its error messages about
assembly code.  Update the error test patterns to account for
this and expand some patterns to check that go vet discovers
the function name correctly.

Fixes golang/go#9041

LGTM=r
R=adg, r, rsc
CC=golang-codereviews
https://golang.org/cl/170940044
2014-11-02 12:21:04 -05:00
Austin Clements
c7512a5f83 cmd/vet: check return moves, support power64x, various fixes
This adds support for checking moves to the return value stack
slot (from rsc), adds support for checking power64x assembly,
fixes argument offset checking and leaf function support on
platforms with a link register (arm and power64).

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/166920043
2014-10-30 11:53:56 -04:00
Robert Griesemer
bdfcf50b6f cmd/vet: fix internal comments
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/163070043
2014-10-23 10:59:27 -07:00
Robert Griesemer
ea1477608d cmd/vet: use changed types.LookupParent API (fix build)
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/162080043
2014-10-23 09:57:19 -07:00
David Symonds
26439e8d81 cmd/vet: return nil from importType if it fails.
This permits vet to not panic during init if fmt.a is unavailable.

LGTM=r
R=gri, r
CC=golang-codereviews
https://golang.org/cl/153590043
2014-10-15 16:56:09 +11:00
Rob Pike
9be0b38f5b cmd/vet: don't panic if import fails
Initializing the unused variable formatterType (it will be used soon) was
panicking if the import couldn't be done, but vet shouldn't be so fragile.

LGTM=gri
R=gri
CC=dsymonds, golang-codereviews
https://golang.org/cl/153480044
2014-10-14 12:55:46 -07:00
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
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
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
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
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
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
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
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
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
Rob Pike
4374c8910f go.tools/cmd/vet: clean up formatting of the package document
It was very ugly; a little tweaking helps godoc parse it better.
Also make unsafeptr.go not own the package doc (add a blank line)
and put one more sentence about that check into doc.go.

Fixes golang/go#7925.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/98370044
2014-05-19 11:34:31 -07:00
Russ Cox
322a5f1b4c cmd/vet: add amd64p32 (nacl) support to asmdecl check
Also add 'ErrorString', for checking Plan 9's package syscall.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/93410045
2014-05-19 12:31:38 -04:00
Russ Cox
d8a81d8377 cmd/vet: fix line number in asm errors
Before:
: asm_amd64.s:16: [amd64] invalid offset new+16(FP); expected new+8(FP)
: asm_amd64.s:26: [amd64] invalid offset new+16(FP); expected new+8(FP)

After:
asm_amd64.s:16: [amd64] invalid offset new+16(FP); expected new+8(FP)
asm_amd64.s:26: [amd64] invalid offset new+16(FP); expected new+8(FP)

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/91510043
2014-05-19 12:31:28 -04:00
Russ Cox
b752e9ffdf cmd/vet: diagnose use of unsafe.Pointer to convert integer to pointer
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/100470044
2014-05-15 15:32:51 -04:00