Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*.go: update to golangci-lint, and fix everything #196

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
go-version: ${{ matrix.go }}

- name: Build
run: make
run: make build

- name: Test
- name: Validation
run: make validation

- name: Build.Arches
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: lint

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.21']
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}

- name: Install tools
run: make install.tools

- name: Test
run: make lint
18 changes: 6 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GO_VER := go1.14
default: build validation

.PHONY: validation
validation: .test .lint .vet .cli.test
validation: .test .vet .cli.test

.PHONY: validation.tags
validation.tags: .test.tags .vet.tags .cli.test .staticcheck
Expand Down Expand Up @@ -50,11 +50,7 @@ lint: .lint
CLEAN_FILES += .lint

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

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

install.tools:
@go install -u github.com/fatih/color@latest ; \
go install -u github.com/fzipp/gocyclo/cmd/gocyclo@latest ; \
go install -u honnef.co/go/tools/cmd/staticcheck@latest ; \
if [ "$(findstring $(GO_VER),$(shell go version))" != "" ] ; then \
go get -u golang.org/x/lint/golint ;\
fi
@go install github.com/fatih/color@latest ; \
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest ; \
go install honnef.co/go/tools/cmd/staticcheck@latest ; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

./bin:
mkdir -p $@
Expand Down
13 changes: 6 additions & 7 deletions check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mtree

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -31,14 +30,14 @@ func TestCheck(t *testing.T) {
// only check again for size and sha1, and ignore time, and ensure it passes
func TestCheckKeywords(t *testing.T) {
content := []byte("I know half of you half as well as I ought to")
dir, err := ioutil.TempDir("", "test-check-keywords")
dir, err := os.MkdirTemp("", "test-check-keywords")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir) // clean up

tmpfn := filepath.Join(dir, "tmpfile")
if err := ioutil.WriteFile(tmpfn, content, 0666); err != nil {
if err := os.WriteFile(tmpfn, content, 0666); err != nil {
t.Fatal(err)
}

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

// https://github.com/vbatts/go-mtree/issues/8
func TestTimeComparison(t *testing.T) {
dir, err := ioutil.TempDir("", "test-time.")
dir, err := os.MkdirTemp("", "test-time.")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -165,7 +164,7 @@ func TestTimeComparison(t *testing.T) {
}

func TestTarTime(t *testing.T) {
dir, err := ioutil.TempDir("", "test-tar-time.")
dir, err := os.MkdirTemp("", "test-tar-time.")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -219,7 +218,7 @@ func TestTarTime(t *testing.T) {
}

func TestIgnoreComments(t *testing.T) {
dir, err := ioutil.TempDir("", "test-comments.")
dir, err := os.MkdirTemp("", "test-comments.")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -288,7 +287,7 @@ func TestIgnoreComments(t *testing.T) {
}

func TestCheckNeedsEncoding(t *testing.T) {
dir, err := ioutil.TempDir("", "test-needs-encoding")
dir, err := os.MkdirTemp("", "test-needs-encoding")
if err != nil {
t.Fatal(err)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/gomtree/cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"strings"

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

if _, err := io.Copy(ioutil.Discard, ts); err != nil && err != io.EOF {
if _, err := io.Copy(io.Discard, ts); err != nil && err != io.EOF {
return err
}
if err := ts.Close(); err != nil {
Expand Down Expand Up @@ -344,8 +343,8 @@ func validateAction(c *cli.Context) error {
}

// output stateDh
stateDh.WriteTo(fh)
return nil
_, err = stateDh.WriteTo(fh)
return err
}

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

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

// This is a validation.
Expand Down
37 changes: 18 additions & 19 deletions compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -37,15 +36,15 @@ func TestCompare(t *testing.T) {

//gocyclo:ignore
func TestCompareModified(t *testing.T) {
dir, err := ioutil.TempDir("", "test-compare-modified")
dir, err := os.MkdirTemp("", "test-compare-modified")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)

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

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

tmpsubfile := filepath.Join(tmpdir, "anotherfile")
if err := ioutil.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
if err := os.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
t.Fatal(err)
}

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

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

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

//gocyclo:ignore
func TestCompareMissing(t *testing.T) {
dir, err := ioutil.TempDir("", "test-compare-missing")
dir, err := os.MkdirTemp("", "test-compare-missing")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)

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

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

tmpsubfile := filepath.Join(tmpdir, "anotherfile")
if err := ioutil.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
if err := os.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
t.Fatal(err)
}

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

//gocyclo:ignore
func TestCompareExtra(t *testing.T) {
dir, err := ioutil.TempDir("", "test-compare-extra")
dir, err := os.MkdirTemp("", "test-compare-extra")
if err != nil {
t.Fatal(err)
}
Expand All @@ -223,7 +222,7 @@ func TestCompareExtra(t *testing.T) {

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

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

tmpsubfile := filepath.Join(tmpdir, "anotherfile")
if err := ioutil.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
if err := os.WriteFile(tmpsubfile, []byte("some different content"), 0666); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -287,15 +286,15 @@ func TestCompareExtra(t *testing.T) {
}

func TestCompareKeys(t *testing.T) {
dir, err := ioutil.TempDir("", "test-compare-keys")
dir, err := os.MkdirTemp("", "test-compare-keys")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)

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

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

tmpsubfile := filepath.Join(tmpdir, "anotherfile")
if err := ioutil.WriteFile(tmpsubfile, []byte("aaa"), 0666); err != nil {
if err := os.WriteFile(tmpsubfile, []byte("aaa"), 0666); err != nil {
t.Fatal(err)
}

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

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

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

//gocyclo:ignore
func TestTarCompare(t *testing.T) {
dir, err := ioutil.TempDir("", "test-compare-tar")
dir, err := os.MkdirTemp("", "test-compare-tar")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)

// Create a bunch of objects.
tmpfile := filepath.Join(dir, "tmpfile")
if err := ioutil.WriteFile(tmpfile, []byte("some content"), 0644); err != nil {
if err := os.WriteFile(tmpfile, []byte("some content"), 0644); err != nil {
t.Fatal(err)
}

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

tmpsubfile := filepath.Join(tmpdir, "anotherfile")
if err := ioutil.WriteFile(tmpsubfile, []byte("aaa"), 0644); err != nil {
if err := os.WriteFile(tmpsubfile, []byte("aaa"), 0644); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -395,7 +394,7 @@ func TestTarCompare(t *testing.T) {
}

str := NewTarStreamer(bytes.NewBuffer(ts), nil, append(DefaultTarKeywords, "sha1"))
if _, err = io.Copy(ioutil.Discard, str); err != nil && err != io.EOF {
if _, err = io.Copy(io.Discard, str); err != nil && err != io.EOF {
t.Fatal(err)
}
if err = str.Close(); err != nil {
Expand Down
5 changes: 2 additions & 3 deletions fseval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mtree

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -73,15 +72,15 @@ func (fs *MockFsEval) KeywordFunc(fn KeywordFunc) KeywordFunc {

//gocyclo:ignore
func TestCheckFsEval(t *testing.T) {
dir, err := ioutil.TempDir("", "test-check-fs-eval")
dir, err := os.MkdirTemp("", "test-check-fs-eval")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir) // clean up

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

Expand Down
2 changes: 1 addition & 1 deletion keywordfunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

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

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

Expand Down
Loading