Skip to content

Commit

Permalink
Update golangci lint 155 (#196)
Browse files Browse the repository at this point in the history
* bump golangci-lint to 1.55 and fix linting errors that come up because of it

Signed-off-by: Avi Deitcher <[email protected]>

* for Actions CI, use golang 1.21

Signed-off-by: Avi Deitcher <[email protected]>

---------

Signed-off-by: Avi Deitcher <[email protected]>
  • Loading branch information
deitch authored Dec 13, 2023
1 parent 25d5b7e commit 3e68808
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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'
Expand Down
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
Expand Down Expand Up @@ -49,9 +48,6 @@ linters:
- unconvert
- unparam
- whitespace
# - wsl # лишние пустые строки и т.д., чистый стиль
# - goconst # проверка на наличие переменных, которых следовало бы вынести в const
# - gomnd # поиск всяких "магических" чисел, переменных

run:
issues-exit-code: 1
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion diskfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 2 additions & 0 deletions filesystem/fat32/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

}
3 changes: 1 addition & 2 deletions filesystem/iso9660/directoryentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion filesystem/iso9660/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 2 additions & 0 deletions filesystem/squashfs/common_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions filesystem/squashfs/compressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions filesystem/squashfs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion filesystem/squashfs/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
9 changes: 8 additions & 1 deletion filesystem/squashfs/inode_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion filesystem/squashfs/squashfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions filesystem/squashfs/squashfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

}
42 changes: 21 additions & 21 deletions partition/gpt/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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)
}
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions partition/mbr/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand All @@ -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
}
2 changes: 2 additions & 0 deletions testhelper/fileimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
}

0 comments on commit 3e68808

Please sign in to comment.