Skip to content

Commit 42b655d

Browse files
committed
*.go: update to golangci-lint, and fix everything
install tools in the workflow actions Also switch away from deprecated ioutil Signed-off-by: Vincent Batts <[email protected]>
1 parent e7a79ae commit 42b655d

19 files changed

+101
-78
lines changed

.github/workflows/go.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jobs:
2222
go-version: ${{ matrix.go }}
2323

2424
- name: Build
25-
run: make
25+
run: make build
2626

27-
- name: Test
27+
- name: Validation
2828
run: make validation
2929

3030
- name: Build.Arches

.github/workflows/validation.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: lint
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
11+
build:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
go: ['1.21']
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v3
21+
with:
22+
go-version: ${{ matrix.go }}
23+
24+
- name: Install tools
25+
run: make install.tools
26+
27+
- name: Test
28+
run: make lint

Makefile

+6-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ GO_VER := go1.14
1111
default: build validation
1212

1313
.PHONY: validation
14-
validation: .test .lint .vet .cli.test
14+
validation: .test .vet .cli.test
1515

1616
.PHONY: validation.tags
1717
validation.tags: .test.tags .vet.tags .cli.test .staticcheck
@@ -50,11 +50,7 @@ lint: .lint
5050
CLEAN_FILES += .lint
5151

5252
.lint: $(SOURCE_FILES)
53-
@if [ "$(findstring $(GO_VER),$(shell go version))" != "" ] ; then \
54-
set -e ; for dir in $(NO_VENDOR_DIR) ; do golint -set_exit_status $$dir ; done && touch $@ \
55-
else \
56-
touch $@ ; \
57-
fi
53+
set -e ; golangci-lint run && touch $@
5854

5955
.PHONY: vet
6056
vet: .vet .vet.tags
@@ -85,12 +81,10 @@ $(BUILD): $(SOURCE_FILES)
8581
go build -ldflags="-X 'main.Version=$(shell git describe --always --dirty)'" -mod=vendor -o $(BUILD) $(BUILDPATH)
8682

8783
install.tools:
88-
@go install -u github.com/fatih/color@latest ; \
89-
go install -u github.com/fzipp/gocyclo/cmd/gocyclo@latest ; \
90-
go install -u honnef.co/go/tools/cmd/staticcheck@latest ; \
91-
if [ "$(findstring $(GO_VER),$(shell go version))" != "" ] ; then \
92-
go get -u golang.org/x/lint/golint ;\
93-
fi
84+
@go install github.com/fatih/color@latest ; \
85+
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest ; \
86+
go install honnef.co/go/tools/cmd/staticcheck@latest ; \
87+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
9488

9589
./bin:
9690
mkdir -p $@

check_test.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package mtree
22

