@@ -142,8 +142,11 @@ $(BIN)/thriftrw: internal/tools/go.mod
142
142
$(BIN ) /thriftrw-plugin-yarpc : internal/tools/go.mod
143
143
$(call go_build_tool,go.uber.org/yarpc/encoding/thrift/thriftrw-plugin-yarpc)
144
144
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)
147
150
148
151
$(BIN ) /staticcheck : internal/tools/go.mod
149
152
$(call go_build_tool,honnef.co/go/tools/cmd/staticcheck)
@@ -217,27 +220,11 @@ $(THRIFT_GEN): $(THRIFT_FILES) $(BIN)/thriftrw $(BIN)/thriftrw-plugin-yarpc
217
220
# other intermediates
218
221
# ====================================
219
222
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 $@
241
228
242
229
# fmt and copyright are mutually cyclic with their inputs, so if a copyright header is modified:
243
230
# - copyright -> makes changes
@@ -253,11 +240,10 @@ $(BUILD)/lint: $(BIN)/golint $(ALL_SRC)
253
240
MAYBE_TOUCH_COPYRIGHT =
254
241
255
242
# 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 ..."
258
245
$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 )
261
247
$Q touch $@
262
248
$Q $(MAYBE_TOUCH_COPYRIGHT )
263
249
@@ -274,22 +260,25 @@ $(BUILD)/copyright: $(ALL_SRC) $(BIN)/copyright
274
260
# this way the effort is shared with future `make` runs.
275
261
# ====================================
276
262
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
+
277
270
.PHONY : build
278
271
build : $(BUILD ) /dummy # # ensure all packages build
279
272
280
273
.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)
289
278
290
279
.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
293
282
294
283
.PHONY : copyright
295
284
# not identical to the intermediate target, but does provide the same codegen (or more).
0 commit comments