Skip to content

Commit

Permalink
Merge pull request #3284 from hashicorp/f-lint
Browse files Browse the repository at this point in the history
Enable more linters
  • Loading branch information
dadgar committed Sep 26, 2017
2 parents cfe4f05 + a9e3a41 commit 8750e2d
Show file tree
Hide file tree
Showing 120 changed files with 745 additions and 973 deletions.
21 changes: 15 additions & 6 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ GIT_DIRTY := $(if $(shell git status --porcelain),+CHANGES)
GO_LDFLAGS := "-X main.GitCommit=$(GIT_COMMIT)$(GIT_DIRTY)"
GO_TAGS =

# Enable additional linters as the codebase evolves to pass them
CHECKS ?= --enable goimports

default: help

ifeq (,$(findstring $(THIS_OS),Darwin Linux FreeBSD))
Expand Down Expand Up @@ -160,11 +157,23 @@ check: ## Lint the source code
@gometalinter \
--deadline 10m \
--vendor \
--exclude '(.*\.generated\.go:\d+:|bindata_assetfs)' \
--exclude='.*\.generated\.go' \
--exclude='.*bindata_assetfs\.go' \
--skip="ui/" \
--sort="path" \
--aggregate \
--enable-gc \
--disable-all \
--sort severity \
$(CHECKS) \
--enable goimports \
--enable misspell \
--enable vet \
--enable deadcode \
--enable varcheck \
--enable ineffassign \
--enable structcheck \
--enable unconvert \
--enable gas \
--enable gofmt \
./...

