Skip to content

Commit a73fe0e

Browse files
authored
Switched to revive, goimports, re-formatted everything (#1233)
* Switched to revive, goimports, re-formatted everything Works pretty well! Using latest tools/go.mod versions (except thrift), and using the server's revive.toml for starting out. Revive is a bit noisy due to some `Id` -> `ID` recommendations, but we probably should actually do that for v2.
1 parent 849a82b commit a73fe0e

File tree

109 files changed

+443
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+443
-185
lines changed

.gen/go/cadence/cadence.go

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gen/go/cadence/workflowserviceclient/client.go

+5-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gen/go/cadence/workflowservicefx/client.go

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gen/go/cadence/workflowservicefx/server.go

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gen/go/cadence/workflowserviceserver/server.go

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gen/go/cadence/workflowservicetest/client.go

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gen/go/shadower/shadower.go

+6-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gen/go/shared/shared.go

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

+26-37
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,11 @@ $(BIN)/thriftrw: internal/tools/go.mod
142142
$(BIN)/thriftrw-plugin-yarpc: internal/tools/go.mod
143143
$(call go_build_tool,go.uber.org/yarpc/encoding/thrift/thriftrw-plugin-yarpc)
144144

145-
$(BIN)/golint: internal/tools/go.mod
146-
$(call go_build_tool,golang.org/x/lint/golint)
145+
$(BIN)/goimports: internal/tools/go.mod
146+
$(call go_build_tool,golang.org/x/tools/cmd/goimports)
147+
148+
$(BIN)/revive: internal/tools/go.mod
149+
$(call go_build_tool,github.com/mgechev/revive)
147150

148151
$(BIN)/staticcheck: internal/tools/go.mod
149152
$(call go_build_tool,honnef.co/go/tools/cmd/staticcheck)
@@ -217,27 +220,11 @@ $(THRIFT_GEN): $(THRIFT_FILES) $(BIN)/thriftrw $(BIN)/thriftrw-plugin-yarpc
217220
# other intermediates
218221
# ====================================
219222

220-
# golint fails to report many lint failures if it is only given a single file
221-
# to work on at a time, and it can't handle multiple packages at once, *and*
222-
# we can't exclude files from its checks, so for best results we need to give
223-
# it a whitelist of every file in every package that we want linted, per package.
224-
#
225-
# so lint + this golint func works like:
226-
# - iterate over all lintable dirs (outputs "./folder/")
227-
# - find .go files in a dir (via wildcard, so not recursively)
228-
# - filter to only files in LINT_SRC
229-
# - if it's not empty, run golint against the list
230-
define lint_if_present
231-
test -n "$1" && $(BIN)/golint -set_exit_status $1
232-
endef
233-
234-
# TODO: replace this with revive, like the server.
235-
# keep in sync with `lint`
236-
$(BUILD)/lint: $(BIN)/golint $(ALL_SRC)
237-
$Q $(foreach pkg, \
238-
$(sort $(dir $(LINT_SRC))), \
239-
$(call lint_if_present,$(filter $(wildcard $(pkg)*.go),$(LINT_SRC))) || ERR=1; \
240-
) test -z "$$ERR"; touch $@; exit $$ERR
223+
# note that LINT_SRC is fairly fake as a prerequisite.
224+
# it's a coarse "you probably don't need to re-lint" filter, nothing more.
225+
$(BUILD)/lint: $(LINT_SRC) $(BIN)/revive | $(BUILD)
226+
$Q $(BIN)/revive -config revive.toml -exclude './vendor/...' -exclude './.gen/...' -formatter stylish ./...
227+
$Q touch $@
241228

242229
# fmt and copyright are mutually cyclic with their inputs, so if a copyright header is modified:
243230
# - copyright -> makes changes
@@ -253,11 +240,10 @@ $(BUILD)/lint: $(BIN)/golint $(ALL_SRC)
253240
MAYBE_TOUCH_COPYRIGHT=
254241

255242
# TODO: switch to goimports, so we can pin the version
256-
$(BUILD)/fmt: $(ALL_SRC)
257-
$Q echo "gofmt..."
243+
$(BUILD)/fmt: $(ALL_SRC) $(BIN)/goimports
244+
$Q echo "goimports..."
258245
$Q # use FRESH_ALL_SRC so it won't miss any generated files produced earlier
259-
$Q gofmt -w $(ALL_SRC)
260-
$Q # ideally, mimic server: $(BIN)/goimports -local "go.uber.org/cadence" -w $(FRESH_ALL_SRC)
246+
$Q $(BIN)/goimports -local "go.uber.org/cadence" -w $(FRESH_ALL_SRC)
261247
$Q touch $@
262248
$Q $(MAYBE_TOUCH_COPYRIGHT)
263249

@@ -274,22 +260,25 @@ $(BUILD)/copyright: $(ALL_SRC) $(BIN)/copyright
274260
# this way the effort is shared with future `make` runs.
275261
# ====================================
276262

263+
# "re-make" a target by deleting and re-building book-keeping target(s).
264+
# the + is necessary for parallelism flags to be propagated
265+
define remake
266+
$Q rm -f $(addprefix $(BUILD)/,$(1))
267+
$Q +$(MAKE) --no-print-directory $(addprefix $(BUILD)/,$(1))
268+
endef
269+
277270
.PHONY: build
278271
build: $(BUILD)/dummy ## ensure all packages build
279272

280273
.PHONY: lint
281-
# useful to actually re-run to get output again, as the intermediate will not be run unless necessary.
282-
# dummy is used only because it occurs before $(BUILD)/lint, fmt would likely be sufficient too.
283-
# keep in sync with `$(BUILD)/lint`
284-
lint: $(BUILD)/dummy $(BIN)/golint ## (re)run golint
285-
$Q $(foreach pkg, \
286-
$(sort $(dir $(LINT_SRC))), \
287-
$(call lint_if_present,$(filter $(wildcard $(pkg)*.go),$(LINT_SRC))) || ERR=1; \
288-
) test -z "$$ERR"; touch $(BUILD)/lint; exit $$ERR
274+
# useful to actually re-run to get output again.
275+
# reuse the intermediates for simplicity and consistency.
276+
lint: ## (re)run the linter
277+
$(call remake,lint)
289278

290279
.PHONY: fmt
291-
# intentionally not re-making, gofmt is slow and it's clear when it's unnecessary
292-
fmt: $(BUILD)/fmt ## run gofmt
280+
# intentionally not re-making, it's clear when it's unnecessary
281+
fmt: $(BUILD)/fmt ## run goimports
293282

294283
.PHONY: copyright
295284
# not identical to the intermediate target, but does provide the same codegen (or more).

activity/activity.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import (
2424
"context"
2525

2626
"github.com/uber-go/tally"
27-
"go.uber.org/cadence/internal"
2827
"go.uber.org/zap"
28+
29+
"go.uber.org/cadence/internal"
2930
)
3031

3132
type (

compatibility/thrift2proto.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
package compatibility
2222

2323
import (
24-
apiv1 "github.com/uber/cadence-idl/go/proto/api/v1"
2524
"go.uber.org/cadence/.gen/go/cadence/workflowserviceclient"
2625
internal "go.uber.org/cadence/internal/compatibility"
26+
27+
apiv1 "github.com/uber/cadence-idl/go/proto/api/v1"
2728
)
2829

2930
// NewThrift2ProtoAdapter creates an adapter for mapping calls from Thrift to Protobuf types.

evictiontest/workflow_cache_eviction_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ import (
3737
"github.com/golang/mock/gomock"
3838
"github.com/stretchr/testify/suite"
3939
"go.uber.org/atomic"
40+
"go.uber.org/yarpc"
41+
"go.uber.org/zap/zaptest"
42+
"golang.org/x/net/context"
43+
4044
"go.uber.org/cadence/.gen/go/cadence/workflowservicetest"
4145
m "go.uber.org/cadence/.gen/go/shared"
4246
"go.uber.org/cadence/internal"
4347
"go.uber.org/cadence/internal/common"
4448
"go.uber.org/cadence/worker"
45-
"go.uber.org/yarpc"
46-
"go.uber.org/zap/zaptest"
47-
"golang.org/x/net/context"
4849
)
4950

5051
// copied from internal/test_helpers_test.go

internal/activity.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ import (
2828

2929
"github.com/opentracing/opentracing-go"
3030
"github.com/uber-go/tally"
31-
"go.uber.org/cadence/.gen/go/shared"
3231
"go.uber.org/zap"
3332
"go.uber.org/zap/zapcore"
33+
34+
"go.uber.org/cadence/.gen/go/shared"
3435
)
3536

3637
type (

internal/activity_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ import (
2727
"github.com/golang/mock/gomock"
2828
"github.com/stretchr/testify/require"
2929
"github.com/stretchr/testify/suite"
30+
"go.uber.org/yarpc"
31+
3032
"go.uber.org/cadence/.gen/go/cadence/workflowservicetest"
3133
"go.uber.org/cadence/.gen/go/shared"
3234
"go.uber.org/cadence/internal/common"
33-
"go.uber.org/yarpc"
3435
)
3536

3637
type activityTestSuite struct {

internal/client.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ import (
2828

2929
"github.com/opentracing/opentracing-go"
3030
"github.com/uber-go/tally"
31+
"go.uber.org/zap"
32+
3133
"go.uber.org/cadence/.gen/go/cadence/workflowserviceclient"
3234
s "go.uber.org/cadence/.gen/go/shared"
3335
"go.uber.org/cadence/internal/common/auth"
3436
"go.uber.org/cadence/internal/common/metrics"
35-
"go.uber.org/zap"
3637
)
3738

3839
const (

internal/common/auth/service_wrapper.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ package auth
2323
import (
2424
"context"
2525

26+
"go.uber.org/yarpc"
27+
2628
"go.uber.org/cadence/.gen/go/cadence/workflowserviceclient"
2729
"go.uber.org/cadence/.gen/go/shared"
28-
"go.uber.org/yarpc"
2930
)
3031

3132
const (

internal/common/auth/service_wrapper_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ package auth
2222

2323
import (
2424
"fmt"
25-
"github.com/uber/tchannel-go/thrift"
26-
"go.uber.org/cadence/.gen/go/shared"
2725
"testing"
2826
"time"
2927

3028
"github.com/golang/mock/gomock"
31-
"go.uber.org/cadence/.gen/go/cadence/workflowservicetest"
32-
3329
"github.com/stretchr/testify/suite"
30+
"github.com/uber/tchannel-go/thrift"
31+
32+
"go.uber.org/cadence/.gen/go/cadence/workflowservicetest"
33+
"go.uber.org/cadence/.gen/go/shared"
3434
)
3535

3636
type (

internal/common/backoff/retry_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"time"
2828

2929
"github.com/stretchr/testify/assert"
30+
3031
"go.uber.org/cadence/.gen/go/shared"
3132
)
3233

internal/common/metrics/service_wrapper.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ import (
2626
"time"
2727

2828
"github.com/uber-go/tally"
29+
"go.uber.org/yarpc"
30+
2931
"go.uber.org/cadence/.gen/go/cadence/workflowserviceclient"
3032
"go.uber.org/cadence/.gen/go/shared"
31-
"go.uber.org/yarpc"
3233
)
3334

3435
type (

internal/common/metrics/service_wrapper_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ import (
3232
"github.com/stretchr/testify/require"
3333
"github.com/uber-go/tally"
3434
"github.com/uber/tchannel-go/thrift"
35+
"go.uber.org/yarpc"
36+
3537
"go.uber.org/cadence/.gen/go/cadence/workflowserviceclient"
3638
"go.uber.org/cadence/.gen/go/cadence/workflowservicetest"
3739
s "go.uber.org/cadence/.gen/go/shared"
38-
"go.uber.org/yarpc"
3940
)
4041

4142
var (

internal/common/serializer/history_serializer.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ import (
2525
"encoding/json"
2626
"errors"
2727
"fmt"
28-
"go.uber.org/cadence/.gen/go/shared"
28+
2929
"go.uber.org/thriftrw/protocol"
3030
"go.uber.org/thriftrw/wire"
31+
32+
"go.uber.org/cadence/.gen/go/shared"
3133
)
3234

3335
type (

0 commit comments

Comments
 (0)