Skip to content

Commit c82d2e9

Browse files
authored
fix: Lint fixes (#253)
1 parent d263b66 commit c82d2e9

File tree

11 files changed

+51
-32
lines changed

11 files changed

+51
-32
lines changed

.golangci.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ linters:
66
- asciicheck
77
- bidichk
88
- bodyclose
9+
- canonicalheader
910
- containedctx
1011
- contextcheck
12+
- copyloopvar
1113
- cyclop
1214
- decorder
1315
- dogsled
@@ -18,15 +20,17 @@ linters:
1820
- errchkjson
1921
- errname
2022
- errorlint
21-
- execinquery
2223
- exhaustive
23-
- exportloopref
24+
- fatcontext
2425
- forbidigo
2526
- forcetypeassert
2627
- funlen
2728
- gci
29+
- ginkgolinter
30+
- gocheckcompilerdirectives
2831
- gochecknoglobals
2932
- gochecknoinits
33+
- gochecksumtype
3034
- gocognit
3135
- goconst
3236
- gocritic
@@ -41,16 +45,21 @@ linters:
4145
- goprintffuncname
4246
- gosec
4347
- gosimple
48+
- gosmopolitan
4449
- govet
4550
- grouper
4651
- importas
52+
- inamedparam
4753
- ineffassign
4854
- interfacebloat
55+
- intrange
4956
- lll
5057
- loggercheck
5158
- maintidx
5259
- makezero
60+
- mirror
5361
- misspell
62+
- musttag
5463
- nakedret
5564
- nestif
5665
- nilerr
@@ -60,18 +69,24 @@ linters:
6069
- nolintlint
6170
- nosprintfhostport
6271
- paralleltest
72+
- perfsprint
6373
- prealloc
6474
- predeclared
6575
- promlinter
76+
- protogetter
6677
- reassign
6778
- revive
6879
- rowserrcheck
80+
- sloglint
81+
- spancheck
6982
- sqlclosecheck
7083
- staticcheck
7184
- stylecheck
85+
- tagalign
7286
- tagliatelle
7387
- tenv
7488
- testableexamples
89+
- testifylint
7590
- testpackage
7691
- thelper
7792
- tparallel
@@ -83,3 +98,4 @@ linters:
8398
- wastedassign
8499
- whitespace
85100
- wsl
101+
- zerologlint

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
hooks:
1010
- id: commitizen
1111
- repo: https://github.com/golangci/golangci-lint
12-
rev: v1.54.1
12+
rev: v1.60.3
1313
hooks:
1414
- id: golangci-lint
1515
- repo: https://github.com/gitleaks/gitleaks

internal/aes7z/key.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func calculateKey(password string, cycles int, salt []byte) ([]byte, error) {
6262
_, _ = h.Write(b.Bytes())
6363
_ = binary.Write(h, binary.LittleEndian, i)
6464
}
65+
6566
copy(key, h.Sum(nil))
6667
}
6768

internal/bcj2/reader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type readCloser struct {
4949
sd [256 + 2]uint
5050

5151
previous byte
52-
written uint64
52+
written uint32
5353

5454
buf *bytes.Buffer
5555
}
@@ -189,7 +189,7 @@ func (rc *readCloser) read() error {
189189
return err
190190
}
191191

192-
dest -= uint32(rc.written + 4)
192+
dest -= rc.written + 4
193193
_ = binary.Write(rc.buf, binary.LittleEndian, dest)
194194

195195
rc.previous = byte(dest >> 24)

internal/bra/bcj.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ func (c *bcj) Convert(b []byte, encoding bool) int {
2424
}
2525

2626
var (
27-
pos int
27+
pos uint32
2828
mask = c.state & 7
2929
)
3030

