Skip to content

Commit

Permalink
Add goimports and golangci-lint (#17)
Browse files Browse the repository at this point in the history
goimports for import rewritting
golangci-lint as the configurable linting swiss army knife.

These tools are recorded in [tools.go](https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module). This records
them as a dependency to make sure we're all using the same tool versions.

To make sure this project's tool's versions don't stomp over versions
from other projects, they are installed in ./.tools, which is
.gitignored.

goimports was run and fixed up a single file:
plugin/httptrace/httptrace.go

I prefer to group local packages below external packages, hence the use
of goimports -local option.

.golangci.yml contains nothing but an incomplete set of defaults ATM.
I expect those to change over time though. ;-)

To use, run:

$ make precommit

Fixes #15
  • Loading branch information
Edward Muller authored and rghetia committed Jun 19, 2019
1 parent 56ada5a commit 063035e
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.tools/
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# See https://github.com/golangci/golangci-lint#config-file
run:
issues-exit-code: 1 #Default
tests: true #Default
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: precommit

TOOLS_DIR := ./.tools

$(TOOLS_DIR)/golangci-lint: go.mod go.sum tools.go
go build -o $(TOOLS_DIR)/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint

$(TOOLS_DIR)/goimports: go.mod go.sum tools.go
go build -o $(TOOLS_DIR)/goimports golang.org/x/tools/cmd/goimports

precommit: $(TOOLS_DIR)/goimports $(TOOLS_DIR)/golangci-lint
$(TOOLS_DIR)/goimports -d -local github.com/open-telemetry/opentelemetry-go -w .
$(TOOLS_DIR)/golangci-lint run
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module github.com/open-telemetry/opentelemetry-go
go 1.12

require (
github.com/golangci/golangci-lint v1.17.1
github.com/lightstep/tracecontext.go v0.0.0-20181129014701-1757c391b1ac
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
golang.org/x/tools v0.0.0-20190521203540-521d6ed310dd
)
199 changes: 199 additions & 0 deletions go.sum

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions plugin/httptrace/httptrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import (
"encoding/binary"
"net/http"

"github.com/open-telemetry/opentelemetry-go/api/core"
"github.com/open-telemetry/opentelemetry-go/api/tag"
"github.com/lightstep/tracecontext.go"
"github.com/lightstep/tracecontext.go/tracestate"

"github.com/open-telemetry/opentelemetry-go/api/core"
"github.com/open-telemetry/opentelemetry-go/api/tag"
)

const (
Expand Down
8 changes: 8 additions & 0 deletions tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// +build tools

package tools

import (
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "golang.org/x/tools/cmd/goimports"
)

0 comments on commit 063035e

Please sign in to comment.