Skip to content

Commit

Permalink
(from AES) CI: Add a job to check that Go code is formatted with `gof…
Browse files Browse the repository at this point in the history
…mt -s`
  • Loading branch information
LukeShu committed Sep 2, 2020
1 parent f53e5f8 commit c688fc3
Show file tree
Hide file tree
Showing 7 changed files with 594 additions and 111 deletions.
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ jobs:
machine:
image: "ubuntu-1604:201903-01"
working_directory: ~/project/ambassador
oss-dev-lint:
steps:
- oss-linux-setup
- run: make lint
machine:
image: "ubuntu-1604:201903-01"
working_directory: ~/project/ambassador
oss-dev-images:
steps:
- oss-linux-setup
Expand Down Expand Up @@ -489,6 +496,7 @@ workflows:
jobs:
- "oss-dev-images"
- "oss-dev-generate"
- "oss-dev-lint"
'OSS: Release':
when:
or:
Expand Down
7 changes: 7 additions & 0 deletions .circleci/config.yml.d/oss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ jobs:
- run: make generate
- dirty-check

"oss-dev-lint":
<<: *oss-linux-job
steps:
- oss-linux-setup
- run: make lint

"oss-dev-images":
<<: *oss-linux-job
steps:
Expand Down Expand Up @@ -190,6 +196,7 @@ workflows:
jobs:
- "oss-dev-images"
- "oss-dev-generate"
- "oss-dev-lint"
"OSS: Release":
when:
or:
Expand Down
57 changes: 57 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Start with a very conservative configuration, and slowly turn things
# back on.
linters:
disable-all: true
enable:
- gofmt
linters-settings:
gofmt:
simplify: true

# The old configuration, that hasn't been used for many months:

#linters:
# enable-all: true
# disable:
# - errcheck
# - gochecknoglobals
# - gochecknoinits
# - golint
# - interfacer # author says it's deprecated, gives very subjective advice
# - lll
# - maligned
# - prealloc
# - scopelint
# - stylecheck
# - unparam
# - unused # confused by dev-portal-server, for some reason
#linters-settings:
# unused:
# # treat code as a program (not a library) and report unused
# # exported identifiers
# check-exported: true
# goimports:
# # put imports beginning with prefix after 3rd-party packages;
# # it's a comma-separated list of prefixes
# local-prefixes: github.com/datawire/apro,github.com/lyft/ratelimit
# depguard:
# list-type: blacklist
# include-go-root: true
# packages:
# - errors # use "github.com/pkg/errors"
# - golang.org/x/net/context # use "context"
# - github.com/datawire/teleproxy # use "github.com/datawire/ambassador/pkg"
# - github.com/datawire/ambassador/go # use "github.com/datawire/ambassador/pkg"
# - github.com/datawire/kat-backend/xds # use "github.com/datawire/ambassador/pkg/api/envoy"
# - github.com/lyft/ratelimit/proto # use "github.com/datawire/ambassador/pkg/api/envoy"
# #- github.com/russross/blackfriday # use "github.com/russross/blackfriday/v2" # can't turn off prefix-matching
# - gopkg.in/russross/blackfriday.v2 # use "github.com/russross/blackfriday/v2"
# goconst:
# min-len: 12
#issues:
# new-from-rev: a72c53cbcd05c806b1838d95146d049b09a51ffb
#run:
# build-tags:
# - test
# - integration
# - lint
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ include $(OSS_HOME)/_cxx/envoy.mk
$(call module,ambassador,$(OSS_HOME))

include $(OSS_HOME)/build-aux-local/generate.mk
include $(OSS_HOME)/build-aux-local/lint.mk

# Configure GNU Make itself
SHELL = bash
Expand Down
26 changes: 26 additions & 0 deletions build-aux-local/lint.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Must be included *after* generate.mk, because we use GOHOSTOS and GOHOSTARCH defined there.

# The version number of golangci-lint is controllers in a go.mod file
tools/golangci-lint = $(OSS_HOME)/bin_$(GOHOSTOS)_$(GOHOSTARCH)/golangci-lint
$(tools/golangci-lint): $(OSS_HOME)/build-aux/bin-go/golangci-lint/go.mod
mkdir -p $(@D)
cd $(<D) && go build -o $@ github.com/golangci/golangci-lint/cmd/golangci-lint

lint/go-dirs = $(OSS_HOME)

lint: $(tools/golangci-lint)
@PS4=; set -x; r=0; { \
for dir in $(lint/go-dirs); do \
(cd $$dir && $(tools/golangci-lint) run ./...) || r=$?; \
done; \
exit $$r; \
}
.PHONY: lint

format: $(tools/golangci-lint)
@PS4=; set -x; { \
for dir in $(lint/go-dirs); do \
(cd $$dir && $(tools/golangci-lint) run ./...) || true; \
exit $$r; \
}
.PHONY: format
16 changes: 2 additions & 14 deletions build-aux/bin-go/golangci-lint/go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
module github.com/datawire/build-aux/bin-go/golangci-lint

go 1.12
go 1.15

require github.com/golangci/golangci-lint v1.17.1

// Fix incorrect timestamps that Go 1.13 complains about.
replace (
github.com/go-critic/go-critic v0.0.0-20181204210945-1df300866540 => github.com/go-critic/go-critic v0.0.0-20190526074819-1df300866540
github.com/golangci/errcheck v0.0.0-20181003203344-ef45e06d44b6 => github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6
github.com/golangci/go-tools v0.0.0-20180109140146-af6baa5dc196 => github.com/golangci/go-tools v0.0.0-20190318060251-af6baa5dc196
github.com/golangci/gofmt v0.0.0-20181105071733-0b8337e80d98 => github.com/golangci/gofmt v0.0.0-20181222123516-0b8337e80d98
github.com/golangci/gosec v0.0.0-20180901114220-66fb7fc33547 => github.com/golangci/gosec v0.0.0-20190211064107-66fb7fc33547
github.com/golangci/ineffassign v0.0.0-20180808204949-42439a7714cc => github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc
github.com/golangci/lint-1 v0.0.0-20180610141402-ee948d087217 => github.com/golangci/lint-1 v0.0.0-20190420132249-ee948d087217
mvdan.cc/unparam v0.0.0-20190124213536-fbb59629db34 => mvdan.cc/unparam v0.0.0-20190209190245-fbb59629db34
)
require github.com/golangci/golangci-lint v1.30.0
Loading

0 comments on commit c688fc3

Please sign in to comment.