Skip to content

Commit 070c828

Browse files
authored
update linter and fix lints (#284)
Signed-off-by: Hamza El-Saawy <[email protected]>
1 parent b884eb7 commit 070c828

File tree

9 files changed

+58
-29
lines changed

9 files changed

+58
-29
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,26 @@ on:
44
- pull_request
55

66
env:
7-
GO_VERSION: "1.17"
7+
GO_VERSION: "oldstable"
8+
GOTESTSUM_VERSION: "latest"
89

910
jobs:
1011
lint:
1112
name: Lint
1213
runs-on: windows-2019
1314
steps:
14-
- uses: actions/checkout@v3
15-
- uses: actions/setup-go@v3
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
18+
- name: Install go
19+
uses: actions/setup-go@v4
1620
with:
1721
go-version: ${{ env.GO_VERSION }}
22+
1823
- name: Run golangci-lint
1924
uses: golangci/golangci-lint-action@v3
2025
with:
21-
version: v1.50
26+
version: v1.52
2227
args: >-
2328
--verbose
2429
--timeout=5m
@@ -31,10 +36,14 @@ jobs:
3136
name: Go Generate
3237
runs-on: windows-2019
3338
steps:
34-
- uses: actions/checkout@v3
35-
- uses: actions/setup-go@v3
39+
- name: Checkout
40+
uses: actions/checkout@v3
41+
42+
- name: Install go
43+
uses: actions/setup-go@v4
3644
with:
3745
go-version: ${{ env.GO_VERSION }}
46+
3847
- name: Run go generate
3948
shell: pwsh
4049
run: |
@@ -45,6 +54,7 @@ jobs:
4554
Write-Output "::error title=Go Generate::Error running go generate."
4655
exit $LASTEXITCODE
4756
}
57+
4858
- name: Diff
4959
shell: pwsh
5060
run: |
@@ -66,22 +76,34 @@ jobs:
6676
matrix:
6777
os: [windows-2019, windows-2022, ubuntu-latest]
6878
steps:
69-
- uses: actions/checkout@v3
70-
- uses: actions/setup-go@v3
79+
- name: Checkout
80+
uses: actions/checkout@v3
81+
82+
- name: Install go
83+
uses: actions/setup-go@v4
7184
with:
7285
go-version: ${{ env.GO_VERSION }}
73-
- run: go test -gcflags=all=-d=checkptr -v ./...
86+
87+
- name: Install gotestsum
88+
run: go install gotest.tools/gotestsum@${{ env.GOTESTSUM_VERSION }}
89+
90+
- name: Test repo
91+
run: gotestsum --format standard-verbose --debug -- -gcflags=all=-d=checkptr -v ./...
7492

7593
build:
7694
name: Build Repo
7795
needs:
7896
- test
7997
runs-on: "windows-2019"
8098
steps:
81-
- uses: actions/checkout@v3
82-
- uses: actions/setup-go@v3
99+
- name: Checkout
100+
uses: actions/checkout@v3
101+
102+
- name: Install go
103+
uses: actions/setup-go@v4
83104
with:
84105
go-version: ${{ env.GO_VERSION }}
106+
85107
- run: go build ./pkg/etw/sample/
86108
- run: go build ./tools/etw-provider-gen/
87109
- run: go build ./tools/mkwinsyscall/

.golangci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ issues:
3535
text: "^line-length-limit: "
3636
source: "^//(go:generate|sys) "
3737

38+
#TODO: remove after upgrading to go1.18
39+
# ignore comment spacing for nolint and sys directives
40+
- linters:
41+
- revive
42+
text: "^comment-spacings: no space between comment delimiter and comment text"
43+
source: "//(cspell:|nolint:|sys |todo)"
44+
45+
# not on go 1.18 yet, so no any
46+
- linters:
47+
- revive
48+
text: "^use-any: since GO 1.18 'interface{}' can be replaced by 'any'"
49+
3850
# allow unjustified ignores of error checks in defer statements
3951
- linters:
4052
- nolintlint

