Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit d1f8b38

Browse files
authored
Merge pull request #1157 from tamird/static-checker
Add static checkers
2 parents aa8e076 + 3a25b0b commit d1f8b38

20 files changed

+53
-103
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
- stage: test
88
go_import_path: github.com/golang/dep
99
install:
10-
- go get -u honnef.co/go/tools/cmd/{gosimple,staticcheck}
10+
- go get -u github.com/golang/lint/golint honnef.co/go/tools/cmd/megacheck
1111
- npm install -g codeclimate-test-reporter
1212
env:
1313
- DEPTESTBYPASS501=1

cmd/dep/ensure.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ type ensureCommand struct {
135135
noVendor bool
136136
vendorOnly bool
137137
dryRun bool
138-
overrides stringSlice
139138
}
140139

141140
func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
@@ -699,19 +698,6 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
699698
return errors.Wrapf(f.Close(), "closing %s", dep.ManifestName)
700699
}
701700

702-
type stringSlice []string
703-
704-
func (s *stringSlice) String() string {
705-
if len(*s) == 0 {
706-
return "<none>"
707-
}
708-
return strings.Join(*s, ", ")
709-
}
710-
711-
func (s *stringSlice) Set(value string) error {
712-
*s = append(*s, value)
713-
return nil
714-
}
715701
func getProjectConstraint(arg string, sm gps.SourceManager) (gps.ProjectConstraint, string, error) {
716702
emptyPC := gps.ProjectConstraint{
717703
Constraint: gps.Any(), // default to any; avoids panics later

context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ func defaultGOPATH() string {
8383
return ""
8484
}
8585

86+
// SourceManager produces an instance of gps's built-in SourceManager
87+
// initialized to log to the receiver's logger.
8688
func (c *Ctx) SourceManager() (*gps.SourceMgr, error) {
8789
return gps.NewSourceManager(gps.SourceManagerConfig{
8890
Cachedir: filepath.Join(c.GOPATH, "pkg", "dep"),

hack/lint.bash

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# This script will validate code with various linters
77
set -e
88

9-
PKGS=$(go list ./... | grep -v /vendor/)
9+
PKGS=$(go list ./... | grep -vF /vendor/)
1010
go vet $PKGS
11-
staticcheck $PKGS
12-
gosimple $PKGS
11+
golint $PKGS
12+
megacheck -unused.exported -ignore github.com/golang/dep/internal/test/test.go:U1000 $PKGS

internal/gps/bridge.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ type bridge struct {
5656
// held by the solver that it ends up being easier and saner to do this.
5757
s *solver
5858

59-
// Simple, local cache of the root's PackageTree
60-
crp *struct {
61-
ptree pkgtree.PackageTree
62-
err error
63-
}
64-
6559
// Map of project root name to their available version list. This cache is
6660
// layered on top of the proper SourceManager's cache; the only difference
6761
// is that this keeps the versions sorted in the direction required by the

internal/gps/cmd.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ func (c *monitoredCmd) run(ctx context.Context) error {
7272
// in at the same time as process completion, but one of the former are
7373
// picked first; in such a case, cmd.Process could(?) be nil by the time we
7474
// call signal methods on it.
75-
var isDone *int32 = new(int32)
75+
var isDone int32
7676
done := make(chan error, 1)
7777

7878
go func() {
7979
// Wait() can only be called once, so this must act as the completion
8080
// indicator for both normal *and* signal-induced termination.
8181
done <- c.cmd.Wait()
82-
atomic.CompareAndSwapInt32(isDone, 0, 1)
82+
atomic.CompareAndSwapInt32(&isDone, 0, 1)
8383
}()
8484

8585
var killerr error
@@ -89,17 +89,17 @@ selloop:
8989
case err := <-done:
9090
return err
9191
case <-ticker.C:
92-
if !atomic.CompareAndSwapInt32(isDone, 1, 1) && c.hasTimedOut() {
93-
if err := killProcess(c.cmd, isDone); err != nil {
92+
if !atomic.CompareAndSwapInt32(&isDone, 1, 1) && c.hasTimedOut() {
93+
if err := killProcess(c.cmd, &isDone); err != nil {
9494
killerr = &killCmdError{err}
9595
} else {
9696
killerr = &noProgressError{c.timeout}
9797
}
9898
break selloop
9999
}
100100
case <-ctx.Done():
101-
if !atomic.CompareAndSwapInt32(isDone, 1, 1) {
102-
if err := killProcess(c.cmd, isDone); err != nil {
101+
if !atomic.CompareAndSwapInt32(&isDone, 1, 1) {
102+
if err := killProcess(c.cmd, &isDone); err != nil {
103103
killerr = &killCmdError{err}
104104
} else {
105105
killerr = ctx.Err()

internal/gps/pkgtree/pkgtree_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ func TestWorkmapToReach(t *testing.T) {
3232
return make(map[string]bool)
3333
}
3434

35-
e := struct {
36-
Internal, External []string
37-
}{}
3835
table := map[string]struct {
3936
workmap map[string]wm
4037
rm ReachMap
@@ -49,7 +46,7 @@ func TestWorkmapToReach(t *testing.T) {
4946
},
5047
},
5148
rm: ReachMap{
52-
"foo": e,
49+
"foo": {},
5350
},
5451
},
5552
"no external": {
@@ -64,8 +61,8 @@ func TestWorkmapToReach(t *testing.T) {
6461
},
6562
},
6663
rm: ReachMap{
67-
"foo": e,
68-
"foo/bar": e,
64+
"foo": {},
65+
"foo/bar": {},
6966
},
7067
},
7168
"no external with subpkg": {
@@ -85,7 +82,7 @@ func TestWorkmapToReach(t *testing.T) {
8582
"foo": {
8683
Internal: []string{"foo/bar"},
8784
},
88-
"foo/bar": e,
85+
"foo/bar": {},
8986
},
9087
},
9188
"simple base transitive": {

internal/gps/selection.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ func (s *selection) depperCount(id ProjectIdentifier) int {
7373
return len(s.deps[id.ProjectRoot])
7474
}
7575

76-
func (s *selection) setDependenciesOn(id ProjectIdentifier, deps []dependency) {
77-
s.deps[id.ProjectRoot] = deps
78-
}
79-
8076
// Compute a list of the unique packages within the given ProjectIdentifier that
8177
// have dependers, and the number of dependers they have.
8278
func (s *selection) getRequiredPackagesIn(id ProjectIdentifier) map[string]int {
@@ -93,6 +89,9 @@ func (s *selection) getRequiredPackagesIn(id ProjectIdentifier) map[string]int {
9389
return uniq
9490
}
9591

92+
// Suppress unused warning.
93+
var _ = (*selection)(nil).getSelectedPackagesIn
94+
9695
// Compute a list of the unique packages within the given ProjectIdentifier that
9796
// are currently selected, and the number of times each package has been
9897
// independently selected.

internal/gps/solve_basic_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,14 +1353,6 @@ func (sm *depspecSourceManager) GetManifestAndLock(id ProjectIdentifier, v Versi
13531353
return nil, nil, fmt.Errorf("Project %s at version %s could not be found", id, v)
13541354
}
13551355

1356-
func (sm *depspecSourceManager) ExternalReach(id ProjectIdentifier, v Version) (map[string][]string, error) {
1357-
pid := pident{n: ProjectRoot(id.normalizedSource()), v: v}
1358-
if m, exists := sm.rm[pid]; exists {
1359-
return m, nil
1360-
}
1361-
return nil, fmt.Errorf("No reach data for %s at version %s", id, v)
1362-
}
1363-
13641356
func (sm *depspecSourceManager) ListPackages(id ProjectIdentifier, v Version) (pkgtree.PackageTree, error) {
13651357
pid := pident{n: ProjectRoot(id.normalizedSource()), v: v}
13661358
if pv, ok := v.(PairedVersion); ok && pv.Revision() == "FAKEREV" {
@@ -1568,10 +1560,6 @@ func (ds depspec) DependencyConstraints() ProjectConstraints {
15681560

15691561
type fixLock []LockedProject
15701562

1571-
func (fixLock) SolverVersion() string {
1572-
return "-1"
1573-
}
1574-
15751563
// impl Lock interface
15761564
func (fixLock) InputHash() []byte {
15771565
return []byte("fooooorooooofooorooofoo")
@@ -1584,11 +1572,6 @@ func (l fixLock) Projects() []LockedProject {
15841572

15851573
type dummyLock struct{}
15861574

1587-
// impl Lock interface
1588-
func (dummyLock) SolverVersion() string {
1589-
return "-1"
1590-
}
1591-
15921575
// impl Lock interface
15931576
func (dummyLock) InputHash() []byte {
15941577
return []byte("fooooorooooofooorooofoo")

internal/gps/solve_failures.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@ import (
1111
"strings"
1212
)
1313

14-
type errorLevel uint8
15-
16-
// TODO(sdboyer) consistent, sensible way of handling 'type' and 'severity' - or figure
17-
// out that they're not orthogonal and collapse into just 'type'
18-
19-
const (
20-
warning errorLevel = 1 << iota
21-
mustResolve
22-
cannotResolve
23-
)
24-
2514
func a2vs(a atom) string {
2615
if a.v == rootRev || a.v == nil {
2716
return "(root)"

internal/gps/source_manager.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ func NewSourceManager(c SourceManagerConfig) (*SourceMgr, error) {
213213
lasttime = nowtime
214214
}
215215

216-
if _, ok := err.(interface {
216+
if t, ok := err.(interface {
217217
Temporary() bool
218-
}); ok {
218+
}); ok && t.Temporary() {
219219
time.Sleep(time.Second * 1)
220220
} else {
221221
return nil, CouldNotCreateLockError{
@@ -677,7 +677,6 @@ const (
677677
ctSourcePing
678678
ctSourceInit
679679
ctSourceFetch
680-
ctCheckoutVersion
681680
ctExportTree
682681
)
683682

internal/gps/typed_radix.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func newDeducerTrie() *deducerTrie {
3030
}
3131
}
3232

33+
// Suppress unused warning.
34+
var _ = (*deducerTrie)(nil).Delete
35+
3336
// Delete is used to delete a key, returning the previous value and if it was deleted
3437
func (t *deducerTrie) Delete(s string) (pathDeducer, bool) {
3538
t.Lock()

internal/gps/vcs_repo.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ func getVCSRepo(s vcs.Type, ustr, path string) (r ctxRepo, err error) {
5353
var repo *vcs.HgRepo
5454
repo, err = vcs.NewHgRepo(ustr, path)
5555
r = &hgRepo{repo}
56+
case vcs.Svn:
57+
var repo *vcs.SvnRepo
58+
repo, err = vcs.NewSvnRepo(ustr, path)
59+
r = &svnRepo{repo}
5660
}
5761

5862
return
@@ -218,7 +222,7 @@ func (r *svnRepo) get(ctx context.Context) error {
218222
return nil
219223
}
220224

221-
func (r *svnRepo) update(ctx context.Context) error {
225+
func (r *svnRepo) fetch(ctx context.Context) error {
222226
out, err := runFromRepoDir(ctx, r, expensiveCmdTimeout, "svn", "update")
223227
if err != nil {
224228
return newVcsRemoteErrorOr("unable to update repository", err, string(out))

internal/gps/vcs_repo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func testSvnRepo(t *testing.T) {
171171
}
172172

173173
// Perform an update which should take up back to the latest version.
174-
err = repo.update(ctx)
174+
err = repo.fetch(ctx)
175175
if err != nil {
176176
t.Fatal(err)
177177
}

internal/gps/vcs_source.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,6 @@ func (s *hgSource) listVersions(ctx context.Context) ([]PairedVersion, error) {
570570
return vlist, nil
571571
}
572572

573-
type repo struct {
574-
// Object for direct repo interaction
575-
r ctxRepo
576-
}
577-
578573
// This func copied from Masterminds/vcs so we can exec our own commands
579574
func mergeEnvLists(in, out []string) []string {
580575
NextVar:

internal/gps/vcs_source_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ func TestSlowVcs(t *testing.T) {
2525
t.Run("source-gateway", testSourceGateway)
2626
t.Run("bzr-repo", testBzrRepo)
2727
t.Run("bzr-source", testBzrSourceInteractions)
28-
// TODO(kris-nova) re-enable syn-repo after gps is merged into dep
29-
//t.Run("svn-repo", testSvnRepo)
28+
t.Run("svn-repo", testSvnRepo)
3029
// TODO(sdboyer) svn-source
3130
t.Run("hg-repo", testHgRepo)
3231
t.Run("hg-source", testHgSourceInteractions)

internal/gps/version.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ func (r Revision) String() string {
119119
return string(r)
120120
}
121121

122+
// ImpliedCaretString follows the same rules as String(), but in accordance with
123+
// the Constraint interface will always print a leading "=", as all Versions,
124+
// when acting as a Constraint, act as exact matches.
122125
func (r Revision) ImpliedCaretString() string {
123126
return r.String()
124127
}

internal/gps/version_queue_test.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
package gps
66

77
import (
8-
"fmt"
98
"testing"
9+
10+
"github.com/pkg/errors"
1011
)
1112

12-
// just need a ListVersions method
13+
// just need a listVersions method
1314
type fakeBridge struct {
1415
*bridge
1516
vl []Version
@@ -27,10 +28,6 @@ func init() {
2728
SortForUpgrade(fakevl)
2829
}
2930

30-
func (fb *fakeBridge) ListVersions(id ProjectIdentifier) ([]PairedVersion, error) {
31-
return nil, nil
32-
}
33-
3431
func (fb *fakeBridge) listVersions(id ProjectIdentifier) ([]Version, error) {
3532
// it's a fixture, we only ever do the one, regardless of id
3633
return fb.vl, nil
@@ -40,11 +37,7 @@ type fakeFailBridge struct {
4037
*bridge
4138
}
4239

43-
var errVQ = fmt.Errorf("vqerr")
44-
45-
func (fb *fakeFailBridge) ListVersions(id ProjectIdentifier) ([]PairedVersion, error) {
46-
return nil, nil
47-
}
40+
var errVQ = errors.New("vqerr")
4841

4942
func (fb *fakeFailBridge) listVersions(id ProjectIdentifier) ([]Version, error) {
5043
return nil, errVQ
@@ -152,7 +145,7 @@ func TestVersionQueueAdvance(t *testing.T) {
152145
}
153146

154147
for k, v := range fakevl[1:] {
155-
err = vq.advance(fmt.Errorf("advancment fail for %s", fakevl[k]))
148+
err = vq.advance(errors.Errorf("advancment fail for %s", fakevl[k]))
156149
if err != nil {
157150
t.Errorf("error on advancing vq from %s to %s", fakevl[k], v)
158151
break
@@ -166,7 +159,7 @@ func TestVersionQueueAdvance(t *testing.T) {
166159
if vq.isExhausted() {
167160
t.Error("should not be exhausted until advancing 'past' the end")
168161
}
169-
if err = vq.advance(fmt.Errorf("final advance failure")); err != nil {
162+
if err = vq.advance(errors.Errorf("final advance failure")); err != nil {
170163
t.Errorf("should not error on advance, even past end, but got %s", err)
171164
}
172165

@@ -191,7 +184,7 @@ func TestVersionQueueAdvance(t *testing.T) {
191184
t.Error("can't be exhausted, we aren't even 'allLoaded' yet")
192185
}
193186

194-
err = vq.advance(fmt.Errorf("dequeue lockv"))
187+
err = vq.advance(errors.Errorf("dequeue lockv"))
195188
if err != nil {
196189
t.Error("unexpected error when advancing past lockv", err)
197190
} else {
@@ -203,7 +196,7 @@ func TestVersionQueueAdvance(t *testing.T) {
203196
}
204197
}
205198

206-
err = vq.advance(fmt.Errorf("dequeue prefv"))
199+
err = vq.advance(errors.Errorf("dequeue prefv"))
207200
if err != nil {
208201
t.Error("unexpected error when advancing past prefv", err)
209202
} else {

internal/test/integration/testproj.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ type RunFunc func(prog string, newargs []string, outW, errW io.Writer, dir strin
3131
// and content
3232
type TestProject struct {
3333
t *testing.T
34-
h *test.Helper
3534
preImports []string
3635
tempdir string
3736
env []string

0 commit comments

Comments
 (0)