From 3e6880846e1a78fc1e1d2d55f79ee33f44860015 Mon Sep 17 00:00:00 2001 From: Avi Deitcher Date: Wed, 13 Dec 2023 04:29:36 -0800 Subject: [PATCH] Update golangci lint 155 (#196) * bump golangci-lint to 1.55 and fix linting errors that come up because of it Signed-off-by: Avi Deitcher * for Actions CI, use golang 1.21 Signed-off-by: Avi Deitcher --------- Signed-off-by: Avi Deitcher --- .github/workflows/ci.yaml | 4 +- .golangci.yml | 4 -- Makefile | 2 +- diskfs.go | 2 +- filesystem/fat32/file_test.go | 2 + filesystem/iso9660/directoryentry.go | 3 +- filesystem/iso9660/file.go | 2 +- filesystem/squashfs/common_internal_test.go | 2 + filesystem/squashfs/compressor.go | 2 + filesystem/squashfs/file.go | 2 + filesystem/squashfs/finalize.go | 2 +- filesystem/squashfs/inode_internal_test.go | 9 ++++- filesystem/squashfs/squashfs.go | 2 +- filesystem/squashfs/squashfs_test.go | 1 + partition/gpt/table_test.go | 42 ++++++++++----------- partition/mbr/table.go | 8 ++++ testhelper/fileimpl.go | 2 + 17 files changed, 56 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2e422b2e..b79fb23e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -39,7 +39,7 @@ jobs: uses: actions/checkout@v2 - uses: actions/setup-go@v2 with: - go-version: ^1.16 + go-version: ^1.21 - run: go build env: GOOS: ${{ matrix.target.os }} @@ -55,7 +55,7 @@ jobs: uses: actions/checkout@v2 - uses: actions/setup-go@v2 with: - go-version: ^1.16 + go-version: ^1.21 - run: go build - name: vet if: matrix.os != 'windows-latest' diff --git a/.golangci.yml b/.golangci.yml index 2ec29ec2..5434216b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,7 +21,6 @@ linters: disable-all: true enable: - bodyclose - - depguard - dogsled - dupl - errcheck @@ -49,9 +48,6 @@ linters: - unconvert - unparam - whitespace - # - wsl # лишние пустые строки и т.д., чистый стиль - # - goconst # проверка на наличие переменных, которых следовало бы вынести в const - # - gomnd # поиск всяких "магических" чисел, переменных run: issues-exit-code: 1 diff --git a/Makefile b/Makefile index 7aacf67c..24bbc2f4 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.51.2 +LINTER_VERSION ?= v1.55.2 # BUILDARCH is the host architecture # ARCH is the target architecture diff --git a/diskfs.go b/diskfs.go index f2e39cf2..f910e45b 100644 --- a/diskfs.go +++ b/diskfs.go @@ -335,7 +335,7 @@ func Open(device string, opts ...OpenOpt) (*disk.Disk, error) { // Create a Disk from a path to a device // Should pass a path to a block device e.g. /dev/sda or a path to a file /tmp/foo.img // The provided device must not exist at the time you call Create() -func Create(device string, size int64, format Format, sectorSize SectorSize) (*disk.Disk, error) { +func Create(device string, size int64, _ Format, sectorSize SectorSize) (*disk.Disk, error) { if device == "" { return nil, errors.New("must pass device name") } diff --git a/filesystem/fat32/file_test.go b/filesystem/fat32/file_test.go index 43ac9e98..37ac0fb4 100644 --- a/filesystem/fat32/file_test.go +++ b/filesystem/fat32/file_test.go @@ -2,10 +2,12 @@ package fat32_test import "testing" +//nolint:unused,revive // keep for future when we implement it and will need t func TestFileRead(t *testing.T) { } +//nolint:unused,revive // keep for future when we implement it and will need t func TestFileWrite(t *testing.T) { } diff --git a/filesystem/iso9660/directoryentry.go b/filesystem/iso9660/directoryentry.go index 43f03518..d9877673 100644 --- a/filesystem/iso9660/directoryentry.go +++ b/filesystem/iso9660/directoryentry.go @@ -189,9 +189,8 @@ func dirEntryExtensionsToBytes(extensions []directoryEntrySystemUseExtension, ma } b = append(b, ce.Bytes()...) break - } else { - b = append(b, b2...) } + b = append(b, b2...) } ret = append(ret, b) if len(continuedBytes) > 0 { diff --git a/filesystem/iso9660/file.go b/filesystem/iso9660/file.go index 7d6bb519..83dff8b7 100644 --- a/filesystem/iso9660/file.go +++ b/filesystem/iso9660/file.go @@ -64,7 +64,7 @@ func (fl *File) Read(b []byte) (int, error) { // Write writes len(b) bytes to the File. // // you cannot write to an iso, so this returns an error -func (fl *File) Write(p []byte) (int, error) { +func (fl *File) Write(_ []byte) (int, error) { return 0, fmt.Errorf("cannot write to a read-only iso filesystem") } diff --git a/filesystem/squashfs/common_internal_test.go b/filesystem/squashfs/common_internal_test.go index eb02313d..9c4ce8a7 100644 --- a/filesystem/squashfs/common_internal_test.go +++ b/filesystem/squashfs/common_internal_test.go @@ -18,6 +18,8 @@ func (c *testCompressorAddBytes) decompress(b []byte) ([]byte, error) { } return append(b, c.b...), nil } + +//nolint:unused,revive // it is important to implement the interface func (c *testCompressorAddBytes) loadOptions(b []byte) error { return nil } diff --git a/filesystem/squashfs/compressor.go b/filesystem/squashfs/compressor.go index b608d551..42c0819d 100644 --- a/filesystem/squashfs/compressor.go +++ b/filesystem/squashfs/compressor.go @@ -51,6 +51,8 @@ func (c *CompressorLzma) decompress(in []byte) ([]byte, error) { } return p, nil } + +//nolint:unused,revive // it is important to implement the interface func (c *CompressorLzma) loadOptions(b []byte) error { // lzma has no supported optiosn return nil diff --git a/filesystem/squashfs/file.go b/filesystem/squashfs/file.go index 93487dd3..d1466046 100644 --- a/filesystem/squashfs/file.go +++ b/filesystem/squashfs/file.go @@ -111,6 +111,8 @@ func (fl *File) Read(b []byte) (int, error) { // Write writes len(b) bytes to the File. // // you cannot write to a finished squashfs, so this returns an error +// +//nolint:unused,revive // but it is important to implement the interface func (fl *File) Write(p []byte) (int, error) { return 0, fmt.Errorf("cannot write to a read-only squashfs filesystem") } diff --git a/filesystem/squashfs/finalize.go b/filesystem/squashfs/finalize.go index f85c28fe..1b5e8e92 100644 --- a/filesystem/squashfs/finalize.go +++ b/filesystem/squashfs/finalize.go @@ -750,7 +750,7 @@ func writeDirectories(dirs []*finalizeFileInfo, f util.File, compressor Compress // writeFragmentTable write the fragment table // -//nolint:unparam // this does not use fragmentBlocksStart yet, but only because we have not yet added support +//nolint:unparam,unused,revive // this does not use fragmentBlocksStart yet, but only because we have not yet added support func writeFragmentTable(fragmentBlocks []fragmentBlock, fragmentBlocksStart int64, f util.File, compressor Compressor, location int64) (fragmentsWritten int, finalLocation uint64, err error) { // now write the actual fragment table entries var ( diff --git a/filesystem/squashfs/inode_internal_test.go b/filesystem/squashfs/inode_internal_test.go index 162a57b4..75bb1aaf 100644 --- a/filesystem/squashfs/inode_internal_test.go +++ b/filesystem/squashfs/inode_internal_test.go @@ -22,7 +22,8 @@ type inodeTestImpl struct { func (i *inodeTestImpl) toBytes() []byte { return nil } -func (i *inodeTestImpl) equal(o inode) bool { + +func (i *inodeTestImpl) equal(_ inode) bool { return false } func (i *inodeTestImpl) size() int64 { @@ -191,6 +192,7 @@ func TestBasicDirectory(t *testing.T) { }) } +//nolint:unused,revive // keep for future when we implement it and will need t func TestExtendedDirectory(t *testing.T) { // do some day when we have good raw data @@ -381,6 +383,7 @@ func TestBasicSymlink(t *testing.T) { }) } +//nolint:unused,revive // keep for future when we implement it and will need t func TestExtendedSymlink(t *testing.T) { // when we have more data with which to work @@ -389,6 +392,7 @@ func TestExtendedSymlink(t *testing.T) { // func parseExtendedSymlink(b []byte) (*extendedSymlink, error) { } +//nolint:unused,revive // keep for future when we implement it and will need t func TestBasicDevice(t *testing.T) { // when we have more data with which to work @@ -397,6 +401,7 @@ func TestBasicDevice(t *testing.T) { // func parseBasicDevice(b []byte) (*basicDevice, error) { } +//nolint:unused,revive // keep for future when we implement it and will need t func TestExtendedDevice(t *testing.T) { // when we have more data with which to work @@ -406,6 +411,7 @@ func TestExtendedDevice(t *testing.T) { } +//nolint:unused,revive // keep for future when we implement it and will need t func TestBasicIPC(t *testing.T) { // when we have more data with which to work @@ -414,6 +420,7 @@ func TestBasicIPC(t *testing.T) { // func parseBasicIPC(b []byte) (*basicIPC, error) { } +//nolint:unused,revive // keep for future when we implement it and will need t func TestExtendedIPC(t *testing.T) { // when we have more data with which to work diff --git a/filesystem/squashfs/squashfs.go b/filesystem/squashfs/squashfs.go index 19f88f11..d67c61ca 100644 --- a/filesystem/squashfs/squashfs.go +++ b/filesystem/squashfs/squashfs.go @@ -704,7 +704,7 @@ func readXattrsTable(s *superblock, file util.File, c Compressor) (*xAttrTable, return parseXattrsTable(xAttrData, bIndex, s.idTableStart, c) } -//nolint:unparam // this does not use offset or compressor yet, but only because we have not yet added support +//nolint:unparam,unused,revive // this does not use offset or compressor yet, but only because we have not yet added support func parseXattrsTable(bUIDXattr, bIndex []byte, offset uint64, c Compressor) (*xAttrTable, error) { // create the ID list var ( diff --git a/filesystem/squashfs/squashfs_test.go b/filesystem/squashfs/squashfs_test.go index e254672d..f27f15cf 100644 --- a/filesystem/squashfs/squashfs_test.go +++ b/filesystem/squashfs/squashfs_test.go @@ -379,6 +379,7 @@ func TestSquashfsReadDirXattr(t *testing.T) { } } +//nolint:unused,revive // keep for future when we implement it and will need t func TestFinalize(t *testing.T) { } diff --git a/partition/gpt/table_test.go b/partition/gpt/table_test.go index c6eb4340..9a6ca3c2 100644 --- a/partition/gpt/table_test.go +++ b/partition/gpt/table_test.go @@ -13,7 +13,7 @@ import ( "strings" "testing" - . "github.com/diskfs/go-diskfs/partition/gpt" + "github.com/diskfs/go-diskfs/partition/gpt" "github.com/diskfs/go-diskfs/testhelper" ) @@ -94,7 +94,7 @@ func compareGPTBytes(b1, b2 []byte) bool { func TestTableType(t *testing.T) { expected := "gpt" - table := GetValidTable() + table := gpt.GetValidTable() tableType := table.Type() if tableType != expected { t.Errorf("Type() returned unexpected table type, actual %s expected %s", tableType, expected) @@ -109,7 +109,7 @@ func TestTableRead(t *testing.T) { return 0, errors.New(expected) }, } - table, err := Read(f, 512, 512) + table, err := gpt.Read(f, 512, 512) if table != nil { t.Errorf("returned table instead of nil") } @@ -128,7 +128,7 @@ func TestTableRead(t *testing.T) { return size, nil }, } - table, err := Read(f, 512, 512) + table, err := gpt.Read(f, 512, 512) if table != nil { t.Errorf("returned table instead of nil") } @@ -144,14 +144,14 @@ func TestTableRead(t *testing.T) { if err != nil { t.Fatalf("error opening file %s to read: %v", gptFile, err) } - table, err := Read(f, 512, 512) + table, err := gpt.Read(f, 512, 512) if table == nil { t.Errorf("returned nil instead of table") } if err != nil { t.Errorf("returned error %v instead of nil", err) } - expected := GetValidTable() + expected := gpt.GetValidTable() if table == nil || !table.Equal(expected) { t.Errorf("actual table was %v instead of expected %v", table, expected) } @@ -161,7 +161,7 @@ func TestTableRead(t *testing.T) { //nolint:gocyclo // we really do not care about the cyclomatic complexity of a test function. Maybe someday we will improve it. func TestTableWrite(t *testing.T) { t.Run("error writing file", func(t *testing.T) { - table := GetValidTable() + table := gpt.GetValidTable() expected := "error writing protective MBR to disk" f := &testhelper.FileImpl{ Writer: func(b []byte, offset int64) (int, error) { @@ -177,7 +177,7 @@ func TestTableWrite(t *testing.T) { } }) t.Run("insufficient data written", func(t *testing.T) { - table := GetValidTable() + table := gpt.GetValidTable() var size int f := &testhelper.FileImpl{ Writer: func(b []byte, offset int64) (int, error) { @@ -195,17 +195,17 @@ func TestTableWrite(t *testing.T) { } }) t.Run("successful write", func(t *testing.T) { - table := GetValidTable() - gpt, err := os.Open(gptFile) + table := gpt.GetValidTable() + gptFileRef, err := os.Open(gptFile) if err != nil { t.Fatalf("unable to open gpt file: %v", err) } - defer gpt.Close() + defer gptFileRef.Close() if err != nil { t.Fatalf("error opening file %s: %v", gptFile, err) } firstBytes := make([]byte, gptSize+512*2) - firstRead, err := gpt.ReadAt(firstBytes, 0) + firstRead, err := gptFileRef.ReadAt(firstBytes, 0) if err != nil { t.Fatalf("error reading primary header from file %s: %v", gptFile, err) } @@ -270,9 +270,9 @@ func TestTableWrite(t *testing.T) { // make it a 5MB partition partitionEnd := uint64(5*1024*1024/sectorSize) + partitionStart name := "EFI System Tester" - table := &Table{ - Partitions: []*Partition{ - {Start: partitionStart, End: partitionEnd, Type: EFISystemPartition, Name: name}, + table := &gpt.Table{ + Partitions: []*gpt.Partition{ + {Start: partitionStart, End: partitionEnd, Type: gpt.EFISystemPartition, Name: name}, }, LogicalSectorSize: sectorSize, ProtectiveMBR: true, @@ -322,8 +322,8 @@ func TestTableWrite(t *testing.T) { switch { case len(partitionType) < 2: t.Errorf("unable to retrieve partition type %v", partitionType) - case partitionType[1] != string(EFISystemPartition): - t.Errorf("Mismatched partition type, actual %s expected %s", partitionType[1], EFISystemPartition) + case partitionType[1] != string(gpt.EFISystemPartition): + t.Errorf("Mismatched partition type, actual %s expected %s", partitionType[1], gpt.EFISystemPartition) } switch { @@ -357,7 +357,7 @@ func TestTableWrite(t *testing.T) { }) } func TestGetPartitionSize(t *testing.T) { - table := GetValidTable() + table := gpt.GetValidTable() request := 0 size := table.Partitions[request].GetSize() expected := int64(table.Partitions[request].Size) @@ -366,7 +366,7 @@ func TestGetPartitionSize(t *testing.T) { } } func TestGetPartitionStart(t *testing.T) { - table := GetValidTable() + table := gpt.GetValidTable() maxPart := len(table.Partitions) request := maxPart - 1 start := table.Partitions[request].GetStart() @@ -376,7 +376,7 @@ func TestGetPartitionStart(t *testing.T) { } } func TestReadPartitionContents(t *testing.T) { - table := GetValidTable() + table := gpt.GetValidTable() maxPart := len(table.Partitions) request := maxPart - 1 var b bytes.Buffer @@ -405,7 +405,7 @@ func TestReadPartitionContents(t *testing.T) { } } func TestWritePartitionContents(t *testing.T) { - table := GetValidTable() + table := gpt.GetValidTable() request := 0 size := table.Partitions[request].Size b := make([]byte, size) diff --git a/partition/mbr/table.go b/partition/mbr/table.go index d19554c5..6d0ed1d0 100644 --- a/partition/mbr/table.go +++ b/partition/mbr/table.go @@ -120,6 +120,8 @@ func (t *Table) Type() string { } // Read read a partition table from a disk, given the logical block size and physical block size +// +//nolint:unused,revive // not used in MBR, but it is important to implement the interface func Read(f util.File, logicalBlockSize, physicalBlockSize int) (*Table, error) { // read the data off of the disk b := make([]byte, mbrSize) @@ -155,6 +157,8 @@ func (t *Table) toBytes() []byte { // Write writes a given MBR Table to disk. // Must be passed the util.File to write to and the size of the disk +// +//nolint:unused,revive // not used in MBR, but it is important to implement the interface func (t *Table) Write(f util.File, size int64) error { b := t.toBytes() @@ -178,11 +182,15 @@ func (t *Table) GetPartitions() []part.Partition { } // Verify will attempt to evaluate the headers +// +//nolint:unused,revive // not used in MBR, but it is important to implement the interface func (t *Table) Verify(f util.File, diskSize uint64) error { return nil } // Repair will attempt to repair a broken Master Boot Record +// +//nolint:unused,revive // not used in MBR, but it is important to implement the interface func (t *Table) Repair(diskSize uint64) error { return nil } diff --git a/testhelper/fileimpl.go b/testhelper/fileimpl.go index 995a4f01..b593aeda 100644 --- a/testhelper/fileimpl.go +++ b/testhelper/fileimpl.go @@ -23,6 +23,8 @@ func (f *FileImpl) WriteAt(b []byte, offset int64) (int, error) { } // Seek seek a particular offset - does not actually work +// +//nolint:unused,revive // to implement the interface func (f *FileImpl) Seek(offset int64, whence int) (int64, error) { return 0, fmt.Errorf("FileImpl does not implement Seek()") }