Skip to content

Commit eca3ac3

Browse files
committed
fix: More involved lint fixes
1 parent ced63d2 commit eca3ac3

31 files changed

+93
-67
lines changed

internal/cli/commands/find/find_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ func TestRun(t *testing.T) {
8484
assert.Len(t, lines, len(expectedPaths))
8585

8686
// Convert expected paths to use OS-specific path separators
87-
var osExpectedPaths []string
87+
osExpectedPaths := make([]string, 0, len(expectedPaths))
8888
for _, path := range expectedPaths {
8989
osExpectedPaths = append(osExpectedPaths, filepath.FromSlash(path))
9090
}
9191

9292
// Convert actual paths to use OS-specific path separators
93-
var osPaths []string
93+
osPaths := make([]string, 0, len(lines))
9494
for _, line := range lines {
9595
osPaths = append(osPaths, filepath.FromSlash(strings.TrimSpace(line)))
9696
}
@@ -150,13 +150,13 @@ func TestRun(t *testing.T) {
150150
assert.Len(t, configs, len(expectedPaths))
151151

152152
// Convert expected paths to use OS-specific path separators
153-
var osExpectedPaths []string
153+
osExpectedPaths := make([]string, 0, len(expectedPaths))
154154
for _, path := range expectedPaths {
155155
osExpectedPaths = append(osExpectedPaths, filepath.FromSlash(path))
156156
}
157157

158158
// Extract paths and convert to OS-specific separators
159-
var paths []string
159+
paths := make([]string, 0, len(configs))
160160
for _, config := range configs {
161161
paths = append(paths, filepath.FromSlash(config.Path))
162162
}
@@ -224,13 +224,13 @@ func TestRun(t *testing.T) {
224224
assert.Len(t, lines, len(expectedPaths))
225225

226226
// Convert expected paths to use OS-specific path separators
227-
var osExpectedPaths []string
227+
osExpectedPaths := make([]string, 0, len(expectedPaths))
228228
for _, path := range expectedPaths {
229229
osExpectedPaths = append(osExpectedPaths, filepath.FromSlash(path))
230230
}
231231

232232
// Convert actual paths to use OS-specific path separators
233-
var osPaths []string
233+
osPaths := make([]string, 0, len(lines))
234234
for _, line := range lines {
235235
osPaths = append(osPaths, filepath.FromSlash(strings.TrimSpace(line)))
236236
}
@@ -295,13 +295,13 @@ dependency "unit2" {
295295
assert.Len(t, lines, len(expectedPaths))
296296

297297
// Convert paths to use OS-specific separators
298-
var osPaths []string
298+
osPaths := make([]string, 0, len(lines))
299299
for _, line := range lines {
300300
osPaths = append(osPaths, filepath.FromSlash(strings.TrimSpace(line)))
301301
}
302302

303303
// Convert expected paths to use OS-specific separators
304-
var osExpectedPaths []string
304+
osExpectedPaths := make([]string, 0, len(expectedPaths))
305305
for _, path := range expectedPaths {
306306
osExpectedPaths = append(osExpectedPaths, filepath.FromSlash(path))
307307
}
@@ -365,13 +365,13 @@ dependency "B" {
365365
assert.Len(t, configs, len(expectedPaths))
366366

367367
// Extract paths and verify order
368-
var paths []string
368+
paths := make([]string, 0, len(configs))
369369
for _, config := range configs {
370370
paths = append(paths, filepath.FromSlash(config.Path))
371371
}
372372

373373
// Convert expected paths to use OS-specific separators
374-
var osExpectedPaths []string
374+
osExpectedPaths := make([]string, 0, len(expectedPaths))
375375
for _, path := range expectedPaths {
376376
osExpectedPaths = append(osExpectedPaths, filepath.FromSlash(path))
377377
}

internal/cli/commands/hcl/validate/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ func getTerraformInputNamesFromEnvVar(opts *options.TerragruntOptions, terragrun
489489
// getTerraformInputNamesFromConfig will return the list of names of variables configured by the inputs block in the
490490
// terragrunt config.
491491
func getTerraformInputNamesFromConfig(terragruntConfig *config.TerragruntConfig) []string {
492-
out := []string{}
492+
out := make([]string, 0, len(terragruntConfig.Inputs))
493493
for inputName := range terragruntConfig.Inputs {
494494
out = append(out, inputName)
495495
}

internal/cli/commands/list/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func renderLong(opts *Options, components ListedComponents, c *Colorizer) error
372372
buf.WriteString(" " + c.Colorize(component))
373373

374374
if opts.Dependencies && len(component.Dependencies) > 0 {
375-
colorizedDeps := []string{}
375+
colorizedDeps := make([]string, 0, len(component.Dependencies))
376376

377377
for _, dep := range component.Dependencies {
378378
colorizedDeps = append(colorizedDeps, c.Colorize(dep))

internal/cli/commands/scaffold/scaffold.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func Run(ctx context.Context, l log.Logger, opts *options.TerragruntOptions, mod
133133
applyCatalogConfigToScaffold(ctx, l, opts)
134134

135135
// download remote repo to local
136-
var dirsToClean []string
136+
dirsToClean := make([]string, 0, 1)
137137
// clean all temp dirs
138138
defer func() {
139139
for _, dir := range dirsToClean {

internal/cli/commands/scaffold/scaffold_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ func TestDefaultTemplateVariables(t *testing.T) {
4242
// set pre-defined variables
4343
vars := map[string]any{}
4444

45-
var requiredVariables, optionalVariables []*config.ParsedVariable
45+
requiredVariables := make([]*config.ParsedVariable, 0, 1)
46+
optionalVariables := make([]*config.ParsedVariable, 0, 1)
4647

4748
requiredVariables = append(requiredVariables, &config.ParsedVariable{
4849
Name: "required_var_1",

internal/clihelper/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (flags Flags) WithSubcommandScope() Flags {
136136
}
137137

138138
func (flags Flags) Names() []string {
139-
var names []string
139+
names := make([]string, 0, len(flags))
140140

141141
for _, flag := range flags {
142142
names = append(names, flag.Names()...)

internal/clihelper/slice_flag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (flag *sliceValue[T]) Set(str string) error {
184184
}
185185

186186
func (flag *sliceValue[T]) Get() any {
187-
var vals []T
187+
vals := make([]T, 0, len(*flag.values))
188188

189189
vals = append(vals, *flag.values...)
190190

internal/clihelper/slice_flag_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func testSliceFlagApply[T clihelper.SliceFlagType](t *testing.T, flag *clihelper
178178
assert.Equal(t, expectedValue, actualValue)
179179

180180
expectedStringValueFn := func(value []T) string {
181-
var stringValue []string
181+
stringValue := make([]string, 0, len(value))
182182
for _, val := range value {
183183
stringValue = append(stringValue, fmt.Sprintf("%v", val))
184184
}

internal/experiment/experiment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func NewExperiments() Experiments {
9696

9797
// Names returns all experiment names.
9898
func (exps Experiments) Names() []string {
99-
names := []string{}
99+
names := make([]string, 0, len(exps))
100100

101101
for _, exp := range exps {
102102
names = append(names, exp.Name)

internal/filter/filter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func TestFilter_RealWorldScenarios(t *testing.T) {
345345
result, err := filter.Apply(l, tt.filterString, repoComponents)
346346
require.NoError(t, err)
347347

348-
var resultNames []string
348+
resultNames := make([]string, 0, len(result))
349349
for _, c := range result {
350350
resultNames = append(resultNames, filepath.Base(c.Path()))
351351
}

0 commit comments

Comments
 (0)