Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.

Commit 02a136a

Browse files
authored
Switch linting to GitHub Actions (#1373)
* Switch linting to GitHub Actions Also fix issues identified by linter * Spelling
1 parent daff00a commit 02a136a

File tree

110 files changed

+739
-581
lines changed

Some content is hidden

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

110 files changed

+739
-581
lines changed

.github/workflows/codereview.yaml

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,35 @@ on:
66
- 'main'
77

88
jobs:
9-
only-user-errors:
10-
name: errorw-bot
9+
golangci-lint:
10+
name: go-lint
1111
runs-on: ubuntu-latest
1212

13+
steps:
14+
- name: Check out code
15+
uses: actions/checkout@v2
16+
17+
- name: lint
18+
uses: golangci/golangci-lint-action@v2
19+
with:
20+
version: v1.36.0
21+
only-new-issues: true
22+
23+
reviewdog:
24+
name: reviewdog
25+
runs-on: ubuntu-latest
26+
continue-on-error: true
27+
1328
steps:
1429
- name: Check out code
1530
uses: actions/checkout@v2
1631

1732
- uses: reviewdog/action-setup@v1
1833

19-
- name: Check
34+
- name: Install pcregrep
35+
run: sudo apt-get -yqq install pcregrep
36+
37+
- name: errorw
2038
shell: bash
2139
env:
2240
REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }}
@@ -32,17 +50,7 @@ jobs:
3250
-fail-on-error="false" \
3351
-level="warning"
3452
35-
copyright-check:
36-
name: copyright-check
37-
runs-on: ubuntu-latest
38-
39-
steps:
40-
- name: Check out code
41-
uses: actions/checkout@v2
42-
43-
- uses: reviewdog/action-setup@v1
44-
45-
- name: Check
53+
- name: copyright-check
4654
shell: bash
4755
env:
4856
REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }}
@@ -59,6 +67,23 @@ jobs:
5967
-fail-on-error="true" \
6068
-level="error"
6169
70+
- name: tab-check
71+
shell: bash
72+
env:
73+
REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }}
74+
run: |-
75+
set -eEu
76+
set +o pipefail
77+
78+
YEAR=$(date +"%Y")
79+
make tabcheck | \
80+
reviewdog -efm="%f:%l:%m" \
81+
-name="tab-check" \
82+
-reporter="github-pr-review" \
83+
-filter-mode="diff_context" \
84+
-fail-on-error="true" \
85+
-level="error"
86+
6287
zap-logger:
6388
name: zap-logger
6489
runs-on: ubuntu-latest

.golangci.yaml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
run:
16+
# default: '1m'
17+
timeout: '5m'
18+
19+
# default: []
20+
build-tags:
21+
- 'all'
22+
23+
# default: []
24+
skip-dirs:
25+
- 'internal/pb'
26+
27+
# default: true
28+
skip-dirs-use-default: false
29+
30+
# default: ''
31+
modules-download-mode: 'readonly'
32+
33+
# default: false
34+
allow-parallel-runners: true
35+
36+
linters:
37+
enable:
38+
- 'asciicheck'
39+
- 'bodyclose'
40+
- 'deadcode'
41+
- 'depguard'
42+
- 'dogsled'
43+
- 'errcheck'
44+
- 'errorlint'
45+
- 'exportloopref'
46+
- 'gofmt'
47+
- 'gofumpt'
48+
- 'goheader'
49+
- 'goimports'
50+
- 'golint'
51+
- 'gomodguard'
52+
- 'goprintffuncname'
53+
- 'gosec'
54+
- 'gosimple'
55+
- 'govet'
56+
- 'ineffassign'
57+
- 'interfacer'
58+
- 'makezero'
59+
- 'misspell'
60+
- 'noctx'
61+
- 'nolintlint'
62+
- 'paralleltest'
63+
- 'prealloc'
64+
- 'predeclared'
65+
- 'scopelint'
66+
- 'sqlclosecheck'
67+
- 'staticcheck'
68+
- 'structcheck'
69+
- 'stylecheck'
70+
- 'typecheck'
71+
- 'unconvert'
72+
- 'unused'
73+
- 'varcheck'
74+
- 'whitespace'
75+
76+
issues:
77+
# default: []
78+
exclude:
79+
- '^S1023:' # staticcheck: redundant returns help with http handlers
80+
- '^SA3000:' # staticcheck: not required in Go 11.4+
81+
- '^G102:' # gosec: we have to bind to all ifaces
82+
- '^G402:' # gosec: some services terminate at the load balancer
83+
- '^G505:' # gosec: we use crypto/sha1 for some HMACs
84+
- '^Range statement' # paralleltest: false positives
85+
86+
# default: 50
87+
max-issues-per-linter: 0
88+
89+
# default: 3
90+
max-same-issues: 0
91+
92+
severity:
93+
# default: ''
94+
default-severity: error