3131
for {
3232
p := pos
33-
for ; p < len(b)-bcjLookAhead; p++ {
33+
for ; int(p) < len(b)-bcjLookAhead; p++ {
3434
if b[p]&0xfe == 0xe8 {
3535
break
3636
}
@@ -39,23 +39,23 @@ func (c *bcj) Convert(b []byte, encoding bool) int {
3939
d := p - pos
4040
pos = p
4141

42-
if p >= len(b)-bcjLookAhead {
42+
if int(p) >= len(b)-bcjLookAhead {
4343
if d > 2 {
4444
c.state = 0
4545
} else {
4646
c.state = mask >> d
4747
}
4848

49-
c.ip += uint32(pos)
49+
c.ip += pos
5050

51-
return pos
51+
return int(pos)
5252
}
5353

5454
if d > 2 {
5555
mask = 0
5656
} else {
5757
mask >>= d
58-
if mask != 0 && (mask > 4 || mask == 3 || test86MSByte(b[p+int(mask>>1)+1])) {
58+
if mask != 0 && (mask > 4 || mask == 3 || test86MSByte(b[p+(mask>>1)+1])) {
5959
mask = (mask >> 1) | 4
6060
pos++
6161

@@ -66,8 +66,8 @@ func (c *bcj) Convert(b []byte, encoding bool) int {
6666
//nolint:nestif
6767
if test86MSByte(b[p+4]) {
6868
v := binary.LittleEndian.Uint32(b[p+1:])
69-
cur := c.ip + uint32(c.Size()+pos)
70-
pos += c.Size()
69+
cur := c.ip + uint32(c.Size()) + pos //nolint:gosec
70+
pos += uint32(c.Size()) //nolint:gosec
7171

7272
if encoding {
7373
v += cur

internal/bra/bra.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ package bra
22

33
type converter interface {
44
Size() int
5-
Convert([]byte, bool) int
5+
Convert(b []byte, encoding bool) int
66
}

internal/bra/minmax_compat.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package bra
44

5+
//nolint:predeclared
56
func min(x, y int) int {
67
if x < y {
78
return x
@@ -10,6 +11,7 @@ func min(x, y int) int {
1011
return y
1112
}
1213

14+
//nolint:predeclared
1315
func max(x, y int) int {
1416
if x > y {
1517
return x

internal/pool/pool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111

1212
// Pooler is the interface implemented by a pool.
1313
type Pooler interface {
14-
Get(int64) (util.SizeReadSeekCloser, bool)
15-
Put(int64, util.SizeReadSeekCloser) (bool, error)
14+
Get(offset int64) (util.SizeReadSeekCloser, bool)
15+
Put(offset int64, rc util.SizeReadSeekCloser) (bool, error)
1616
}
1717

1818
// Constructor is the function prototype used to instantiate a pool.

reader.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (f *File) Open() (io.ReadCloser, error) {
139139
return &fileReader{
140140
rc: rc,
141141
f: f,
142-
n: int64(f.UncompressedSize),
142+
n: int64(f.UncompressedSize), //nolint:gosec
143143
}, nil
144144
}
145145

@@ -349,7 +349,7 @@ func (z *Reader) init(r io.ReaderAt, size int64) error {
349349
}
350350

351351
// Seek over the streams
352-
if z.end, err = sr.Seek(int64(start.Offset), io.SeekCurrent); err != nil {
352+
if z.end, err = sr.Seek(int64(start.Offset), io.SeekCurrent); err != nil { //nolint:gosec
353353
return err
354354
}
355355

@@ -359,7 +359,7 @@ func (z *Reader) init(r io.ReaderAt, size int64) error {
359359
h.Reset()
360360

361361
// Bound bufio.Reader otherwise it can read trailing garbage which screws up the CRC check
362-
br := bufio.NewReader(io.NewSectionReader(tra, z.end, int64(start.Size)))
362+
br := bufio.NewReader(io.NewSectionReader(tra, z.end, int64(start.Size))) //nolint:gosec
363363

364364
id, err := br.ReadByte()
365365
if err != nil {
@@ -449,7 +449,7 @@ func (z *Reader) init(r io.ReaderAt, size int64) error {
449449
}
450450

451451
f.offset = offset
452-
offset += int64(f.UncompressedSize)
452+
offset += int64(f.UncompressedSize) //nolint:gosec
453453
folder = f.folder
454454
j++
455455
}

struct.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var errAlgorithm = errors.New("sevenzip: unsupported compression algorithm")
1818

1919
// CryptoReadCloser adds a Password method to decompressors.
2020
type CryptoReadCloser interface {
21-
Password(string) error
21+
Password(password string) error
2222
}
2323

2424
type signatureHeader struct {
@@ -97,7 +97,7 @@ func (f *folder) coderReader(readers []io.ReadCloser, coder uint64, password str
9797
}
9898
}
9999

100-
return plumbing.LimitReadCloser(cr, int64(f.size[coder])), nil
100+
return plumbing.LimitReadCloser(cr, int64(f.size[coder])), nil //nolint:gosec
101101
}
102102

103103
type folderReadCloser struct {
@@ -118,7 +118,7 @@ func (rc *folderReadCloser) Seek(offset int64, whence int) (int64, error) {
118118
case io.SeekStart:
119119
newo = offset
120120
case io.SeekCurrent:
121-
newo = int64(rc.wc.Count()) + offset
121+
newo = int64(rc.wc.Count()) + offset //nolint:gosec
122122
case io.SeekEnd:
123123
newo = rc.Size() + offset
124124
default:
@@ -129,15 +129,15 @@ func (rc *folderReadCloser) Seek(offset int64, whence int) (int64, error) {
129129
return 0, errors.New("negative seek")
130130
}
131131

132-
if newo < int64(rc.wc.Count()) {
132+
if uint64(newo) < rc.wc.Count() {
133133
return 0, errors.New("cannot seek backwards")
134134
}
135135

136136
if newo > rc.Size() {
137137
return 0, errors.New("cannot seek beyond EOF")
138138
}
139139

140-
if _, err := io.CopyN(io.Discard, rc, newo-int64(rc.wc.Count())); err != nil {
140+
if _, err := io.CopyN(io.Discard, rc, newo-int64(rc.wc.Count())); err != nil { //nolint:gosec
141141
return 0, err
142142
}
143143

@@ -232,7 +232,7 @@ func (si *streamsInfo) folderOffset(folder int) int64 {
232232
k += si.unpackInfo.folder[i].packedStreams
233233
}
234234

235-
return int64(si.packInfo.position + offset)
235+
return int64(si.packInfo.position + offset) //nolint:gosec
236236
}
237237

238238
//nolint:cyclop,funlen
@@ -249,7 +249,7 @@ func (si *streamsInfo) FolderReader(r io.ReaderAt, folder int, password string)
249249
offset := int64(0)
250250

251251
for i, input := range f.packed {
252-
size := int64(si.packInfo.size[packedOffset+i])
252+
size := int64(si.packInfo.size[packedOffset+i]) //nolint:gosec
253253
in[input] = util.NopCloser(bufio.NewReader(io.NewSectionReader(r, si.folderOffset(folder)+offset, size)))
254254
offset += size
255255
}
@@ -297,7 +297,7 @@ func (si *streamsInfo) FolderReader(r io.ReaderAt, folder int, password string)
297297
return nil, 0, errors.New("expecting one unbound output stream")
298298
}
299299

300-
fr := newFolderReadCloser(out[unbound[0]], int64(f.unpackSize()))
300+
fr := newFolderReadCloser(out[unbound[0]], int64(f.unpackSize())) //nolint:gosec
301301

302302
if si.unpackInfo.digest != nil {
303303
return fr, si.unpackInfo.digest[folder], nil
@@ -344,7 +344,7 @@ type headerFileInfo struct {
344344
}
345345

346346
func (fi headerFileInfo) Name() string { return path.Base(fi.fh.Name) }
347-
func (fi headerFileInfo) Size() int64 { return int64(fi.fh.UncompressedSize) }
347+
func (fi headerFileInfo) Size() int64 { return int64(fi.fh.UncompressedSize) } //nolint:gosec
348348
func (fi headerFileInfo) IsDir() bool { return fi.Mode().IsDir() }
349349
func (fi headerFileInfo) ModTime() time.Time { return fi.fh.Modified.UTC() }
350350
func (fi headerFileInfo) Mode() fs.FileMode { return fi.fh.Mode() }

0 commit comments

Comments
 (0)