From 1c5247ce13bc4a7dd03e63ed0142d81bd5826ade Mon Sep 17 00:00:00 2001 From: Avi Deitcher Date: Thu, 19 Sep 2024 20:11:12 +0300 Subject: [PATCH] bump go version, add linter fixes (#257) Signed-off-by: Avi Deitcher --- .github/workflows/ci.yaml | 4 ++-- .golangci.yml | 5 ++++- Makefile | 2 +- disk/disk_test.go | 12 ++++++------ diskfs_test.go | 4 ++-- filesystem/fat32/fat32_test.go | 12 ++++++------ filesystem/iso9660/iso9660_test.go | 10 +++++----- filesystem/squashfs/compressor.go | 2 +- filesystem/squashfs/squashfs_test.go | 8 ++++---- go.mod | 2 +- partition/mbr/partition.go | 2 +- partition/partition_test.go | 4 ++-- 12 files changed, 35 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 484e20d0..b536eacc 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -38,9 +38,9 @@ jobs: steps: - name: checkout uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v5 with: - go-version: ^1.21 + go-version-file: 'go.mod' - run: go build env: GOOS: ${{ matrix.target.os }} diff --git a/.golangci.yml b/.golangci.yml index 5434216b..ea972134 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,6 +16,9 @@ linters-settings: nolintlint: require-explanation: true require-specific: true + gosec: + excludes: + - G115 linters: disable-all: true @@ -24,7 +27,7 @@ linters: - dogsled - dupl - errcheck - - exportloopref + - copyloopvar - exhaustive - gocritic - gofmt diff --git a/Makefile b/Makefile index 40325898..da1d3500 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ GOENV ?= GO111MODULE=on CGO_ENABLED=0 GO_FILES ?= $(shell $(GOENV) go list ./...) GOBIN ?= $(shell go env GOPATH)/bin LINTER ?= $(GOBIN)/golangci-lint -LINTER_VERSION ?= v1.59.0 +LINTER_VERSION ?= v1.61.0 # BUILDARCH is the host architecture # ARCH is the target architecture diff --git a/disk/disk_test.go b/disk/disk_test.go index 990be177..7bb2ce4c 100644 --- a/disk/disk_test.go +++ b/disk/disk_test.go @@ -210,9 +210,9 @@ func TestWritePartitionContents(t *testing.T) { {"no table, write to partition -1", nil, -1, fmt.Errorf("cannot write contents of a partition on a disk without a partition table")}, {"good table, write to partition 1", table, 1, nil}, } - for _, tt := range tests { + for _, t2 := range tests { // so that closures do not cause an issue - tt := tt + tt := t2 t.Run(tt.name, func(t *testing.T) { f, err := tmpDisk("") if err != nil { @@ -292,9 +292,9 @@ func TestReadPartitionContents(t *testing.T) { {"good table, partition greater than max", table, 5, fmt.Errorf("cannot read contents of partition %d which is greater than max partition %d", 5, 1)}, {"good table, good partition 1", table, 1, nil}, } - for _, tt := range tests { + for _, t2 := range tests { // so that closure does not cause issues - tt := tt + tt := t2 t.Run(tt.name, func(t *testing.T) { f, err := tmpDisk("../partition/gpt/testdata/gpt.img") if err != nil { @@ -366,8 +366,8 @@ func TestReadPartitionContents(t *testing.T) { {"valid table partition 5", table, 5, fmt.Errorf("cannot read contents of partition %d which is greater than max partition %d", 5, 1)}, {"valid table partition 1", table, 1, nil}, } - for _, tt := range tests { - tt := tt + for _, t2 := range tests { + tt := t2 t.Run(tt.name, func(t *testing.T) { f, err := tmpDisk("../partition/mbr/testdata/mbr.img") if err != nil { diff --git a/diskfs_test.go b/diskfs_test.go index 6e772046..314be098 100644 --- a/diskfs_test.go +++ b/diskfs_test.go @@ -209,8 +209,8 @@ func TestCreate(t *testing.T) { {"10MB with 2048 sector size", "disk", 10 * oneMB, diskfs.Raw, diskfs.SectorSize4k, &disk.Disk{LogicalBlocksize: 4096, PhysicalBlocksize: 4096, Size: 10 * oneMB, Type: disk.File}, nil}, } - for i, tt := range tests { - tt := tt + for i, t2 := range tests { + tt := t2 t.Run(tt.name, func(t *testing.T) { var filename string if tt.path != "" { diff --git a/filesystem/fat32/fat32_test.go b/filesystem/fat32/fat32_test.go index 1bc189e0..83818e4b 100644 --- a/filesystem/fat32/fat32_test.go +++ b/filesystem/fat32/fat32_test.go @@ -193,8 +193,8 @@ func TestFat32Create(t *testing.T) { } //nolint:thelper // this is not a helper function runTest := func(t *testing.T, pre, post int64) { - for _, tt := range tests { - tt := tt + for _, t2 := range tests { + tt := t2 t.Run(fmt.Sprintf("blocksize %d filesize %d", tt.blocksize, tt.filesize), func(t *testing.T) { // get a temporary working file f, err := tmpFat32(false, pre, post) @@ -245,8 +245,8 @@ func TestFat32Read(t *testing.T) { } //nolint:thelper // this is not a helper function runTest := func(t *testing.T, pre, post int64) { - for _, tt := range tests { - tt := tt + for _, t2 := range tests { + tt := t2 t.Run(fmt.Sprintf("blocksize %d filesize %d bytechange %d", tt.filesize, tt.blocksize, tt.bytechange), func(t *testing.T) { // get a temporary working file f, err := tmpFat32(true, pre, post) @@ -455,8 +455,8 @@ func TestFat32OpenFile(t *testing.T) { {"/CORTO1.TXT", os.O_APPEND, true, "More", "", fmt.Errorf("cannot write to file opened read-only")}, {"/CORTO1.TXT", os.O_APPEND | os.O_RDWR, true, "More", "Moremos un archivo corto\n", nil}, } - for _, tt := range tests { - tt := tt + for _, t2 := range tests { + tt := t2 t.Run(fmt.Sprintf("path %s mode %v beginning %v", tt.path, tt.mode, tt.beginning), func(t *testing.T) { header := fmt.Sprintf("OpenFile(%s, %s, %t)", tt.path, getOpenMode(tt.mode), tt.beginning) // get a temporary working file diff --git a/filesystem/iso9660/iso9660_test.go b/filesystem/iso9660/iso9660_test.go index 601dba86..a0b16338 100644 --- a/filesystem/iso9660/iso9660_test.go +++ b/filesystem/iso9660/iso9660_test.go @@ -14,7 +14,7 @@ import ( "strings" "testing" - "github.com/diskfs/go-diskfs" + diskfs "github.com/diskfs/go-diskfs" "github.com/diskfs/go-diskfs/disk" "github.com/diskfs/go-diskfs/filesystem" "github.com/diskfs/go-diskfs/filesystem/iso9660" @@ -174,8 +174,8 @@ func TestIso9660Create(t *testing.T) { {2048, 10000000, &iso9660.FileSystem{}, nil, testDir}, {2048, 10000000, &iso9660.FileSystem{}, nil, ""}, } - for _, tt := range tests { - tt := tt + for _, t2 := range tests { + tt := t2 t.Run(fmt.Sprintf("blocksize %d filesize %d", tt.blocksize, tt.filesize), func(t *testing.T) { // create the filesystem f, err := tmpIso9660File() @@ -214,8 +214,8 @@ func TestISO9660Read(t *testing.T) { {512, iso9660.MaxBlocks*2048 + 10000, -1, nil, fmt.Errorf("blocksize for ISO9660 must be")}, {2048, 10000000, -1, &iso9660.FileSystem{}, nil}, } - for _, tt := range tests { - tt := tt + for _, t2 := range tests { + tt := t2 t.Run(fmt.Sprintf("blocksize %d filesize %d", tt.blocksize, tt.filesize), func(t *testing.T) { // get a temporary working file f, err := os.Open(iso9660.ISO9660File) diff --git a/filesystem/squashfs/compressor.go b/filesystem/squashfs/compressor.go index 173edabf..1c95ff10 100644 --- a/filesystem/squashfs/compressor.go +++ b/filesystem/squashfs/compressor.go @@ -8,7 +8,7 @@ import ( "io" "github.com/klauspost/compress/zstd" - "github.com/pierrec/lz4/v4" + lz4 "github.com/pierrec/lz4/v4" "github.com/ulikunitz/xz" "github.com/ulikunitz/xz/lzma" ) diff --git a/filesystem/squashfs/squashfs_test.go b/filesystem/squashfs/squashfs_test.go index 236d98e6..b58b2174 100644 --- a/filesystem/squashfs/squashfs_test.go +++ b/filesystem/squashfs/squashfs_test.go @@ -349,8 +349,8 @@ func TestSquashfsRead(t *testing.T) { {4097, squashfs.GB * squashfs.GB, -1, nil, fmt.Errorf("blocksize %d is not a power of 2", 4097)}, {4096, 10000000, -1, &squashfs.FileSystem{}, nil}, } - for i, tt := range tests { - tt := tt + for i, t2 := range tests { + tt := t2 t.Run(fmt.Sprintf("blocksize %d filesize %d bytechange %d", tt.blocksize, tt.filesize, tt.bytechange), func(t *testing.T) { // get a temporary working file f, err := os.Open(squashfs.Squashfsfile) @@ -641,8 +641,8 @@ func TestSquashfsCreate(t *testing.T) { {4097, squashfs.GB * squashfs.GB, nil, fmt.Errorf("blocksize %d is not a power of 2", 4097)}, {4096, 10000000, &squashfs.FileSystem{}, nil}, } - for _, tt := range tests { - tt := tt + for _, t2 := range tests { + tt := t2 t.Run(fmt.Sprintf("blocksize %d filesize %d", tt.blocksize, tt.filesize), func(t *testing.T) { // create the filesystem f, err := tmpSquashfsFile() diff --git a/go.mod b/go.mod index c3fd0694..45c1ecd0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/diskfs/go-diskfs -go 1.21 +go 1.23 require ( github.com/djherbis/times v1.6.0 diff --git a/partition/mbr/partition.go b/partition/mbr/partition.go index a63428da..18ecaaf6 100644 --- a/partition/mbr/partition.go +++ b/partition/mbr/partition.go @@ -115,7 +115,7 @@ func partitionFromBytes(b []byte, logicalSectorSize, physicalSectorSize int) (*P EndSector: b[6], EndCylinder: b[7], Start: binary.LittleEndian.Uint32(b[8:12]), - Size: binary.LittleEndian.Uint32(b[12:16]), + Size: binary.LittleEndian.Uint32(b[12:16]), //nolint:gosec // we already checked the length above logicalSectorSize: logicalSectorSize, physicalSectorSize: physicalSectorSize, }, nil diff --git a/partition/partition_test.go b/partition/partition_test.go index 95c0a706..ca564721 100644 --- a/partition/partition_test.go +++ b/partition/partition_test.go @@ -24,8 +24,8 @@ func TestRead(t *testing.T) { {"./gpt/testdata/gpt.img", "gpt", nil}, {"", "", fmt.Errorf("unknown disk partition type")}, } - for _, tt := range tests { - tt := tt + for _, t2 := range tests { + tt := t2 t.Run(tt.tableType, func(t *testing.T) { // create a blank file if we did not provide a path to a test file var f *os.File