Makefile

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,32 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
VETTERS = "asmdecl,assign,atomic,bools,buildtag,cgocall,composites,copylocks,errorsas,httpresponse,loopclosure,lostcancel,nilfunc,printf,shift,stdmethods,structtag,tests,unmarshal,unreachable,unsafeptr,unusedresult"
1615
GOFMT_FILES = $(shell go list -f '{{.Dir}}' ./... | grep -v '/pb')
16+
HTML_FILES = $(shell find . -name \*.html)
1717
GO_FILES = $(shell find . -name \*.go)
18-
19-
bodyclose:
20-
@command -v bodyclose > /dev/null 2>&1 || go get github.com/timakin/bodyclose
21-
@go vet -tags=all -vettool=$$(which bodyclose) ./...
22-
.PHONY: bodyclose
23-
24-
fmtcheck:
25-
@command -v goimports > /dev/null 2>&1 || go get golang.org/x/tools/cmd/goimports
26-
@CHANGES="$$(goimports -d $(GOFMT_FILES))"; \
27-
if [ -n "$${CHANGES}" ]; then \
28-
echo "Unformatted (run goimports -w .):\n\n$${CHANGES}\n\n"; \
29-
exit 1; \
30-
fi
31-
@# Annoyingly, goimports does not support the simplify flag.
32-
@CHANGES="$$(gofmt -s -d $(GOFMT_FILES))"; \
33-
if [ -n "$${CHANGES}" ]; then \
34-
echo "Unformatted (run gofmt -s -w .):\n\n$${CHANGES}\n\n"; \
18+
MD_FILES = $(shell find . -name \*.md)
19+
20+
# lint uses the same linter as CI and tries to report the same results running
21+
# locally. There is a chance that CI detects linter errors that are not found
22+
# locally, but it should be rare.
23+
lint:
24+
@command -v golangci-lint > /dev/null 2>&1 || GO111MODULE=off go get github.com/golangci/golangci-lint/cmd/[email protected]
25+
golangci-lint run --config .golangci.yaml
26+
.PHONY: lint
27+
28+
tabcheck:
29+
@FINDINGS="$$(awk '/\t/ {printf "%s:%s:found tab character\n",FILENAME,FNR}' $(HTML_FILES))"; \
30+
if [ -n "$${FINDINGS}" ]; then \
31+
echo "$${FINDINGS}\n\n"; \
3532
exit 1; \
3633
fi
37-
.PHONY: fmtcheck
38-
39-
spellcheck:
40-
@command -v misspell > /dev/null 2>&1 || go get github.com/client9/misspell/cmd/misspell
41-
@misspell -locale="US" -error -source="text" **/*
42-
.PHONY: spellcheck
43-
44-
# SA3000 is not required in Go 1.15+: https://github.com/dominikh/go-tools/issues/708
45-
staticcheck:
46-
@command -v staticcheck > /dev/null 2>&1 || go get honnef.co/go/tools/cmd/staticcheck
47-
@staticcheck -tags=all -checks="all,-SA3000" -tests $(GOFMT_FILES)
48-
.PHONY: staticcheck
49-
50-
zapcheck:
51-
@command -v zapw > /dev/null 2>&1 || GO111MODULE=off go get github.com/sethvargo/zapw/cmd/zapw
52-
@zapw ./...
34+
.PHONY: tabcheck
5335

5436
test:
5537
@go test \
5638
-count=1 \
5739
-short \
5840
-timeout=5m \
59-
-vet="${VETTERS}" \
6041
./...
6142
.PHONY: test
6243

@@ -65,11 +46,15 @@ test-acc:
6546
-count=1 \
6647
-race \
6748
-timeout=10m \
68-
-vet="${VETTERS}" \
6949
./... \
7050
-coverprofile=coverage.out
7151
.PHONY: test-acc
7252

7353
test-coverage:
7454
@go tool cover -func ./coverage.out | grep total
7555
.PHONY: test-coverage
56+
57+
zapcheck:
58+
@command -v zapw > /dev/null 2>&1 || GO111MODULE=off go get github.com/sethvargo/zapw/cmd/zapw
59+
@zapw ./...
60+
.PHONY: zapcheck

cmd/admin-console/templates/export.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<option value="false" {{if not .export.IncludeTravelers}}selected{{end}}>No</option>
5252
</select>
5353
<small class="form-text text-muted">
54-
Should federeated-in traveler keys be included in this export. If this
54+
Should federated-in traveler keys be included in this export. If this
5555
server is sharing keys with anouther server, the recommended setting
5656
is 'yes'. Even if you are not yet federating, but may in the future,
5757
'yes' is still the recommended setting.
@@ -65,9 +65,8 @@
6565
<option value="false" {{if not .export.OnlyNonTravelers}}selected{{end}}>No</option>
6666
</select>
6767
<small class="form-text text-muted">
68-
Should only federeated-in non-traveler keys be included in this
69-
export. Note, setting this with 'Include Travelers' will result in an
70-
error.
68+
Should only federated-in non-traveler keys be included in this export.
69+
Note, setting this with 'Include Travelers' will result in an error.
7170
</small>
7271
</div>
7372

@@ -77,7 +76,7 @@
7776
<label for="exclude-regions">Exclude regions</label>
7877
<small class="form-text text-muted">
7978
One per line, leave blank for only using the output region (above).
80-
Allows you to exclude travelers from certain regions.
79+
Allows you to exclude travelers from certain regions.
8180
</small>
8281
</div>
8382

docs/playbooks/playbook_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func allPlaybookNames(t *testing.T) []string {
5353
if err != nil {
5454
t.Fatalf("failed to find all playbooks: %s", err)
5555
}
56-
var ret []string
56+
ret := make([]string, 0, len(files))
5757
for _, x := range files {
5858
basename := filepath.Base(x)
5959
ret = append(ret, basename[:len(basename)-len(".md")])
@@ -71,7 +71,7 @@ func allAlertNames(t *testing.T) []string {
7171
if diag.HasErrors() {
7272
t.Fatalf("failed to decode body: %v", diag)
7373
}
74-
var ret []string
74+
ret := make([]string, 0, len(c.Resources))
7575
for _, res := range c.Resources {
7676
if res.Type != "google_monitoring_alert_policy" {
7777
continue
@@ -103,7 +103,7 @@ func setDiff(xs, ys []string) []string {
103103
delete(s1, k)
104104
}
105105
}
106-
var ret []string
106+
ret := make([]string, 0, len(s1))
107107
for k := range s1 {
108108
ret = append(ret, k)
109109
}

internal/admin/config.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ import (
2929
"github.com/google/exposure-notifications-server/pkg/secrets"
3030
)
3131

32-
var _ setup.BlobstoreConfigProvider = (*Config)(nil)
33-
var _ setup.DatabaseConfigProvider = (*Config)(nil)
34-
var _ setup.KeyManagerConfigProvider = (*Config)(nil)
35-
var _ setup.SecretManagerConfigProvider = (*Config)(nil)
32+
var (
33+
_ setup.BlobstoreConfigProvider = (*Config)(nil)
34+
_ setup.DatabaseConfigProvider = (*Config)(nil)
35+
_ setup.KeyManagerConfigProvider = (*Config)(nil)
36+
_ setup.SecretManagerConfigProvider = (*Config)(nil)
37+
)
3638

3739
type Config struct {
3840
Database database.Config

internal/admin/handle_health_authority.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ func (s *Server) HandleHealthAuthorityKeys() func(c *gin.Context) {
141141
ErrorPage(c, fmt.Sprintf("Error saving health authority key: %v", err))
142142
return
143143
}
144-
145144
} else if action == "revoke" || action == "reinstate" || action == "activate" {
146145
version := c.Param("version")
147146

@@ -173,7 +172,6 @@ func (s *Server) HandleHealthAuthorityKeys() func(c *gin.Context) {
173172
ErrorPage(c, fmt.Sprintf("Error saving health authority key: %v", err))
174173
return
175174
}
176-
177175
} else {
178176
ErrorPage(c, "invalid action")
179177
return

internal/authorizedapp/database/authorized_app.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ func (aa *AuthorizedAppDB) InsertAuthorizedApp(ctx context.Context, m *model.Aut
5757
`, m.AppPackageName, m.AllAllowedRegions(),
5858
m.AllAllowedHealthAuthorityIDs(), m.BypassHealthAuthorityVerification,
5959
m.BypassRevisionToken)
60-
6160
if err != nil {
6261
return fmt.Errorf("inserting authorizedapp: %w", err)
6362
}

internal/authorizedapp/database/authorized_app_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,5 +296,4 @@ func TestListAuthorizedApps(t *testing.T) {
296296
if diff := cmp.Diff(apps, got); diff != "" {
297297
t.Errorf("mismatch (-want, +got):\n%s", diff)
298298
}
299-
300299
}

internal/authorizedapp/database_provider.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ func (p *DatabaseProvider) AppConfig(ctx context.Context, name string) (*model.A
8080
return config, nil
8181
}
8282
cached, err := p.cache.WriteThruLookup(name, lookup)
83-
8483
// Indicates an error on the write thru lookup.
8584
if err != nil {
8685
return nil, err

internal/cleanup/config.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ import (
2525
)
2626

2727
// Compile-time check to assert this config matches requirements.
28-
var _ setup.BlobstoreConfigProvider = (*Config)(nil)
29-
var _ setup.DatabaseConfigProvider = (*Config)(nil)
30-
var _ setup.SecretManagerConfigProvider = (*Config)(nil)
31-
var _ setup.ObservabilityExporterConfigProvider = (*Config)(nil)
28+
var (
29+
_ setup.BlobstoreConfigProvider = (*Config)(nil)
30+
_ setup.DatabaseConfigProvider = (*Config)(nil)
31+
_ setup.SecretManagerConfigProvider = (*Config)(nil)
32+
_ setup.ObservabilityExporterConfigProvider = (*Config)(nil)
33+
)
3234

3335
// Config represents the configuration and associated environment variables for
3436
// the cleanup components.

internal/database/connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func NewFromEnv(ctx context.Context, cfg *Config) (*DB, error) {
5252

5353
pool, err := pgxpool.ConnectConfig(ctx, pgxConfig)
5454
if err != nil {
55-
return nil, fmt.Errorf("failed to create connection pool: %v", err)
55+
return nil, fmt.Errorf("failed to create connection pool: %w", err)
5656
}
5757

5858
return &DB{Pool: pool}, nil

0 commit comments

Comments
 (0)