Skip to content

Commit bf359ef

Browse files
committed
GO code staticcheck cleanup
Ignored code generated files and fixed the left checks Signed-off-by: JUN JIE NAN <[email protected]>
1 parent 4c4158c commit bf359ef

32 files changed

+42
-42
lines changed

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ else
2323
COWSQL_PATH=$(GOPATH)/deps/cowsql
2424
endif
2525

26-
# raft
2726
.PHONY: default
2827
default: build
2928

@@ -56,6 +55,7 @@ incus-migrate:
5655

5756
.PHONY: deps
5857
deps:
58+
# raft
5959
@if [ ! -e "$(RAFT_PATH)" ]; then \
6060
git clone --depth=1 "https://github.com/cowsql/raft" "$(RAFT_PATH)"; \
6161
elif [ -e "$(RAFT_PATH)/.git" ]; then \

Diff for: cmd/incus/admin_recover.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"golang.org/x/text/cases"
1111
"golang.org/x/text/language"
1212

13-
"github.com/lxc/incus/v6/client"
13+
incus "github.com/lxc/incus/v6/client"
1414
cli "github.com/lxc/incus/v6/internal/cmd"
1515
"github.com/lxc/incus/v6/internal/i18n"
1616
"github.com/lxc/incus/v6/internal/recover"
@@ -241,7 +241,7 @@ func (c *cmdAdminRecover) Run(cmd *cobra.Command, args []string) error {
241241
// Send /internal/recover/import request to the daemon.
242242
// Don't lint next line with gosimple. It says we should convert reqValidate directly to an RecoverImportPost
243243
// because their types are identical. This is less clear and will not work if either type changes in the future.
244-
reqImport := recover.ImportPost{ //nolint:gosimple
244+
reqImport := recover.ImportPost{ //lint:ignore S1016 for reason above
245245
Pools: reqValidate.Pools,
246246
}
247247

Diff for: cmd/incus/completion.go

-4
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,6 @@ func (g *cmdGlobal) cmpNetworkForwardConfigs(networkName string, listenAddress s
496496
}
497497

498498
func (g *cmdGlobal) cmpNetworkForwards(networkName string) ([]string, cobra.ShellCompDirective) {
499-
results := []string{}
500499
cmpDirectives := cobra.ShellCompDirectiveNoFileComp
501500

502501
resources, _ := g.ParseServers(networkName)
@@ -516,7 +515,6 @@ func (g *cmdGlobal) cmpNetworkForwards(networkName string) ([]string, cobra.Shel
516515
}
517516

518517
func (g *cmdGlobal) cmpNetworkLoadBalancers(networkName string) ([]string, cobra.ShellCompDirective) {
519-
results := []string{}
520518
cmpDirectives := cobra.ShellCompDirectiveNoFileComp
521519

522520
resources, _ := g.ParseServers(networkName)
@@ -560,7 +558,6 @@ func (g *cmdGlobal) cmpNetworkPeerConfigs(networkName string, peerName string) (
560558
}
561559

562560
func (g *cmdGlobal) cmpNetworkPeers(networkName string) ([]string, cobra.ShellCompDirective) {
563-
results := []string{}
564561
cmpDirectives := cobra.ShellCompDirectiveNoFileComp
565562

566563
resources, _ := g.ParseServers(networkName)
@@ -742,7 +739,6 @@ func (g *cmdGlobal) cmpNetworkZoneRecordConfigs(zoneName string, recordName stri
742739
}
743740

744741
func (g *cmdGlobal) cmpNetworkZoneRecords(zoneName string) ([]string, cobra.ShellCompDirective) {
745-
results := []string{}
746742
cmpDirectives := cobra.ShellCompDirectiveNoFileComp
747743

748744
resources, _ := g.ParseServers(zoneName)

Diff for: cmd/incus/snapshot.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/spf13/cobra"
1313
"gopkg.in/yaml.v2"
1414

15-
"github.com/lxc/incus/v6/client"
15+
incus "github.com/lxc/incus/v6/client"
1616
cli "github.com/lxc/incus/v6/internal/cmd"
1717
"github.com/lxc/incus/v6/internal/i18n"
1818
"github.com/lxc/incus/v6/internal/instance"
@@ -514,8 +514,6 @@ func (c *cmdSnapshotRestore) Run(cmd *cobra.Command, args []string) error {
514514
type cmdSnapshotShow struct {
515515
global *cmdGlobal
516516
snapshot *cmdSnapshot
517-
518-
flagExpanded bool
519517
}
520518

521519
func (c *cmdSnapshotShow) Command() *cobra.Command {

Diff for: cmd/incusd/dev_incus.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func hoistReq(f func(*Daemon, instance.Instance, http.ResponseWriter, *http.Requ
278278
conn := ucred.GetConnFromContext(r.Context())
279279
cred, ok := pidMapper.m[conn.(*net.UnixConn)]
280280
if !ok {
281-
http.Error(w, pidNotInContainerErr.Error(), http.StatusInternalServerError)
281+
http.Error(w, errPidNotInContainer.Error(), http.StatusInternalServerError)
282282
return
283283
}
284284

@@ -390,7 +390,7 @@ func (m *ConnPidMapper) ConnStateHandler(conn net.Conn, state http.ConnState) {
390390
}
391391
}
392392

393-
var pidNotInContainerErr = fmt.Errorf("pid not in container?")
393+
var errPidNotInContainer = fmt.Errorf("pid not in container?")
394394

395395
func findContainerForPid(pid int32, s *state.State) (instance.Container, error) {
396396
/*
@@ -496,5 +496,5 @@ func findContainerForPid(pid int32, s *state.State) (instance.Container, error)
496496
}
497497
}
498498

499-
return nil, pidNotInContainerErr
499+
return nil, errPidNotInContainer
500500
}

Diff for: cmd/incusd/dev_incus_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func TestHttpRequest(t *testing.T) {
169169
t.Fatal(err)
170170
}
171171

172-
if !strings.Contains(string(resp), pidNotInContainerErr.Error()) {
172+
if !strings.Contains(string(resp), errPidNotInContainer.Error()) {
173173
t.Fatal("resp error not expected: ", string(resp))
174174
}
175175
}

Diff for: cmd/incusd/instance.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ func instanceCreateAsCopy(s *state.State, opts instanceCreateAsCopyOpts, op *ope
427427
"path": "/",
428428
"pool": instRootDiskDevice["pool"],
429429
}
430-
} else { //nolint:staticcheck // (keep the empty branch for the comment)
430+
//lint:ignore SA9003 keep the empty branch for the comment
431+
} else {
431432
// Snapshot has multiple root disk devices, we can't automatically fix this so
432433
// leave alone so we don't prevent copy.
433434
}

Diff for: internal/server/cluster/membership.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import (
2626
"github.com/lxc/incus/v6/shared/util"
2727
)
2828

29-
// clusterBusyError is returned by dqlite if attempting attempting to join a cluster at the same time as a role-change.
29+
// errClusterBusy is returned by dqlite if attempting attempting to join a cluster at the same time as a role-change.
3030
// This error tells us we can retry and probably join the cluster or fail due to something else.
3131
// The error code here is SQLITE_BUSY.
32-
var clusterBusyError = fmt.Errorf("A configuration change is already in progress (5)")
32+
var errClusterBusy = fmt.Errorf("A configuration change is already in progress (5)")
3333

3434
// Bootstrap turns a non-clustered server into the first (and leader)
3535
// member of a new cluster.
@@ -447,7 +447,7 @@ func Join(state *state.State, gateway *Gateway, networkCert *localtls.CertInfo,
447447
return fmt.Errorf("Failed to join cluster: %w", ctx.Err())
448448
default:
449449
err = client.Add(ctx, info.NodeInfo)
450-
if err != nil && err.Error() == clusterBusyError.Error() {
450+
if err != nil && err.Error() == errClusterBusy.Error() {
451451
// If the cluster is busy with a role change, sleep a second and then keep trying to join.
452452
time.Sleep(1 * time.Second)
453453
continue
@@ -593,6 +593,7 @@ func NotifyHeartbeat(state *state.State, gateway *Gateway) {
593593
// Wait for heartbeat to finish and then release.
594594
// Ignore staticcheck "SA2001: empty critical section" because we want to wait for the lock.
595595
gateway.HeartbeatLock.Lock()
596+
//lint:ignore SA2001 we want to wait for the lock
596597
gateway.HeartbeatLock.Unlock() //nolint:staticcheck
597598
}
598599

Diff for: internal/server/db/cluster/certificate_projects.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/certificates.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/cluster_groups.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/config.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/devices.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/images.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/instance_profiles.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/instances.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/networks_integrations.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/nodes.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/nodes_cluster_groups.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/operations.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/profiles.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/projects.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/snapshots.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/cluster/warnings.mapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cluster
44

55
// The code below was generated by incus-generate - DO NOT EDIT!
6+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
67

78
import (
89
"context"

Diff for: internal/server/db/generate/file/write.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func Reset(path string, imports []string, buildComment string, iface bool) error
2828
content := fmt.Sprintf(`%spackage %s
2929
3030
// The code below was generated by %s - DO NOT EDIT!
31+
//lint:file-ignore U1000,SA4006 Ignore staticcheck
3132
3233
import (
3334
`, buildComment, os.Getenv("GOPACKAGE"), os.Args[0])

Diff for: internal/server/network/ovs/utils.go

-16
This file was deleted.

Diff for: internal/server/response/swagger.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Package response contains helpers for rendering HTTP responses.
22
//
33
//nolint:deadcode,unused
4+
//lint:file-ignore U1000 Ignore unused
5+
46
package response
57

68
import (

Diff for: internal/server/scriptlet/load/load.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"sync"
77

88
"go.starlark.net/starlark"
9+
"go.starlark.net/syntax"
910
)
1011

1112
// nameInstancePlacement is the name used in Starlark for the instance placement scriptlet.
@@ -30,7 +31,7 @@ func InstancePlacementCompile(src string) (*starlark.Program, error) {
3031
}
3132

3233
// Parse, resolve, and compile a Starlark source file.
33-
_, mod, err := starlark.SourceProgram(nameInstancePlacement, src, isPreDeclared)
34+
_, mod, err := starlark.SourceProgramOptions(syntax.LegacyFileOptions(), nameInstancePlacement, src, isPreDeclared)
3435
if err != nil {
3536
return nil, err
3637
}

Diff for: internal/server/util/http.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func CheckTrustState(cert x509.Certificate, trustedCerts map[string]x509.Certifi
174174
return false, "" // CRL not signed by CA
175175
}
176176

177-
for _, revoked := range crl.RevokedCertificates {
177+
for _, revoked := range crl.RevokedCertificateEntries {
178178
if cert.SerialNumber.Cmp(revoked.SerialNumber) == 0 {
179179
return false, "" // Certificate is revoked, so not trusted anymore.
180180
}

Diff for: shared/cliconfig/remote.go

+2
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ func (c *Config) getConnectionArgs(name string) (*incus.ConnectionArgs, error) {
332332
// Golang has deprecated all methods relating to PEM encryption due to a vulnerability.
333333
// However, the weakness does not make PEM unsafe for our purposes as it pertains to password protection on the
334334
// key file (client.key is only readable to the user in any case), so we'll ignore deprecation.
335+
//lint:ignore SA1019 see above for reason
335336
isEncrypted := x509.IsEncryptedPEMBlock(pemKey) //nolint:staticcheck
336337
isSSH := pemKey.Type == "OPENSSH PRIVATE KEY"
337338
if isEncrypted || isSSH {
@@ -366,6 +367,7 @@ func (c *Config) getConnectionArgs(name string) (*incus.ConnectionArgs, error) {
366367
return nil, fmt.Errorf("Unsupported key type: %T", sshKey)
367368
}
368369
} else {
370+
//lint:ignore SA1019 see above for reason
369371
derKey, err := x509.DecryptPEMBlock(pemKey, []byte(password)) //nolint:staticcheck
370372
if err != nil {
371373
return nil, err

Diff for: test/mini-oidc/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func main() {
4747
},
4848
}
4949

50-
provider, err := op.NewOpenIDProvider(issuer, config, storage, op.WithAllowInsecure())
50+
provider, err := op.NewProvider(config, storage, op.StaticIssuer(issuer), op.WithAllowInsecure())
5151
if err != nil {
5252
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
5353
os.Exit(1)
@@ -93,8 +93,6 @@ func userCodeHandler(storage *storage.Storage, w http.ResponseWriter, r *http.Re
9393
}
9494

9595
fmt.Printf("%s => %s\n", userCode, name)
96-
97-
return
9896
}
9997

10098
func username() string {

0 commit comments

Comments
 (0)