Skip to content

Commit 1f29536

Browse files
committed
switch to golangci-lint v2
Signed-off-by: Avi Deitcher <[email protected]>
1 parent 414258f commit 1f29536

32 files changed

+148
-120
lines changed

.github/workflows/ci.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ jobs:
5353
runs-on: ${{ matrix.os }}
5454
steps:
5555
- name: checkout
56-
uses: actions/checkout@v2
57-
- uses: actions/setup-go@v2
56+
uses: actions/checkout@v4
57+
- uses: actions/setup-go@v5
5858
with:
59-
go-version: ^1.21
59+
go-version: ^1.24
6060
- run: go build
6161
- name: vet
6262
if: matrix.os != 'windows-latest'

.golangci.yml

+49-33
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,72 @@
1-
linters-settings:
2-
errcheck:
3-
check-type-assertions: true
4-
goconst:
5-
min-len: 2
6-
min-occurrences: 3
7-
gocritic:
8-
enabled-tags:
9-
- diagnostic
10-
- experimental
11-
- opinionated
12-
- performance
13-
- style
14-
govet:
15-
check-shadowing: false
16-
nolintlint:
17-
require-explanation: true
18-
require-specific: true
19-
gosec:
20-
excludes:
21-
- G115
22-
1+
version: "2"
2+
run:
3+
issues-exit-code: 1
234
linters:
24-
disable-all: true
5+
default: none
256
enable:
267
- bodyclose
8+
- copyloopvar
279
- dogsled
2810
- dupl
2911
- errcheck
30-
- copyloopvar
3112
- exhaustive
3213
- gocritic
33-
- gofmt
34-
- goimports
3514
- gocyclo
3615
- gosec
37-
- gosimple
3816
- govet
3917
- ineffassign
4018
- misspell
41-
- nolintlint
4219
- nakedret
20+
- nolintlint
4321
- prealloc
4422
- predeclared
4523
- revive
4624
- staticcheck
47-
- stylecheck
4825
- thelper
4926
- tparallel
50-
- typecheck
5127
- unconvert
5228
- unparam
5329
- whitespace
54-
55-
run:
56-
issues-exit-code: 1
30+
settings:
31+
errcheck:
32+
check-type-assertions: true
33+
goconst:
34+
min-len: 2
35+
min-occurrences: 3
36+
gocritic:
37+
enabled-tags:
38+
- diagnostic
39+
- experimental
40+
- opinionated
41+
- performance
42+
- style
43+
gosec:
44+
excludes:
45+
- G115
46+
govet:
47+
disable:
48+
- shadow
49+
nolintlint:
50+
require-explanation: true
51+
require-specific: true
52+
exclusions:
53+
generated: lax
54+
presets:
55+
- comments
56+
- common-false-positives
57+
- legacy
58+
- std-error-handling
59+
paths:
60+
- third_party$
61+
- builtin$
62+
- examples$
63+
formatters:
64+
enable:
65+
- gofmt
66+
- goimports
67+
exclusions:
68+
generated: lax
69+
paths:
70+
- third_party$
71+
- builtin$
72+
- examples$

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ GOENV ?= GO111MODULE=on CGO_ENABLED=0
66
GO_FILES ?= $(shell $(GOENV) go list ./...)
77
GOBIN ?= $(shell go env GOPATH)/bin
88
LINTER ?= $(GOBIN)/golangci-lint
9-
LINTER_VERSION ?= v1.61.0
9+
LINTER_VERSION ?= v2.0.2
1010

1111
# BUILDARCH is the host architecture
1212
# ARCH is the target architecture

diskfs.go

+2
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,14 @@ func initDisk(b backend.Storage, sectorSize SectorSize) (*disk.Disk, error) {
128128
return nil, backend.ErrNotSuitable
129129
}
130130

131+
//nolint:revive // revive thinks we can drop the 'else' statement, but we need it to capture the size
131132
if size, err := getBlockDeviceSize(osFile); err != nil {
132133
return nil, fmt.Errorf("error getting block device %s size: %s", devInfo.Name(), err)
133134
} else {
134135
newDisk.Size = size
135136
}
136137

