Skip to content

Commit 2e0e80d

Browse files
authored
chore: Upgrade golangci-lint to v2.8.0 (#5365)
* fix: Upgrading `golangci-lint` to `2.8.0` * fix: Adding `run-lint-fix` recipe * fix: Running auto lint fixes * fix: More involved lint fixes * chore: Removing disabled lints * chore: Removing disabled checks for gocritic * fix: Addressing removal of disabled checks for gocritic * fix: Addressing errors * fix: Fixing config methods * fix: Fixing more pointer semantics * fix: Adding parsing recursion limit * fix: Adjusting context usage, as tests were resulting in stack overflows * fix: Addressing lint * fix: Making runner pool controller more reliable * fix: Fixing stack overflow from context * fix: Fixing parse test * fix: Avoiding recursive credential resolution
1 parent 8132e54 commit 2e0e80d

File tree

89 files changed

+478
-246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+478
-246
lines changed

.golangci.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,6 @@ linters:
5555
- wastedassign
5656
- wsl_v5
5757
- zerologlint
58-
disable:
59-
- depguard
60-
- exhaustruct
61-
- gocyclo
62-
- gosec
63-
- nolintlint
64-
- recvcheck
65-
- varnamelen
66-
- wrapcheck
6758
settings:
6859
dupl:
6960
threshold: 120
@@ -80,11 +71,6 @@ linters:
8071
min-len: 3
8172
min-occurrences: 5
8273
gocritic:
83-
disabled-checks:
84-
- regexpMust
85-
- rangeValCopy
86-
- appendAssign
87-
- hugeParam
8874
enabled-tags:
8975
- performance
9076
disabled-tags:

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ run-lint:
3939
@echo "Linting with feature flags: [$(LINT_TAGS)]"
4040
GOFLAGS="-tags=$(LINT_TAGS)" golangci-lint run -v --timeout=10m ./...
4141

42+
run-lint-fix:
43+
@echo "Linting with feature flags: [$(LINT_TAGS)]"
44+
GOFLAGS="-tags=$(LINT_TAGS)" golangci-lint run -v --timeout=10m --fix ./...
45+
4246
run-strict-lint:
4347
golangci-lint run -v --timeout=10m -c .strict.golangci.yml --new-from-rev origin/main ./...
4448

@@ -51,4 +55,4 @@ license-check:
5155
licensei check --debug
5256
licensei header --debug
5357

54-
.PHONY: help fmt fmtcheck install-pre-commit-hook clean run-lint run-strict-lint
58+
.PHONY: help fmt fmtcheck install-pre-commit-hook clean run-lint run-lint-fix run-strict-lint

internal/awshelper/config.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,19 +276,19 @@ func AssumeIamRole(
276276
}
277277

278278
// GetAWSCallerIdentity gets the caller identity from AWS
279-
func GetAWSCallerIdentity(ctx context.Context, cfg aws.Config) (*sts.GetCallerIdentityOutput, error) {
280-
stsClient := sts.NewFromConfig(cfg)
279+
func GetAWSCallerIdentity(ctx context.Context, cfg *aws.Config) (*sts.GetCallerIdentityOutput, error) {
280+
stsClient := sts.NewFromConfig(*cfg)
281281
return stsClient.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
282282
}
283283

284284
// ValidateAwsConfig validates that the AWS config has valid credentials
285-
func ValidateAwsConfig(ctx context.Context, cfg aws.Config) error {
285+
func ValidateAwsConfig(ctx context.Context, cfg *aws.Config) error {
286286
_, err := GetAWSCallerIdentity(ctx, cfg)
287287
return err
288288
}
289289

290290
// GetAWSPartition gets the AWS partition from the caller identity
291-
func GetAWSPartition(ctx context.Context, cfg aws.Config) (string, error) {
291+
func GetAWSPartition(ctx context.Context, cfg *aws.Config) (string, error) {
292292
result, err := GetAWSCallerIdentity(ctx, cfg)
293293
if err != nil {
294294
return "", err
@@ -310,8 +310,8 @@ func GetAWSPartition(ctx context.Context, cfg aws.Config) (string, error) {
310310
}
311311

312312
// GetAWSAccountAlias gets the AWS account alias
313-
func GetAWSAccountAlias(ctx context.Context, cfg aws.Config) (string, error) {
314-
iamClient := iam.NewFromConfig(cfg)
313+
func GetAWSAccountAlias(ctx context.Context, cfg *aws.Config) (string, error) {
314+
iamClient := iam.NewFromConfig(*cfg)
315315

316316
result, err := iamClient.ListAccountAliases(ctx, &iam.ListAccountAliasesInput{})
317317
if err != nil {
@@ -326,7 +326,7 @@ func GetAWSAccountAlias(ctx context.Context, cfg aws.Config) (string, error) {
326326
}
327327

328328
// GetAWSAccountID gets the AWS account ID from the caller identity
329-
func GetAWSAccountID(ctx context.Context, cfg aws.Config) (string, error) {
329+
func GetAWSAccountID(ctx context.Context, cfg *aws.Config) (string, error) {
330330
result, err := GetAWSCallerIdentity(ctx, cfg)
331331
if err != nil {
332332
return "", err
@@ -336,7 +336,7 @@ func GetAWSAccountID(ctx context.Context, cfg aws.Config) (string, error) {
336336
}
337337

338338
// GetAWSIdentityArn gets the AWS identity ARN from the caller identity
339-
func GetAWSIdentityArn(ctx context.Context, cfg aws.Config) (string, error) {
339+
func GetAWSIdentityArn(ctx context.Context, cfg *aws.Config) (string, error) {
340340
result, err := GetAWSCallerIdentity(ctx, cfg)
341341
if err != nil {
342342
return "", err
@@ -346,7 +346,7 @@ func GetAWSIdentityArn(ctx context.Context, cfg aws.Config) (string, error) {
346346
}
347347

348348
// GetAWSUserID gets the AWS user ID from the caller identity
349-
func GetAWSUserID(ctx context.Context, cfg aws.Config) (string, error) {
349+
func GetAWSUserID(ctx context.Context, cfg *aws.Config) (string, error) {
350350
result, err := GetAWSCallerIdentity(ctx, cfg)
351351
if err != nil {
352352
return "", err
@@ -369,6 +369,7 @@ func ValidatePublicAccessBlock(output *s3.GetPublicAccessBlockOutput) (bool, err
369369
aws.ToBool(config.RestrictPublicBuckets), nil
370370
}
371371

372+
//nolint:gocritic // hugeParam: intentionally pass by value to avoid recursive credential resolution
372373
func getWebIdentityCredentialsFromIAMRoleOptions(cfg aws.Config, iamRoleOptions options.IAMRoleOptions) aws.CredentialsProviderFunc {
373374
roleSessionName := iamRoleOptions.AssumeRoleSessionName
374375
if roleSessionName == "" {
@@ -411,6 +412,7 @@ func getWebIdentityCredentialsFromIAMRoleOptions(cfg aws.Config, iamRoleOptions
411412
}
412413
}
413414

415+
//nolint:gocritic // hugeParam: intentionally pass by value to avoid recursive credential resolution
414416
func getSTSCredentialsFromIAMRoleOptions(cfg aws.Config, iamRoleOptions options.IAMRoleOptions, externalID string) aws.CredentialsProviderFunc {
415417
return func(ctx context.Context) (aws.Credentials, error) {
416418
stsClient := sts.NewFromConfig(cfg)

internal/cas/tree_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func TestLinkTree(t *testing.T) {
215215

216216
storeDir := helpers.TmpDirWOSymlinks(t)
217217
store := cas.NewStore(storeDir)
218+
218219
return store, ""
219220
},
220221
treeData: []byte(""),
@@ -232,6 +233,7 @@ func TestLinkTree(t *testing.T) {
232233

233234
storeDir := helpers.TmpDirWOSymlinks(t)
234235
store := cas.NewStore(storeDir)
236+
235237
return store, ""
236238
},
237239
treeData: []byte(`100644 blob missing123 README.md`),

internal/cli/app_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,15 @@ func TestParseTerragruntOptionsFromArgs(t *testing.T) {
452452
assert.EqualError(t, actualErr, tc.expectedErr.Error())
453453
} else {
454454
require.NoError(t, actualErr)
455-
assertOptionsEqual(t, *tc.expectedOptions, *actualOptions, "For args %v", tc.args)
455+
assertOptionsEqual(t, tc.expectedOptions, actualOptions, "For args %v", tc.args)
456456
}
457457
})
458458
}
459459
}
460460

461461
// We can't do a direct comparison between TerragruntOptions objects because we can't compare Logger or RunTerragrunt
462462
// instances. Therefore, we have to manually check everything else.
463-
func assertOptionsEqual(t *testing.T, expected options.TerragruntOptions, actual options.TerragruntOptions, msgAndArgs ...any) {
463+
func assertOptionsEqual(t *testing.T, expected *options.TerragruntOptions, actual *options.TerragruntOptions, msgAndArgs ...any) {
464464
t.Helper()
465465

466466
// Normalize path separators for cross-platform compatibility

internal/cli/commands/catalog/tui/keys.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type delegateKeyMap struct {
8080

8181
// Additional short help entries. This satisfies the help.KeyMap interface and
8282
// is entirely optional.
83-
func (d delegateKeyMap) ShortHelp() []key.Binding {
83+
func (d delegateKeyMap) ShortHelp() []key.Binding { //nolint:gocritic
8484
return []key.Binding{
8585
d.choose,
8686
d.scaffold,
@@ -89,7 +89,7 @@ func (d delegateKeyMap) ShortHelp() []key.Binding {
8989

9090
// Additional full help entries. This satisfies the help.KeyMap interface and
9191
// is entirely optional.
92-
func (d delegateKeyMap) FullHelp() [][]key.Binding {
92+
func (d delegateKeyMap) FullHelp() [][]key.Binding { //nolint:gocritic
9393
return [][]key.Binding{
9494
{
9595
d.choose,
@@ -143,7 +143,7 @@ type pagerKeyMap struct {
143143

144144
// ShortHelp returns keybindings to be shown in the mini help view. It's part
145145
// of the key.Map interface.
146-
func (keys pagerKeyMap) ShortHelp() []key.Binding {
146+
func (keys pagerKeyMap) ShortHelp() []key.Binding { //nolint:gocritic
147147
return []key.Binding{
148148
keys.Up,
149149
keys.Down,
@@ -158,7 +158,7 @@ func (keys pagerKeyMap) ShortHelp() []key.Binding {
158158

159159
// FullHelp returns keybindings for the expanded help view. It's part of the
160160
// key.Map interface.
161-
func (keys pagerKeyMap) FullHelp() [][]key.Binding {
161+
func (keys pagerKeyMap) FullHelp() [][]key.Binding { //nolint:gocritic
162162
return [][]key.Binding{
163163
{keys.Up, keys.Down, keys.PageDown, keys.PageUp}, // first column
164164
{keys.Navigation, keys.NavigationBack, keys.Choose, keys.Scaffold}, // second column

internal/cli/commands/catalog/tui/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func NewModel(l log.Logger, opts *options.TerragruntOptions, svc catalog.Catalog
117117
}
118118

119119
// Init implements bubbletea.Model.Init
120-
func (m Model) Init() tea.Cmd {
120+
func (m Model) Init() tea.Cmd { //nolint:gocritic
121121
return tea.Batch(
122122
m.buttonBar.Init(),
123123
)

internal/cli/commands/catalog/tui/update.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/gruntwork-io/terragrunt/pkg/log"
1919
)
2020

21-
func updateList(msg tea.Msg, m Model) (tea.Model, tea.Cmd) {
21+
func updateList(msg tea.Msg, m Model) (tea.Model, tea.Cmd) { //nolint:gocritic
2222
var (
2323
cmd tea.Cmd
2424
cmds []tea.Cmd
@@ -107,7 +107,7 @@ func updateList(msg tea.Msg, m Model) (tea.Model, tea.Cmd) {
107107
return m, cmd
108108
}
109109

110-
func updatePager(msg tea.Msg, m Model) (tea.Model, tea.Cmd) {
110+
func updatePager(msg tea.Msg, m Model) (tea.Model, tea.Cmd) { //nolint:gocritic
111111
var (
112112
cmd tea.Cmd
113113
cmds []tea.Cmd
@@ -168,7 +168,7 @@ func updatePager(msg tea.Msg, m Model) (tea.Model, tea.Cmd) {
168168
}
169169

170170
// Update handles all TUI interactions and implements bubbletea.Model.Update.
171-
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
171+
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { //nolint:gocritic
172172
switch msg := msg.(type) {
173173
case tea.WindowSizeMsg:
174174
h, v := appStyle.GetFrameSize()
@@ -229,7 +229,7 @@ func rendererErrCmd(err error) tea.Cmd {
229229
type scaffoldFinishedMsg struct{ err error }
230230

231231
// Return a tea.Cmd that will scaffold the given module.
232-
func scaffoldModuleCmd(l log.Logger, m Model, svc catalog.CatalogService, module *module.Module) tea.Cmd {
232+
func scaffoldModuleCmd(l log.Logger, m Model, svc catalog.CatalogService, module *module.Module) tea.Cmd { //nolint:gocritic
233233
return tea.Exec(command.NewScaffold(l, m.terragruntOptions, svc, module), func(err error) tea.Msg {
234234
return scaffoldFinishedMsg{err}
235235
})

internal/cli/commands/catalog/tui/view.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var (
1616

1717
// View is the main view, which just calls the appropriate sub-view and returns a string representation of the TUI
1818
// based on the application's state.
19-
func (m Model) View() string {
19+
func (m Model) View() string { //nolint:gocritic
2020
var s string
2121

2222
switch m.State {
@@ -32,15 +32,15 @@ func (m Model) View() string {
3232
return s
3333
}
3434

35-
func (m Model) listView() string {
35+
func (m Model) listView() string { //nolint:gocritic
3636
return m.List.View()
3737
}
3838

39-
func (m Model) pagerView() string {
39+
func (m Model) pagerView() string { //nolint:gocritic
4040
return lipgloss.JoinVertical(lipgloss.Left, m.viewport.View(), m.footerView())
4141
}
4242

43-
func (m Model) footerView() string {
43+
func (m Model) footerView() string { //nolint:gocritic
4444
var percent float64 = 100
4545

4646
info := infoPositionStyle.Render(fmt.Sprintf("%2.f%%", m.viewport.ScrollPercent()*percent))

internal/cli/commands/find/cli.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func NewFlags(l log.Logger, opts *Options, prefix flags.Prefix) clihelper.Flags
9999
}
100100

101101
opts.FilterQueries = append(opts.FilterQueries, "{./**}...")
102+
102103
return nil
103104
},
104105
}),

0 commit comments

Comments
 (0)