hvsock.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ import (
2323
const afHVSock = 34 // AF_HYPERV
2424

2525
// Well known Service and VM IDs
26-
//https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/user-guide/make-integration-service#vmid-wildcards
26+
// https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/user-guide/make-integration-service#vmid-wildcards
2727

2828
// HvsockGUIDWildcard is the wildcard VmId for accepting connections from all partitions.
2929
func HvsockGUIDWildcard() guid.GUID { // 00000000-0000-0000-0000-000000000000
3030
return guid.GUID{}
3131
}
3232

3333
// HvsockGUIDBroadcast is the wildcard VmId for broadcasting sends to all partitions.
34-
func HvsockGUIDBroadcast() guid.GUID { //ffffffff-ffff-ffff-ffff-ffffffffffff
34+
func HvsockGUIDBroadcast() guid.GUID { // ffffffff-ffff-ffff-ffff-ffffffffffff
3535
return guid.GUID{
3636
Data1: 0xffffffff,
3737
Data2: 0xffff,
@@ -246,7 +246,7 @@ func (l *HvsockListener) Accept() (_ net.Conn, err error) {
246246
var addrbuf [addrlen * 2]byte
247247

248248
var bytes uint32
249-
err = syscall.AcceptEx(l.sock.handle, sock.handle, &addrbuf[0], 0 /*rxdatalen*/, addrlen, addrlen, &bytes, &c.o)
249+
err = syscall.AcceptEx(l.sock.handle, sock.handle, &addrbuf[0], 0 /* rxdatalen */, addrlen, addrlen, &bytes, &c.o)
250250
if _, err = l.sock.asyncIO(c, nil, bytes, err); err != nil {
251251
return nil, l.opErr("accept", os.NewSyscallError("acceptex", err))
252252
}

internal/socket/socket.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ func (f *runtimeFunc) Load() error {
100100
(*byte)(unsafe.Pointer(&f.addr)),
101101
uint32(unsafe.Sizeof(f.addr)),
102102
&n,
103-
nil, //overlapped
104-
0, //completionRoutine
103+
nil, // overlapped
104+
0, // completionRoutine
105105
)
106106
})
107107
return f.err

internal/stringbuffer/wstring.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const MinWStringCap = 310
1515
// use *[]uint16 since []uint16 creates an extra allocation where the slice header
1616
// is copied to heap and then referenced via pointer in the interface header that sync.Pool
1717
// stores.
18-
var pathPool = sync.Pool{ //! if go1.18+ adds Pool[T], use that to store []uint16 directly
18+
var pathPool = sync.Pool{ // if go1.18+ adds Pool[T], use that to store []uint16 directly
1919
New: func() interface{} {
2020
b := make([]uint16, MinWStringCap)
2121
return &b
@@ -108,7 +108,7 @@ func (b *WString) String() string {
108108
// Using [windows.UTF16ToString] would require importing "golang.org/x/sys/windows"
109109
// and would make this code Windows-only, which makes no sense.
110110
// So copy UTF16ToString code into here.
111-
//! If other windows-specific code is added, switch to [windows.UTF16ToString]
111+
// If other windows-specific code is added, switch to [windows.UTF16ToString]
112112

113113
s := b.b
114114
for i, v := range s {

pipe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func tryDialPipe(ctx context.Context, path *string, access fs.AccessMask) (sysca
176176
nil, // security attributes
177177
fs.OPEN_EXISTING,
178178
fs.FILE_FLAG_OVERLAPPED|fs.SECURITY_SQOS_PRESENT|fs.SECURITY_ANONYMOUS,
179-
0, //template file handle
179+
0, // template file handle
180180
)
181181
h := syscall.Handle(wh)
182182
if err == nil {

pkg/etw/eventdescriptor.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ const (
4747
)
4848

4949
// EventDescriptor represents various metadata for an ETW event.
50-
//
51-
//nolint:structcheck // task is currently unused
5250
type eventDescriptor struct {
5351
id uint16
5452
version uint8

pkg/security/grantvmgroupaccess.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ type (
2121
trusteeForm uint32
2222
trusteeType uint32
2323

24-
//nolint:structcheck // structcheck thinks fields are unused, but the are used to pass data to OS
2524
explicitAccess struct {
2625
accessPermissions accessMask
2726
accessMode accessMode
2827
inheritance inheritMode
2928
trustee trustee
3029
}
3130

32-
//nolint:structcheck,unused // structcheck thinks fields are unused, but the are used to pass data to OS
3331
trustee struct {
3432
multipleTrustee *trustee
3533
multipleTrusteeOperation int32

wim/lzx/lzx.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,15 +489,14 @@ func (f *decompressor) readCompressedBlock(start, end uint16, hmain, hlength, ha
489489
f.lru[0] = matchoffset
490490
}
491491

492-
if matchoffset <= i && matchlen <= end-i {
493-
copyend := i + matchlen
494-
for ; i < copyend; i++ {
495-
f.window[i] = f.window[i-matchoffset]
496-
}
497-
} else {
492+
if !(matchoffset <= i && matchlen <= end-i) {
498493
f.fail(errCorrupt)
499494
break
500495
}
496+
copyend := i + matchlen
497+
for ; i < copyend; i++ {
498+
f.window[i] = f.window[i-matchoffset]
499+
}
501500
}
502501
return int(i - start), f.err
503502
}

0 commit comments

Comments
 (0)