138+
//nolint:revive // revive thinks we can drop the 'else' statement, but we need it to capture the size
137139
if lblksize, pblksize, err = getSectorSizes(osFile); err != nil {
138140
return nil, fmt.Errorf("unable to get block sizes for device %s: %v", devInfo.Name(), err)
139141
} else {

examples/efi_create.go

+20-7
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ import (
1414
)
1515

1616
func CreateEfi(diskImg string) {
17-
1817
var (
19-
espSize int64 = 100 * 1024 * 1024 // 100 MB
20-
diskSize int64 = espSize + 4*1024*1024 // 104 MB
18+
espSize int64 = 100 * 1024 * 1024 // 100 MB
2119
blkSize int64 = 512
2220
partitionStart int64 = 2048
23-
partitionSectors int64 = espSize / blkSize
24-
partitionEnd int64 = partitionSectors - partitionStart + 1
21+
diskSize = espSize + 4*1024*1024 // 104 MB
22+
partitionSectors = espSize / blkSize
23+
partitionEnd = partitionSectors - partitionStart + 1
2524
)
2625

2726
// create a disk image
@@ -32,23 +31,37 @@ func CreateEfi(diskImg string) {
3231
// create a partition table
3332
table := &gpt.Table{
3433
Partitions: []*gpt.Partition{
35-
&gpt.Partition{Start: uint64(partitionStart), End: uint64(partitionEnd), Type: gpt.EFISystemPartition, Name: "EFI System"},
34+
{Start: uint64(partitionStart), End: uint64(partitionEnd), Type: gpt.EFISystemPartition, Name: "EFI System"},
3635
},
3736
}
3837
// apply the partition table
3938
err = disk.Partition(table)
39+
if err != nil {
40+
log.Panic(err)
41+
}
4042

4143
/*
4244
* create an ESP partition with some contents
4345
*/
4446
kernel, err := os.ReadFile("/some/kernel/file")
47+
if err != nil {
48+
log.Panic(err)
49+
}
4550

4651
spec := diskpkg.FilesystemSpec{Partition: 1, FSType: filesystem.TypeFat32}
4752
fs, err := disk.CreateFilesystem(spec)
53+
if err != nil {
54+
log.Panic(err)
55+
}
4856

4957
// make our directories
50-
err = fs.Mkdir("/EFI/BOOT")
58+
if err = fs.Mkdir("/EFI/BOOT"); err != nil {
59+
log.Panic(err)
60+
}
5161
rw, err := fs.OpenFile("/EFI/BOOT/BOOTX64.EFI", os.O_CREATE|os.O_RDWR)
62+
if err != nil {
63+
log.Panic(err)
64+
}
5265

5366
n, err := rw.Write(kernel)
5467
if err != nil {

examples/iso_info.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ func fileInfoFor(path string, fs filesystem.FileSystem) error {
4848
continue
4949
}
5050

51-
myFile := isoFile.(*iso9660.File)
51+
myFile, ok := isoFile.(*iso9660.File)
52+
if !ok {
53+
fmt.Printf("Failed to cast to iso9660.File for %s\n", fullPath)
54+
continue
55+
}
5256
fmt.Printf("%s\n Size: %d\n Location: %d\n\n", fullPath, file.Size(), myFile.Location())
5357
}
5458
return nil

examples/serve-image/main.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"flag"
5+
"fmt"
56
"log"
67
"net/http"
78
"os"
@@ -13,15 +14,10 @@ import (
1314
"github.com/diskfs/go-diskfs/filesystem/squashfs"
1415
)
1516

16-
func main() {
17-
filename := flag.String("filename", "", "File to serve")
18-
addr := flag.String("addr", ":8100", "address & port to server on")
19-
fsType := flag.String("type", "iso9660", "Filesystem type (iso9660, fat32, squashfs)")
20-
flag.Parse()
21-
17+
func serve(filename, addr, fsType *string) error {
2218
f, err := os.Open(*filename)
2319
if err != nil {
24-
log.Fatalf("Cannot open %q: %s", *filename, err)
20+
return fmt.Errorf("cannot open %q: %s", *filename, err)
2521
}
2622
b := file.New(f, true)
2723

@@ -35,15 +31,26 @@ func main() {
3531
case "squashfs":
3632
fs, err = squashfs.Read(b, 0, 0, 0)
3733
default:
38-
log.Fatalf("Unknown filesystem type %q", *fsType)
34+
return fmt.Errorf("unknown filesystem type %q", *fsType)
3935
}
4036
if err != nil {
41-
log.Fatalf("Cannot open %s image in %q: %s", *fsType, *filename, err)
37+
return fmt.Errorf("cannot open %s image in %q: %s", *fsType, *filename, err)
4238
}
4339

4440
http.Handle("/", http.FileServer(http.FS(filesystem.FS(fs))))
4541

4642
log.Printf("Serving %q on HTTP port: %s\n", *filename, *addr)
47-
log.Fatal(http.ListenAndServe(*addr, nil))
43+
//nolint:gosec // we know this violates G114, but it is just an example
44+
return http.ListenAndServe(*addr, nil)
45+
}
4846

47+
func main() {
48+
filename := flag.String("filename", "", "File to serve")
49+
addr := flag.String("addr", ":8100", "address & port to server on")
50+
fsType := flag.String("type", "iso9660", "Filesystem type (iso9660, fat32, squashfs)")
51+
flag.Parse()
52+
53+
if err := serve(filename, addr, fsType); err != nil {
54+
log.Fatalf("Error serving: %s", err)
55+
}
4956
}

filesystem/fat32/common_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ func testGetValidDirectoryEntriesFromFile(dirFilePath, dirEntryPattern string, f
250250
// ignore entries for . and ..
251251
dirEntriesSubset := dirEntries
252252
for {
253+
//nolint:staticcheck // could lift into for loop, but this is easier to read
253254
if len(dirEntriesSubset) == 0 || (dirEntriesSubset[0].filenameShort != "." && dirEntriesSubset[0].filenameShort != "..") {
254255
break
255256
}

filesystem/fat32/directoryentry.go

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ const (
2323
var validShortNameCharacters, _ = asciiset.MakeASCIISet("!#$%&'()-0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`{}~")
2424

2525
// directoryEntry is a single directory entry
26-
//
27-
//nolint:structcheck // we are willing to leave unused elements here so that we can know their reference
2826
type directoryEntry struct {
2927
filenameShort string
3028
fileExtension string

filesystem/fat32/fat32.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const (
4444
maxCharsLongFilename int = 13
4545
)
4646

47-
//nolint:deadcode,varcheck,unused // we need these references in the future
47+
//nolint:unused // we need these references in the future
4848
const (
4949
minClusterSize int = 128
5050
maxClusterSize int = 65529

filesystem/fat32/fat32_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"strings"
1818
"testing"
1919

20-
"github.com/diskfs/go-diskfs"
20+
diskfs "github.com/diskfs/go-diskfs"
2121
"github.com/diskfs/go-diskfs/backend"
2222
"github.com/diskfs/go-diskfs/backend/file"
2323
"github.com/diskfs/go-diskfs/disk"

filesystem/fat32/fsinfosector.go

-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ const (
1919

2020
const (
2121
// unknownFreeDataClusterCount is the fixed flag for unknown number of free data clusters
22-
//nolint:varcheck,deadcode // keep for future reference
2322
unknownFreeDataClusterCount uint32 = 0xffffffff
2423
// unknownlastAllocatedCluster is the fixed flag for unknown most recently allocated cluster
25-
//nolint:varcheck,deadcode // keep for future reference
2624
unknownlastAllocatedCluster uint32 = 0xffffffff
2725
)
2826

filesystem/iso9660/directoryentry.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func (de *directoryEntry) getLocation(p string) (location, size uint32, err erro
400400
return 0, 0, fmt.Errorf("extension %s count not find a filename property: %v", e.ID(), err2)
401401
default:
402402
checkFilename = filename
403-
//nolint:gosimple // redundant break, but we want this explicit
403+
//nolint:staticcheck // redundant break, but we want this explicit
404404
break
405405
}
406406
}
@@ -459,7 +459,7 @@ func (de *directoryEntry) Name() string {
459459
continue
460460
default:
461461
name = filename
462-
//nolint:gosimple // redundant break, but we want this explicit
462+
//nolint:staticcheck // redundant break, but we want this explicit
463463
break
464464
}
465465
}

filesystem/iso9660/eltorito.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/diskfs/go-diskfs/util"
1111
)
1212

13-
//nolint:deadcode,varcheck,unused // we need these references in the future
13+
//nolint:unused // we need these references in the future
1414
const (
1515
elToritoSector = 0x11
1616
elToritoDefaultBlocks = 4

filesystem/iso9660/finalize.go

-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ type FinalizeOptions struct {
5252
// Nlink() uint32 // number of hardlinks, if supported
5353
// Uid() uint32 // uid, if supported
5454
// Gid() uint32 // gid, if supported
55-
//
56-
//nolint:structcheck // keep unused members so that we can know their references
5755
type finalizeFileInfo struct {
5856
path string
5957
target string

filesystem/iso9660/finalize_internal_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ func TestCollapseAndSortChildren(t *testing.T) {
149149
root.children = children
150150
root.addProperties(1)
151151
dirs, files := root.collapseAndSortChildren()
152-
dirsMatch := true
152+
var dirsMatch = true
153153
if len(dirs) != len(expectedDirs) {
154154
dirsMatch = false
155155
}
156-
filesMatch := true
156+
var filesMatch bool
157157
if len(files) != len(expectedFiles) {
158158
filesMatch = false
159159
}

filesystem/iso9660/finalize_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ func validateElTorito(t *testing.T, f *os.File) {
560560
// look for El Torito line
561561
re := regexp.MustCompile(`El Torito VD version 1 found, boot catalog is in sector (\d+)\n`)
562562
matches := re.FindStringSubmatch(outString)
563-
if matches == nil || len(matches) < 1 {
563+
if len(matches) < 1 {
564564
t.Fatalf("unable to match El Torito information")
565565
}
566566
// what sector should it be in?

0 commit comments

Comments
 (0)