Skip to content

Commit d4c0b43

Browse files
hi-leiclaude
andcommitted
fix: resolve remaining lint and gosec issues
- goconst: extract "gpu" to kindGPU constant - prealloc: preallocate volumes and volDetails slices - revive: suppress var-naming for cmd/util package - nolintlint: suppress for gosec directives (needed by separate security CI) - gosec G304: add nolint to all os.ReadFile on controlled config paths Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9eccacf commit d4c0b43

6 files changed

Lines changed: 19 additions & 9 deletions

File tree

.golangci.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ linters:
9191
- path: cmd/
9292
linters:
9393
- unparam
94+
- path: cmd/util/
95+
linters:
96+
- revive
97+
text: "var-naming"
98+
- linters:
99+
- nolintlint
100+
text: "gosec"
94101

95102
formatters:
96103
enable:

internal/verda-cli/cmd/auth/auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestWriteActiveProfile(t *testing.T) {
1616
t.Fatalf("writeActiveProfile() returned error: %v", err)
1717
}
1818

19-
data, err := os.ReadFile(path)
19+
data, err := os.ReadFile(path) //nolint:gosec // test file
2020
if err != nil {
2121
t.Fatalf("os.ReadFile() returned error: %v", err)
2222
}

internal/verda-cli/cmd/auth/use.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func NewCmdUse(_ cmdutil.Factory, ioStreams cmdutil.IOStreams) *cobra.Command {
5151

5252
func writeActiveProfile(path, profile string) error {
5353
cfg := map[string]any{}
54-
if data, err := os.ReadFile(path); err == nil {
54+
if data, err := os.ReadFile(path); err == nil { //nolint:gosec // controlled config path
5555
if err := yaml.Unmarshal(data, &cfg); err != nil {
5656
return err
5757
}

internal/verda-cli/cmd/vm/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func fetchInstanceVolumes(ctx context.Context, client *verda.Client, inst *verda
120120
}
121121
}
122122

123-
var volumes []verda.Volume
123+
volumes := make([]verda.Volume, 0, len(ids))
124124
for _, id := range ids {
125125
vol, err := client.Volumes.GetVolume(ctx, id)
126126
if err != nil {

internal/verda-cli/cmd/vm/wizard.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import (
1818
cmdutil "github/verda-cloud/verda-cli/internal/verda-cli/cmd/util"
1919
)
2020

21-
const billingTypeSpot = "spot"
21+
const (
22+
billingTypeSpot = "spot"
23+
kindGPU = "gpu"
24+
)
2225

2326
// clientFunc lazily resolves a Verda API client. This allows the wizard
2427
// to start without credentials — steps that don't need API (billing-type,
@@ -184,7 +187,7 @@ func stepKind(opts *createOptions) wizard.Step {
184187
Prompt: wizard.SelectPrompt,
185188
Required: true,
186189
Loader: wizard.StaticChoices(
187-
wizard.Choice{Label: "GPU", Value: "gpu", Description: "GPU-accelerated instances"},
190+
wizard.Choice{Label: "GPU", Value: kindGPU, Description: "GPU-accelerated instances"},
188191
wizard.Choice{Label: "CPU", Value: "cpu", Description: "CPU-only instances"},
189192
),
190193
Setter: func(v any) { opts.Kind = v.(string) },
@@ -1019,7 +1022,7 @@ func renderDeploymentSummary(opts *createOptions, cache *apiCache) {
10191022
unitPrice float64 // per GB per month
10201023
hourly float64
10211024
}
1022-
var volDetails []volDetail
1025+
volDetails := make([]volDetail, 0, len(opts.VolumeSpecs))
10231026
for _, spec := range opts.VolumeSpecs {
10241027
parts := strings.SplitN(spec, ":", 3)
10251028
if len(parts) < 3 {
@@ -1104,7 +1107,7 @@ func matchesKind(instanceType, kind string) bool {
11041107
switch strings.ToLower(kind) {
11051108
case "cpu":
11061109
return isCPU
1107-
case "gpu":
1110+
case kindGPU:
11081111
return !isCPU
11091112
default:
11101113
return true

internal/verda-cli/options/settings.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func SaveSetting(key string, value any) error {
1717
path := filepath.Join(dir, "config.yaml")
1818

1919
cfg := map[string]any{}
20-
if data, err := os.ReadFile(path); err == nil {
20+
if data, err := os.ReadFile(path); err == nil { //nolint:gosec // controlled config path
2121
if err := yaml.Unmarshal(data, &cfg); err != nil {
2222
return err
2323
}
@@ -42,7 +42,7 @@ func GetSetting(key string) (any, bool) {
4242
}
4343
path := filepath.Join(dir, "config.yaml")
4444

45-
data, err := os.ReadFile(path)
45+
data, err := os.ReadFile(path) //nolint:gosec // controlled config path
4646
if err != nil {
4747
return nil, false
4848
}

0 commit comments

Comments
 (0)