.PHONY: checkscripts
Expand Down
2 changes: 1 addition & 1 deletion acl/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func isNamespaceCapabilityValid(cap string) bool {
case NamespaceCapabilityDeny, NamespaceCapabilityListJobs, NamespaceCapabilityReadJob,
NamespaceCapabilitySubmitJob, NamespaceCapabilityReadLogs, NamespaceCapabilityReadFS:
return true
// Seperate the enterprise-only capabilities
// Separate the enterprise-only capabilities
case NamespaceCapabilitySentinelOverride:
return true
default:
Expand Down
10 changes: 5 additions & 5 deletions acl/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestParse(t *testing.T) {
"",
&Policy{
Namespaces: []*NamespacePolicy{
&NamespacePolicy{
{
Name: "default",
Policy: PolicyRead,
Capabilities: []string{
Expand Down Expand Up @@ -59,15 +59,15 @@ func TestParse(t *testing.T) {
"",
&Policy{
Namespaces: []*NamespacePolicy{
&NamespacePolicy{
{
Name: "default",
Policy: PolicyRead,
Capabilities: []string{
NamespaceCapabilityListJobs,
NamespaceCapabilityReadJob,
},
},
&NamespacePolicy{
{
Name: "other",
Policy: PolicyWrite,
Capabilities: []string{
Expand All @@ -78,7 +78,7 @@ func TestParse(t *testing.T) {
NamespaceCapabilityReadFS,
},
},
&NamespacePolicy{
{
Name: "secret",
Capabilities: []string{
NamespaceCapabilityDeny,
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestParse(t *testing.T) {
"",
&Policy{
Namespaces: []*NamespacePolicy{
&NamespacePolicy{
{
Name: "default",
Policy: "",
Capabilities: []string{
Expand Down
72 changes: 36 additions & 36 deletions api/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,98 +142,98 @@ func TestAgents_Sort(t *testing.T) {
}{
{
[]*AgentMember{
&AgentMember{Name: "nomad-2.vac.us-east",
{Name: "nomad-2.vac.us-east",
Tags: map[string]string{"region": "us-east", "dc": "us-east-1c"}},
&AgentMember{Name: "nomad-1.global",
{Name: "nomad-1.global",
Tags: map[string]string{"region": "global", "dc": "dc1"}},
&AgentMember{Name: "nomad-1.vac.us-east",
{Name: "nomad-1.vac.us-east",
Tags: map[string]string{"region": "us-east", "dc": "us-east-1c"}},
},
[]*AgentMember{
&AgentMember{Name: "nomad-1.global",
{Name: "nomad-1.global",
Tags: map[string]string{"region": "global", "dc": "dc1"}},
&AgentMember{Name: "nomad-1.vac.us-east",
{Name: "nomad-1.vac.us-east",
Tags: map[string]string{"region": "us-east", "dc": "us-east-1c"}},
&AgentMember{Name: "nomad-2.vac.us-east",
{Name: "nomad-2.vac.us-east",
Tags: map[string]string{"region": "us-east", "dc": "us-east-1c"}},
},
},
{
[]*AgentMember{
&AgentMember{Name: "nomad-02.tam.us-east",
{Name: "nomad-02.tam.us-east",
Tags: map[string]string{"region": "us-east", "dc": "tampa"}},
&AgentMember{Name: "nomad-02.pal.us-west",
{Name: "nomad-02.pal.us-west",
Tags: map[string]string{"region": "us-west", "dc": "palo_alto"}},
&AgentMember{Name: "nomad-01.pal.us-west",
{Name: "nomad-01.pal.us-west",
Tags: map[string]string{"region": "us-west", "dc": "palo_alto"}},
&AgentMember{Name: "nomad-01.tam.us-east",
{Name: "nomad-01.tam.us-east",
Tags: map[string]string{"region": "us-east", "dc": "tampa"}},
},
[]*AgentMember{
&AgentMember{Name: "nomad-01.tam.us-east",
{Name: "nomad-01.tam.us-east",
Tags: map[string]string{"region": "us-east", "dc": "tampa"}},
&AgentMember{Name: "nomad-02.tam.us-east",
{Name: "nomad-02.tam.us-east",
Tags: map[string]string{"region": "us-east", "dc": "tampa"}},
&AgentMember{Name: "nomad-01.pal.us-west",
{Name: "nomad-01.pal.us-west",
Tags: map[string]string{"region": "us-west", "dc": "palo_alto"}},
&AgentMember{Name: "nomad-02.pal.us-west",
{Name: "nomad-02.pal.us-west",
Tags: map[string]string{"region": "us-west", "dc": "palo_alto"}},
},
},
{
[]*AgentMember{
&AgentMember{Name: "nomad-02.tam.us-east",
{Name: "nomad-02.tam.us-east",
Tags: map[string]string{"region": "us-east", "dc": "tampa"}},
&AgentMember{Name: "nomad-02.ams.europe",
{Name: "nomad-02.ams.europe",
Tags: map[string]string{"region": "europe", "dc": "amsterdam"}},
&AgentMember{Name: "nomad-01.tam.us-east",
{Name: "nomad-01.tam.us-east",
Tags: map[string]string{"region": "us-east", "dc": "tampa"}},
&AgentMember{Name: "nomad-01.ams.europe",
{Name: "nomad-01.ams.europe",
Tags: map[string]string{"region": "europe", "dc": "amsterdam"}},
},
[]*AgentMember{
&AgentMember{Name: "nomad-01.ams.europe",
{Name: "nomad-01.ams.europe",
Tags: map[string]string{"region": "europe", "dc": "amsterdam"}},
&AgentMember{Name: "nomad-02.ams.europe",
{Name: "nomad-02.ams.europe",
Tags: map[string]string{"region": "europe", "dc": "amsterdam"}},
&AgentMember{Name: "nomad-01.tam.us-east",
{Name: "nomad-01.tam.us-east",
Tags: map[string]string{"region": "us-east", "dc": "tampa"}},
&AgentMember{Name: "nomad-02.tam.us-east",
{Name: "nomad-02.tam.us-east",
Tags: map[string]string{"region": "us-east", "dc": "tampa"}},
},
},
{
[]*AgentMember{
&AgentMember{Name: "nomad-02.ber.europe",
{Name: "nomad-02.ber.europe",
Tags: map[string]string{"region": "europe", "dc": "berlin"}},
&AgentMember{Name: "nomad-02.ams.europe",
{Name: "nomad-02.ams.europe",
Tags: map[string]string{"region": "europe", "dc": "amsterdam"}},
&AgentMember{Name: "nomad-01.ams.europe",
{Name: "nomad-01.ams.europe",
Tags: map[string]string{"region": "europe", "dc": "amsterdam"}},
&AgentMember{Name: "nomad-01.ber.europe",
{Name: "nomad-01.ber.europe",
Tags: map[string]string{"region": "europe", "dc": "berlin"}},
},
[]*AgentMember{
&AgentMember{Name: "nomad-01.ams.europe",
{Name: "nomad-01.ams.europe",
Tags: map[string]string{"region": "europe", "dc": "amsterdam"}},
&AgentMember{Name: "nomad-02.ams.europe",
{Name: "nomad-02.ams.europe",
Tags: map[string]string{"region": "europe", "dc": "amsterdam"}},
&AgentMember{Name: "nomad-01.ber.europe",
{Name: "nomad-01.ber.europe",
Tags: map[string]string{"region": "europe", "dc": "berlin"}},
&AgentMember{Name: "nomad-02.ber.europe",
{Name: "nomad-02.ber.europe",
Tags: map[string]string{"region": "europe", "dc": "berlin"}},
},
},
{
[]*AgentMember{
&AgentMember{Name: "nomad-1.global"},
&AgentMember{Name: "nomad-3.global"},
&AgentMember{Name: "nomad-2.global"},
{Name: "nomad-1.global"},
{Name: "nomad-3.global"},
{Name: "nomad-2.global"},
},
[]*AgentMember{
&AgentMember{Name: "nomad-1.global"},
&AgentMember{Name: "nomad-2.global"},
&AgentMember{Name: "nomad-3.global"},
{Name: "nomad-1.global"},
{Name: "nomad-2.global"},
{Name: "nomad-3.global"},
},
},
}
Expand Down
12 changes: 6 additions & 6 deletions api/allocations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ func TestAllocations_PrefixList(t *testing.T) {
func TestAllocations_CreateIndexSort(t *testing.T) {
t.Parallel()
allocs := []*AllocationListStub{
&AllocationListStub{CreateIndex: 2},
&AllocationListStub{CreateIndex: 1},
&AllocationListStub{CreateIndex: 5},
{CreateIndex: 2},
{CreateIndex: 1},
{CreateIndex: 5},
}
sort.Sort(AllocIndexSort(allocs))

expect := []*AllocationListStub{
&AllocationListStub{CreateIndex: 5},
&AllocationListStub{CreateIndex: 2},
&AllocationListStub{CreateIndex: 1},
{CreateIndex: 5},
{CreateIndex: 2},
{CreateIndex: 1},
}
if !reflect.DeepEqual(allocs, expect) {
t.Fatalf("\n\n%#v\n\n%#v", allocs, expect)
Expand Down
14 changes: 7 additions & 7 deletions api/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestCompose(t *testing.T) {
DiskMB: helper.IntToPtr(2048),
IOPS: helper.IntToPtr(500),
Networks: []*NetworkResource{
&NetworkResource{
{
CIDR: "0.0.0.0/0",
MBits: helper.IntToPtr(100),
ReservedPorts: []Port{{"", 80}, {"", 443}},
Expand Down Expand Up @@ -55,25 +55,25 @@ func TestCompose(t *testing.T) {
"foo": "bar",
},
Constraints: []*Constraint{
&Constraint{
{
LTarget: "kernel.name",
RTarget: "linux",
Operand: "=",
},
},
TaskGroups: []*TaskGroup{
&TaskGroup{
{
Name: helper.StringToPtr("grp1"),
Count: helper.IntToPtr(2),
Constraints: []*Constraint{
&Constraint{
{
LTarget: "kernel.name",
RTarget: "linux",
Operand: "=",
},
},
Tasks: []*Task{
&Task{
{
Name: "task1",
Driver: "exec",
Resources: &Resources{
Expand All @@ -82,7 +82,7 @@ func TestCompose(t *testing.T) {
DiskMB: helper.IntToPtr(2048),
IOPS: helper.IntToPtr(500),
Networks: []*NetworkResource{
&NetworkResource{
{
CIDR: "0.0.0.0/0",
MBits: helper.IntToPtr(100),
ReservedPorts: []Port{
Expand All @@ -93,7 +93,7 @@ func TestCompose(t *testing.T) {
},
},
Constraints: []*Constraint{
&Constraint{
{
LTarget: "kernel.name",
RTarget: "linux",
Operand: "=",
Expand Down
12 changes: 6 additions & 6 deletions api/evaluations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@ func TestEvaluations_Allocations(t *testing.T) {
func TestEvaluations_Sort(t *testing.T) {
t.Parallel()
evals := []*Evaluation{
&Evaluation{CreateIndex: 2},
&Evaluation{CreateIndex: 1},
&Evaluation{CreateIndex: 5},
{CreateIndex: 2},
{CreateIndex: 1},
{CreateIndex: 5},
}
sort.Sort(EvalIndexSort(evals))

expect := []*Evaluation{
&Evaluation{CreateIndex: 5},
&Evaluation{CreateIndex: 2},
&Evaluation{CreateIndex: 1},
{CreateIndex: 5},
{CreateIndex: 2},
{CreateIndex: 1},
}
if !reflect.DeepEqual(evals, expect) {
t.Fatalf("\n\n%#v\n\n%#v", evals, expect)
Expand Down
Loading

0 comments on commit 8750e2d

Please sign in to comment.