33
import (
44
"bytes"
5-
"io/ioutil"
65
"os"
76
"path/filepath"
87
"testing"
@@ -31,14 +30,14 @@ func TestCheck(t *testing.T) {
3130
// only check again for size and sha1, and ignore time, and ensure it passes
3231
func TestCheckKeywords(t *testing.T) {
3332
content := []byte("I know half of you half as well as I ought to")
34-
dir, err := ioutil.TempDir("", "test-check-keywords")
33+
dir, err := os.MkdirTemp("", "test-check-keywords")
3534
if err != nil {
3635
t.Fatal(err)
3736
}
3837
defer os.RemoveAll(dir) // clean up
3938

4039
tmpfn := filepath.Join(dir, "tmpfile")
41-
if err := ioutil.WriteFile(tmpfn, content, 0666); err != nil {
40+
if err := os.WriteFile(tmpfn, content, 0666); err != nil {
4241
t.Fatal(err)
4342
}
4443

@@ -120,7 +119,7 @@ func TestDefaultBrokenLink(t *testing.T) {
120119

121120
// https://github.com/vbatts/go-mtree/issues/8
122121
func TestTimeComparison(t *testing.T) {
123-
dir, err := ioutil.TempDir("", "test-time.")
122+
dir, err := os.MkdirTemp("", "test-time.")
124123
if err != nil {
125124
t.Fatal(err)
126125
}
@@ -165,7 +164,7 @@ func TestTimeComparison(t *testing.T) {
165164
}
166165

167166
func TestTarTime(t *testing.T) {
168-
dir, err := ioutil.TempDir("", "test-tar-time.")
167+
dir, err := os.MkdirTemp("", "test-tar-time.")
169168
if err != nil {
170169
t.Fatal(err)
171170
}
@@ -219,7 +218,7 @@ func TestTarTime(t *testing.T) {
219218
}
220219

221220
func TestIgnoreComments(t *testing.T) {
222-
dir, err := ioutil.TempDir("", "test-comments.")
221+
dir, err := os.MkdirTemp("", "test-comments.")
223222
if err != nil {
224223
t.Fatal(err)
225224
}
@@ -288,7 +287,7 @@ func TestIgnoreComments(t *testing.T) {
288287
}
289288

290289
func TestCheckNeedsEncoding(t *testing.T) {
291-
dir, err := ioutil.TempDir("", "test-needs-encoding")
290+
dir, err := os.MkdirTemp("", "test-needs-encoding")
292291
if err != nil {
293292
t.Fatal(err)
294293
}

cmd/gomtree/cmd/validate.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"os"
109
"strings"
1110

@@ -266,7 +265,7 @@ func validateAction(c *cli.Context) error {
266265
}
267266
ts := mtree.NewTarStreamer(input, excludes, currentKeywords)
268267

269-
if _, err := io.Copy(ioutil.Discard, ts); err != nil && err != io.EOF {
268+
if _, err := io.Copy(io.Discard, ts); err != nil && err != io.EOF {
270269
return err
271270
}
272271
if err := ts.Close(); err != nil {
@@ -344,8 +343,8 @@ func validateAction(c *cli.Context) error {
344343
}
345344

346345
// output stateDh
347-
stateDh.WriteTo(fh)
348-
return nil
346+
_, err = stateDh.WriteTo(fh)
347+
return err
349348
}
350349

351350
// no spec manifest has been provided yet, so look for it on stdin
@@ -358,7 +357,8 @@ func validateAction(c *cli.Context) error {
358357

359358
// We can't check against more fields than in the specKeywords list, so
360359
// currentKeywords can only have a subset of specKeywords.
361-
specKeywords = specDh.UsedKeywords()
360+
// TODO this specKeywords is not even used
361+
_ = specDh.UsedKeywords()
362362
}
363363

364364
// This is a validation.

compare_test.go

+18-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"bytes"
66
"encoding/json"
77
"io"
8-
"io/ioutil"
98
"os"
109
"path/filepath"
1110
"testing"
@@ -37,15 +36,15 @@ func TestCompare(t *testing.T) {
3736

3837
//gocyclo:ignore
3938
func TestCompareModified(t *testing.T) {
40-
dir, err := ioutil.TempDir("", "test-compare-modified")
39+
dir, err := os.MkdirTemp("", "test-compare-modified")
4140
if err != nil {
4241
t.Fatal(err)
4342
}
4443
defer os.RemoveAll(dir)
4544

4645
// Create a bunch of objects.
4746
tmpfile := filepath.Join(dir, "tmpfile")
48-
if err := ioutil.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
47+
if err := os.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
4948
t.Fatal(err)
5049
}
5150

@@ -55,7 +54,7 @@ func TestCompareModified(t *testing.T) {
5554
}
5655

5756
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
58-
if err := ioutil.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
57+
if err := os.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
5958
t.Fatal(err)
6059
}
6160

@@ -66,7 +65,7 @@ func TestCompareModified(t *testing.T) {
6665
}
6766

6867
// Overwrite the content in one of the files.
69-
if err := ioutil.WriteFile(tmpsubfile, []byte("modified content"), 0666); err != nil {
68+
if err := os.WriteFile(tmpsubfile, []byte("modified content"), 0666); err != nil {
7069
t.Fatal(err)
7170
}
7271

@@ -117,15 +116,15 @@ func TestCompareModified(t *testing.T) {
117116

118117
//gocyclo:ignore
119118
func TestCompareMissing(t *testing.T) {
120-
dir, err := ioutil.TempDir("", "test-compare-missing")
119+
dir, err := os.MkdirTemp("", "test-compare-missing")
121120
if err != nil {
122121
t.Fatal(err)
123122
}
124123
defer os.RemoveAll(dir)
125124

126125
// Create a bunch of objects.
127126
tmpfile := filepath.Join(dir, "tmpfile")
128-
if err := ioutil.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
127+
if err := os.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
129128
t.Fatal(err)
130129
}
131130

@@ -135,7 +134,7 @@ func TestCompareMissing(t *testing.T) {
135134
}
136135

137136
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
138-
if err := ioutil.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
137+
if err := os.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
139138
t.Fatal(err)
140139
}
141140

@@ -209,7 +208,7 @@ func TestCompareMissing(t *testing.T) {
209208

210209
//gocyclo:ignore
211210
func TestCompareExtra(t *testing.T) {
212-
dir, err := ioutil.TempDir("", "test-compare-extra")
211+
dir, err := os.MkdirTemp("", "test-compare-extra")
213212
if err != nil {
214213
t.Fatal(err)
215214
}
@@ -223,7 +222,7 @@ func TestCompareExtra(t *testing.T) {
223222

224223
// Create a bunch of objects.
225224
tmpfile := filepath.Join(dir, "tmpfile")
226-
if err := ioutil.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
225+
if err := os.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
227226
t.Fatal(err)
228227
}
229228

@@ -233,7 +232,7 @@ func TestCompareExtra(t *testing.T) {
233232
}
234233

235234
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
236-
if err := ioutil.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
235+
if err := os.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
237236
t.Fatal(err)
238237
}
239238

@@ -287,15 +286,15 @@ func TestCompareExtra(t *testing.T) {
287286
}
288287

289288
func TestCompareKeys(t *testing.T) {
290-
dir, err := ioutil.TempDir("", "test-compare-keys")
289+
dir, err := os.MkdirTemp("", "test-compare-keys")
291290
if err != nil {
292291
t.Fatal(err)
293292
}
294293
defer os.RemoveAll(dir)
295294

296295
// Create a bunch of objects.
297296
tmpfile := filepath.Join(dir, "tmpfile")
298-
if err := ioutil.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
297+
if err := os.WriteFile(tmpfile, []byte("some content here"), 0666); err != nil {
299298
t.Fatal(err)
300299
}
301300

@@ -305,7 +304,7 @@ func TestCompareKeys(t *testing.T) {
305304
}
306305

307306
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
308-
if err := ioutil.WriteFile(tmpsubfile, []byte("aaa"), 0666); err != nil {
307+
if err := os.WriteFile(tmpsubfile, []byte("aaa"), 0666); err != nil {
309308
t.Fatal(err)
310309
}
311310

@@ -316,7 +315,7 @@ func TestCompareKeys(t *testing.T) {
316315
}
317316

318317
// Overwrite the content in one of the files, but without changing the size.
319-
if err := ioutil.WriteFile(tmpsubfile, []byte("bbb"), 0666); err != nil {
318+
if err := os.WriteFile(tmpsubfile, []byte("bbb"), 0666); err != nil {
320319
t.Fatal(err)
321320
}
322321

@@ -343,15 +342,15 @@ func TestCompareKeys(t *testing.T) {
343342

344343
//gocyclo:ignore
345344
func TestTarCompare(t *testing.T) {
346-
dir, err := ioutil.TempDir("", "test-compare-tar")
345+
dir, err := os.MkdirTemp("", "test-compare-tar")
347346
if err != nil {
348347
t.Fatal(err)
349348
}
350349
defer os.RemoveAll(dir)
351350

352351
// Create a bunch of objects.
353352
tmpfile := filepath.Join(dir, "tmpfile")
354-
if err := ioutil.WriteFile(tmpfile, []byte("some content"), 0644); err != nil {
353+
if err := os.WriteFile(tmpfile, []byte("some content"), 0644); err != nil {
355354
t.Fatal(err)
356355
}
357356

@@ -361,7 +360,7 @@ func TestTarCompare(t *testing.T) {
361360
}
362361

363362
tmpsubfile := filepath.Join(tmpdir, "anotherfile")
364-
if err := ioutil.WriteFile(tmpsubfile, []byte("aaa"), 0644); err != nil {
363+
if err := os.WriteFile(tmpsubfile, []byte("aaa"), 0644); err != nil {
365364
t.Fatal(err)
366365
}
367366

@@ -395,7 +394,7 @@ func TestTarCompare(t *testing.T) {
395394
}
396395

397396
str := NewTarStreamer(bytes.NewBuffer(ts), nil, append(DefaultTarKeywords, "sha1"))
398-
if _, err = io.Copy(ioutil.Discard, str); err != nil && err != io.EOF {
397+
if _, err = io.Copy(io.Discard, str); err != nil && err != io.EOF {
399398
t.Fatal(err)
400399
}
401400
if err = str.Close(); err != nil {

fseval_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package mtree
22

33
import (
44
"encoding/json"
5-
"io/ioutil"
65
"os"
76
"path/filepath"
87
"testing"
@@ -73,15 +72,15 @@ func (fs *MockFsEval) KeywordFunc(fn KeywordFunc) KeywordFunc {
7372

7473
//gocyclo:ignore
7574
func TestCheckFsEval(t *testing.T) {
76-
dir, err := ioutil.TempDir("", "test-check-fs-eval")
75+
dir, err := os.MkdirTemp("", "test-check-fs-eval")
7776
if err != nil {
7877
t.Fatal(err)
7978
}
8079
defer os.RemoveAll(dir) // clean up
8180

8281
content := []byte("If you hide your ignorance, no one will hit you and you'll never learn.")
8382
tmpfn := filepath.Join(dir, "tmpfile")
84-
if err := ioutil.WriteFile(tmpfn, content, 0451); err != nil {
83+
if err := os.WriteFile(tmpfn, content, 0451); err != nil {
8584
t.Fatal(err)
8685
}
8786

keywordfunc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
"github.com/vbatts/go-mtree/pkg/govis"
1515

16-
//lint:ignore SA1019 yes ripemd160 is deprecated, but this is for mtree compatibility
16+
//nolint:staticcheck // SA1019 yes ripemd160 is deprecated, but this is for mtree compatibility
1717
"golang.org/x/crypto/ripemd160"
1818
)
1919

0 commit comments

Comments
 (0)