Skip to content

Commit 1cb4b5d

Browse files
authored
Migrate golangci-lint to GitHub Actions (#1351)
* Migrate golangci-lint to GitHub Actions * `golangci-lint migrate` * Fix golangci-lint issues
1 parent a3a6bf5 commit 1cb4b5d

File tree

9 files changed

+70
-50
lines changed

9 files changed

+70
-50
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: golangci-lint
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
golangci:
12+
name: lint
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
16+
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
17+
with:
18+
go-version-file: go.mod
19+
- name: golangci-lint
20+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
21+
with:
22+
version: v2.5.0
23+
args: --timeout=8m

.golangci.yaml

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
1+
version: "2"
12
run:
2-
# timeout for analysis, e.g. 30s, 5m, default is 1m
3-
deadline: 90s
43
build-tags:
54
- lint
6-
7-
linters-settings:
8-
gocyclo:
9-
# minimal code complexity to report, 30 by default (but we recommend 10-20)
10-
min-complexity: 25
11-
depguard:
12-
packages:
13-
- golang.org/x/net/context
14-
- github.com/gogo/protobuf/proto
15-
- encoding/asn1
16-
- crypto/x509
17-
18-
issues:
19-
# Don't turn off any checks by default. We can do this explicitly if needed.
20-
exclude-use-default: false
21-
# List of regexps of issue texts to exclude.
22-
#
23-
# But independently of this option we use default exclude patterns,
24-
# it can be disabled by `exclude-use-default: false`.
25-
# To list all excluded by default patterns execute `golangci-lint run --help`
26-
#
27-
# Default: https://golangci-lint.run/usage/false-positives/#default-exclusions
28-
exclude:
29-
- "package-comments: should have a package comment"
30-
31-
exclude-rules:
32-
# The following grpc linters are excluded because grpc.Dial, grpc.DialContext and grpc.WithBlock will be supported throughout 1.x.
33-
- linters: [staticcheck]
34-
text: 'SA1019: grpc.Dial is deprecated: use NewClient instead'
35-
- linters: [staticcheck]
36-
text: 'SA1019: grpc.DialContext is deprecated: use NewClient instead'
37-
- linters: [staticcheck]
38-
text: 'SA1019: grpc.WithBlock is deprecated: this DialOption is not supported by NewClient'
5+
linters:
6+
settings:
7+
depguard:
8+
rules:
9+
main:
10+
deny:
11+
- pkg: golang.org/x/net/context
12+
- pkg: github.com/gogo/protobuf/proto
13+
- pkg: encoding/asn1
14+
- pkg: crypto/x509
15+
gocyclo:
16+
min-complexity: 25
17+
exclusions:
18+
generated: lax
19+
rules:
20+
- linters:
21+
- staticcheck
22+
text: 'SA1019: grpc.Dial is deprecated: use NewClient instead'
23+
- linters:
24+
- staticcheck
25+
text: 'SA1019: grpc.DialContext is deprecated: use NewClient instead'
26+
- linters:
27+
- staticcheck
28+
text: 'SA1019: grpc.WithBlock is deprecated: this DialOption is not supported by NewClient'
29+
- path: (.+)\.go$
30+
text: 'package-comments: should have a package comment'
31+
paths:
32+
- third_party$
33+
- builtin$
34+
- examples$
35+
formatters:
36+
exclusions:
37+
generated: lax
38+
paths:
39+
- third_party$
40+
- builtin$
41+
- examples$

binary_transparency/firmware/cmd/ft_witness/impl/ft_witness.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type WitnessOpts struct {
4242
// Main kickstarts the witness
4343
func Main(ctx context.Context, opts WitnessOpts) error {
4444
if len(opts.WSFile) == 0 {
45-
return errors.New("Witness Store file is required")
45+
return errors.New("witness store file is required")
4646
}
4747

4848
ws, err := ws.NewStorage(opts.WSFile)

binary_transparency/firmware/internal/crypto/signature.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,6 @@ func ClaimantForType(t api.StatementType) (*Claimant, error) {
158158
case api.MalwareStatementType:
159159
return &AnnotatorMalware, nil
160160
default:
161-
return nil, fmt.Errorf("Unknown Claimant type %v", t)
161+
return nil, fmt.Errorf("unknown Claimant type %v", t)
162162
}
163163
}

clone/cmd/sumdbverify/verify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (v sumdbVerifier) verifyLeaves(ctx context.Context) (uint64, error) {
194194
return 0, fmt.Errorf("GetRootHash(): %v", err)
195195
}
196196
if !bytes.Equal(rootHash, cp.Hash) {
197-
return 0, fmt.Errorf("Data corruption: checkpoint from DB has hash %x but calculated hash %x from leaves", cp.Hash, rootHash)
197+
return 0, fmt.Errorf("data corruption: checkpoint from DB has hash %x but calculated hash %x from leaves", cp.Hash, rootHash)
198198
}
199199
return index, nil
200200
}

experimental/batchmap/ctmap/cmd/build/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func (w *writeCheckpointFn) ProcessElement(ctx context.Context, t *batchmap.Tile
222222
return err
223223
}
224224

225-
if _, err := fd.Write([]byte(fmt.Sprintf("%d\n%x\n", w.EntryCount, root))); err != nil {
225+
if _, err := fd.Write(fmt.Appendf(nil, "%d\n%x\n", w.EntryCount, root)); err != nil {
226226
return err
227227
}
228228
if _, err := fd.Write(w.LogCheckpoint); err != nil {

experimental/batchmap/sumdb/build/pipeline/entries.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@ func ParseStatementFn(l InputLogLeaf) Metadata {
6565
lines := strings.Split(string(l.Data), "\n")
6666

6767
if len(lines) != 3 {
68-
panic(fmt.Errorf("Expected 2 lines in log leaf, but got %d", len(lines)))
68+
panic(fmt.Errorf("expected 2 lines in log leaf, but got %d", len(lines)))
6969
}
7070
line0Parts := line0RE.FindStringSubmatch(lines[0])
7171
if got, want := len(line0Parts), 4; got != want {
72-
panic(fmt.Errorf("Regexp: line0 expected %d submatches, but got %d", want, got))
72+
panic(fmt.Errorf("regexp: line0 expected %d submatches, but got %d", want, got))
7373
}
7474
line0Module, line0Version, line0Hash := line0Parts[1], line0Parts[2], line0Parts[3]
7575

7676
line1Parts := line1RE.FindStringSubmatch(lines[1])
7777
if got, want := len(line1Parts), 4; got != want {
78-
panic(fmt.Errorf("Regexp: line1 expected %d submatches, but got %d (%q)", want, got, lines[1]))
78+
panic(fmt.Errorf("regexp: line1 expected %d submatches, but got %d (%q)", want, got, lines[1]))
7979
}
8080
line1Module, line1Version, line1Hash := line1Parts[1], line1Parts[2], line1Parts[3]
8181

@@ -113,7 +113,7 @@ type mapEntryFn struct {
113113

114114
func (fn *mapEntryFn) ProcessElement(m Metadata, emit func(*batchmap.Entry)) {
115115
h := hash.New()
116-
h.Write([]byte(fmt.Sprintf("%s %s/go.mod", m.Module, m.Version)))
116+
h.Write(fmt.Appendf(nil, "%s %s/go.mod", m.Module, m.Version))
117117
modKey := h.Sum(nil)
118118
modLeafID := node.NewID(string(modKey), uint(len(modKey)*8))
119119

@@ -123,7 +123,7 @@ func (fn *mapEntryFn) ProcessElement(m Metadata, emit func(*batchmap.Entry)) {
123123
})
124124

125125
h = hash.New()
126-
h.Write([]byte(fmt.Sprintf("%s %s", m.Module, m.Version)))
126+
h.Write(fmt.Appendf(nil, "%s %s", m.Module, m.Version))
127127
repoKey := h.Sum(nil)
128128
repoLeafID := node.NewID(string(repoKey), uint(len(repoKey)*8))
129129

integration/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ RUN echo "deb http://deb.debian.org/debian bookworm-backports main contrib non-f
1010
RUN apt-get update && apt-get -y install curl docker-compose lsof netcat-traditional unzip wget xxd
1111

1212
RUN cd /usr/bin && curl -L -O https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && mv jq-linux64 /usr/bin/jq && chmod +x /usr/bin/jq
13-
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.64.6
1413
RUN mkdir protoc && \
1514
(cd protoc && \
1615
wget "https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip" && \

scripts/presubmit.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ main() {
127127
fi
128128

129129
if [[ "${run_lint}" -eq 1 ]]; then
130-
check_cmd golangci-lint \
131-
'have you installed github.com/golangci/golangci-lint?' || exit 1
132-
133-
echo 'running golangci-lint'
134-
golangci-lint run --timeout=10m
135130
echo 'checking license headers'
136131
./scripts/check_license.sh ${go_srcs}
137132
fi

0 commit comments

Comments
 (0)