Skip to content

Commit b5e1260

Browse files
authored
feat: Adding govet alignment check (#4057)
* feat: Adding just `fieldalignment` lint * fix: Blindly implementing the alignment adjustments * fix: Addressing errors in test cases * fix: More alignment fixes * fix: Addressing more errors in test cases * fix: Dropping unnecessary bottom values * fix: Fixing accidental drift in tests * fix: Restoring accidentally removed comments * fix: Fixing more accidental changes from addressing the lint findings * fix: Addressing more comment removals * fix: Addressing more unnecessary bottom values * fix: Addressing more removed comments * fix: Fixing test * fix: More test fixes * fix: Correcting `TestNewMatchingChecksumAuthentication` breakage * fix: Correcting `TestMatchesAny`
1 parent 03cacad commit b5e1260

121 files changed

Lines changed: 1918 additions & 2089 deletions

File tree

Some content is hidden

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

.golangci.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ linters-settings:
3030
goconst:
3131
min-len: 3
3232
min-occurrences: 5
33-
revive:
34-
min-confidence: 0.8
35-
unused:
36-
check-exported: false
3733
unparam:
3834
check-exported: false
3935
nakedret:
@@ -48,6 +44,9 @@ linters-settings:
4844
- performance
4945
disabled-tags:
5046
- experimental
47+
govet:
48+
enable:
49+
- fieldalignment
5150

5251
linters:
5352
enable:
@@ -82,8 +81,6 @@ linters:
8281
- recvcheck # In the latest version of golangci-lint this https://github.com/raeperd/recvcheck/issues/7 issue is not fixed yet.
8382

8483
fast: false
85-
mnd:
86-
ignored-functions: strconv.Format*,os.*,strconv.Parse*,strings.SplitN,bytes.SplitN
8784
presets:
8885
- bugs
8986
- performance
@@ -93,6 +90,7 @@ linters:
9390
# - style
9491
# - complexity
9592

93+
9694
issues:
9795
exclude-dirs:
9896
- docs

.strict.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ linters-settings:
5353
- performance
5454
disabled-tags:
5555
- experimental
56+
govet:
57+
enable:
58+
- fieldalignment
5659

5760
linters:
5861
enable:

awshelper/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ import (
2424

2525
// AwsSessionConfig is a representation of the configuration options for an AWS Session
2626
type AwsSessionConfig struct {
27+
Tags map[string]string
2728
Region string
2829
CustomS3Endpoint string
2930
CustomDynamoDBEndpoint string
3031
Profile string
3132
RoleArn string
3233
CredsFilename string
33-
S3ForcePathStyle bool
34-
DisableComputeChecksums bool
3534
ExternalID string
3635
SessionName string
37-
Tags map[string]string
36+
S3ForcePathStyle bool
37+
DisableComputeChecksums bool
3838
}
3939

4040
// addUserAgent - Add terragrunt version to the user agent for AWS API calls.

awshelper/policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ type Policy struct {
1313
// https://docs.aws.amazon.com/IAM//latest/UserGuide/reference_policies_elements_action.html
1414
// https://docs.aws.amazon.com/IAM//latest/UserGuide/reference_policies_elements_resource.html
1515
type Statement struct {
16-
Sid string `json:"Sid"`
17-
Effect string `json:"Effect"`
1816
Principal any `json:"Principal,omitempty"`
1917
NotPrincipal any `json:"NotPrincipal,omitempty"`
2018
Action any `json:"Action"`
2119
Resource any `json:"Resource"`
2220
Condition *map[string]any `json:"Condition,omitempty"`
21+
Sid string `json:"Sid"`
22+
Effect string `json:"Effect"`
2323
}
2424

2525
func UnmarshalPolicy(policy string) (Policy, error) {

cli/app_test.go

Lines changed: 132 additions & 97 deletions
Large diffs are not rendered by default.

cli/commands/aws-provider-patch/aws-provider-patch_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -287,30 +287,30 @@ func TestPatchAwsProviderInTerraformCodeHappyPath(t *testing.T) {
287287
t.Parallel()
288288

289289
testCases := []struct {
290+
attributesToOverride map[string]string
290291
testName string
291292
originalTerraformCode string
292-
attributesToOverride map[string]string
293-
expectedCodeWasUpdated bool
294293
expectedTerraformCode []string
294+
expectedCodeWasUpdated bool
295295
}{
296-
{"empty", "", nil, false, []string{""}},
297-
{"empty with attributes", "", map[string]string{"region": `"eu-west-1"`}, false, []string{""}},
298-
{"no provider", terraformCodeExampleOutputOnly, map[string]string{"region": `"eu-west-1"`}, false, []string{terraformCodeExampleOutputOnly}},
299-
{"no aws provider", terraformCodeExampleGcpProvider, map[string]string{"region": `"eu-west-1"`}, false, []string{terraformCodeExampleGcpProvider}},
300-
{"one empty aws provider, but no overrides", terraformCodeExampleAwsProviderEmptyOriginal, nil, false, []string{terraformCodeExampleAwsProviderEmptyOriginal}},
301-
{"one empty aws provider, with region override", terraformCodeExampleAwsProviderEmptyOriginal, map[string]string{"region": `"eu-west-1"`}, false, []string{terraformCodeExampleAwsProviderEmptyOriginal}},
302-
{"one empty aws provider, with region, version override", terraformCodeExampleAwsProviderEmptyOriginal, map[string]string{"region": `"eu-west-1"`, "version": `"0.3.0"`}, false, []string{terraformCodeExampleAwsProviderEmptyOriginal}},
303-
{"one non-empty aws provider, but no overrides", terraformCodeExampleAwsProviderNonEmptyOriginal, nil, false, []string{terraformCodeExampleAwsProviderNonEmptyOriginal}},
304-
{"one non-empty aws provider, with region override", terraformCodeExampleAwsProviderNonEmptyOriginal, map[string]string{"region": `"eu-west-1"`}, true, []string{terraformCodeExampleAwsProviderRegionOverridenVersionNotOverriddenExpected}},
305-
{"one non-empty aws provider, with region, version override", terraformCodeExampleAwsProviderNonEmptyOriginal, map[string]string{"region": `"eu-west-1"`, "version": `"0.3.0"`}, true, []string{terraformCodeExampleAwsProviderRegionVersionOverridenExpected, terraformCodeExampleAwsProviderRegionVersionOverridenReverseOrderExpected}},
306-
{"multiple providers, but no overrides", terraformCodeExampleAwsMultipleProvidersOriginal, nil, false, []string{terraformCodeExampleAwsMultipleProvidersOriginal}},
307-
{"multiple providers, with region override", terraformCodeExampleAwsMultipleProvidersOriginal, map[string]string{"region": `"eu-west-1"`}, true, []string{terraformCodeExampleAwsMultipleProvidersRegionOverridenExpected}},
308-
{"multiple providers, with region, version override", terraformCodeExampleAwsMultipleProvidersOriginal, map[string]string{"region": `"eu-west-1"`, "version": `"0.3.0"`}, true, []string{terraformCodeExampleAwsMultipleProvidersRegionVersionOverridenExpected}},
309-
{"multiple providers with comments, but no overrides", terraformCodeExampleAwsMultipleProvidersNonEmptyWithCommentsOriginal, nil, false, []string{terraformCodeExampleAwsMultipleProvidersNonEmptyWithCommentsOriginal}},
310-
{"multiple providers with comments, with region override", terraformCodeExampleAwsMultipleProvidersNonEmptyWithCommentsOriginal, map[string]string{"region": `"eu-west-1"`}, true, []string{terraformCodeExampleAwsMultipleProvidersNonEmptyWithCommentsRegionOverriddenExpected}},
311-
{"multiple providers with comments, with region, version override", terraformCodeExampleAwsMultipleProvidersNonEmptyWithCommentsOriginal, map[string]string{"region": `"eu-west-1"`, "version": `"0.3.0"`}, true, []string{terraformCodeExampleAwsMultipleProvidersNonEmptyWithCommentsRegionVersionOverriddenExpected}},
312-
{"one provider with nested blocks, with region and role_arn override", terraformCodeExampleAwsOneProviderNestedBlocks, map[string]string{"region": `"eu-west-1"`, "assume_role.role_arn": `"nested-override"`}, true, []string{terraformCodeExampleAwsOneProviderNestedBlocksRegionRoleArnExpected}},
313-
{"one provider with nested blocks, with region and role_arn override, plus non-matching overrides", terraformCodeExampleAwsOneProviderNestedBlocks, map[string]string{"region": `"eu-west-1"`, "assume_role.role_arn": `"nested-override"`, "should-be": `"ignored"`, "assume_role.should-be": `"ignored"`}, true, []string{terraformCodeExampleAwsOneProviderNestedBlocksRegionRoleArnExpected}},
296+
{testName: "empty", originalTerraformCode: "", attributesToOverride: nil, expectedCodeWasUpdated: false, expectedTerraformCode: []string{""}},
297+
{testName: "empty with attributes", originalTerraformCode: "", attributesToOverride: map[string]string{"region": `"eu-west-1"`}, expectedCodeWasUpdated: false, expectedTerraformCode: []string{""}},
298+
{testName: "no provider", originalTerraformCode: terraformCodeExampleOutputOnly, attributesToOverride: map[string]string{"region": `"eu-west-1"`}, expectedCodeWasUpdated: false, expectedTerraformCode: []string{terraformCodeExampleOutputOnly}},
299+
{testName: "no aws provider", originalTerraformCode: terraformCodeExampleGcpProvider, attributesToOverride: map[string]string{"region": `"eu-west-1"`}, expectedCodeWasUpdated: false, expectedTerraformCode: []string{terraformCodeExampleGcpProvider}},
300+
{testName: "one empty aws provider, but no overrides", originalTerraformCode: terraformCodeExampleAwsProviderEmptyOriginal, attributesToOverride: nil, expectedCodeWasUpdated: false, expectedTerraformCode: []string{terraformCodeExampleAwsProviderEmptyOriginal}},
301+
{testName: "one empty aws provider, with region override", originalTerraformCode: terraformCodeExampleAwsProviderEmptyOriginal, attributesToOverride: map[string]string{"region": `"eu-west-1"`}, expectedCodeWasUpdated: false, expectedTerraformCode: []string{terraformCodeExampleAwsProviderEmptyOriginal}},
302+
{testName: "one empty aws provider, with region, version override", originalTerraformCode: terraformCodeExampleAwsProviderEmptyOriginal, attributesToOverride: map[string]string{"region": `"eu-west-1"`, "version": `"0.3.0"`}, expectedCodeWasUpdated: false, expectedTerraformCode: []string{terraformCodeExampleAwsProviderEmptyOriginal}},
303+
{testName: "one non-empty aws provider, but no overrides", originalTerraformCode: terraformCodeExampleAwsProviderNonEmptyOriginal, attributesToOverride: nil, expectedCodeWasUpdated: false, expectedTerraformCode: []string{terraformCodeExampleAwsProviderNonEmptyOriginal}},
304+
{testName: "one non-empty aws provider, with region override", originalTerraformCode: terraformCodeExampleAwsProviderNonEmptyOriginal, attributesToOverride: map[string]string{"region": `"eu-west-1"`}, expectedCodeWasUpdated: true, expectedTerraformCode: []string{terraformCodeExampleAwsProviderRegionOverridenVersionNotOverriddenExpected}},
305+
{testName: "one non-empty aws provider, with region, version override", originalTerraformCode: terraformCodeExampleAwsProviderNonEmptyOriginal, attributesToOverride: map[string]string{"region": `"eu-west-1"`, "version": `"0.3.0"`}, expectedCodeWasUpdated: true, expectedTerraformCode: []string{terraformCodeExampleAwsProviderRegionVersionOverridenExpected, terraformCodeExampleAwsProviderRegionVersionOverridenReverseOrderExpected}},
306+
{testName: "multiple providers, but no overrides", originalTerraformCode: terraformCodeExampleAwsMultipleProvidersOriginal, attributesToOverride: nil, expectedCodeWasUpdated: false, expectedTerraformCode: []string{terraformCodeExampleAwsMultipleProvidersOriginal}},
307+
{testName: "multiple providers, with region override", originalTerraformCode: terraformCodeExampleAwsMultipleProvidersOriginal, attributesToOverride: map[string]string{"region": `"eu-west-1"`}, expectedCodeWasUpdated: true, expectedTerraformCode: []string{terraformCodeExampleAwsMultipleProvidersRegionOverridenExpected}},
308+
{testName: "multiple providers, with region, version override", originalTerraformCode: terraformCodeExampleAwsMultipleProvidersOriginal, attributesToOverride: map[string]string{"region": `"eu-west-1"`, "version": `"0.3.0"`}, expectedCodeWasUpdated: true, expectedTerraformCode: []string{terraformCodeExampleAwsMultipleProvidersRegionVersionOverridenExpected}},
309+
{testName: "multiple providers with comments, but no overrides", originalTerraformCode: terraformCodeExampleAwsMultipleProvidersNonEmptyWithCommentsOriginal, attributesToOverride: nil, expectedCodeWasUpdated: false, expectedTerraformCode: []string{terraformCodeExampleAwsMultipleProvidersNonEmptyWithCommentsOriginal}},
310+
{testName: "multiple providers with comments, with region override", originalTerraformCode: terraformCodeExampleAwsMultipleProvidersNonEmptyWithCommentsOriginal, attributesToOverride: map[string]string{"region": `"eu-west-1"`}, expectedCodeWasUpdated: true, expectedTerraformCode: []string{terraformCodeExampleAwsMultipleProvidersNonEmptyWithCommentsRegionOverriddenExpected}},
311+
{testName: "multiple providers with comments, with region, version override", originalTerraformCode: terraformCodeExampleAwsMultipleProvidersNonEmptyWithCommentsOriginal, attributesToOverride: map[string]string{"region": `"eu-west-1"`, "version": `"0.3.0"`}, expectedCodeWasUpdated: true, expectedTerraformCode: []string{terraformCodeExampleAwsMultipleProvidersNonEmptyWithCommentsRegionVersionOverriddenExpected}},
312+
{testName: "one provider with nested blocks, with region and role_arn override", originalTerraformCode: terraformCodeExampleAwsOneProviderNestedBlocks, attributesToOverride: map[string]string{"region": `"eu-west-1"`, "assume_role.role_arn": `"nested-override"`}, expectedCodeWasUpdated: true, expectedTerraformCode: []string{terraformCodeExampleAwsOneProviderNestedBlocksRegionRoleArnExpected}},
313+
{testName: "one provider with nested blocks, with region and role_arn override, plus non-matching overrides", originalTerraformCode: terraformCodeExampleAwsOneProviderNestedBlocks, attributesToOverride: map[string]string{"region": `"eu-west-1"`, "assume_role.role_arn": `"nested-override"`, "should-be": `"ignored"`, "assume_role.should-be": `"ignored"`}, expectedCodeWasUpdated: true, expectedTerraformCode: []string{terraformCodeExampleAwsOneProviderNestedBlocksRegionRoleArnExpected}},
314314
}
315315

316316
for _, testCase := range testCases {

cli/commands/aws-provider-patch/errors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ func (flagName MissingOverrideAttrError) Error() string {
99
}
1010

1111
type TypeInferenceError struct {
12-
value string
1312
underlyingErr error
13+
value string
1414
}
1515

1616
func (err TypeInferenceError) Error() string {
@@ -19,8 +19,8 @@ func (err TypeInferenceError) Error() string {
1919
}
2020

2121
type MalformedJSONValError struct {
22-
value string
2322
underlyingErr error
23+
value string
2424
}
2525

2626
func (err MalformedJSONValError) Error() string {

cli/commands/catalog/module/doc.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,13 @@ func (regs DocRegs) Replace(str string) string {
4545
}
4646

4747
type Doc struct {
48-
rawContent string
49-
fileExt string
50-
51-
tagCache map[docDataKey]string
52-
tagRegs map[docTagName]*regexp.Regexp
53-
tagStripRegs DocRegs
54-
48+
tagCache map[docDataKey]string
49+
tagRegs map[docTagName]*regexp.Regexp
5550
frontmatterCache map[docDataKey]string
5651
frontmatterReg *regexp.Regexp
52+
rawContent string
53+
fileExt string
54+
tagStripRegs DocRegs
5755
}
5856

5957
func NewDoc(rawContent, fileExt string) *Doc {

cli/commands/catalog/module/doc_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -184,37 +184,37 @@ func TestElement(t *testing.T) {
184184
testCases := []struct {
185185
content string
186186
fileExt string
187-
maxDescriptionLength int
188187
expectedTitle string
189188
expectedDescription string
189+
maxDescriptionLength int
190190
}{
191191
{
192-
testH1EksK8sArgocd,
193-
".md",
194-
200,
195-
"EKS K8s GitOps Module",
196-
"This module deploys Argo CD to an EKS cluster. Argo CD is a declarative GitOps continuous delivery tool for Kubernetes. See the Argo CD for more details.",
192+
content: testH1EksK8sArgocd,
193+
fileExt: ".md",
194+
maxDescriptionLength: 200,
195+
expectedTitle: "EKS K8s GitOps Module",
196+
expectedDescription: "This module deploys Argo CD to an EKS cluster. Argo CD is a declarative GitOps continuous delivery tool for Kubernetes. See the Argo CD for more details.",
197197
},
198198
{
199-
testH1EksCloudwatchAgent,
200-
".md",
201-
200,
202-
"EKS CloudWatch Agent Module",
203-
"This Terraform Module installs and configures Amazon CloudWatch Agent on an EKS cluster, so that each node runs the agent to collect more system-level metrics from Amazon EC2 instances and ship them to Amazon CloudWatch.",
199+
content: testH1EksCloudwatchAgent,
200+
fileExt: ".md",
201+
maxDescriptionLength: 200,
202+
expectedTitle: "EKS CloudWatch Agent Module",
203+
expectedDescription: "This Terraform Module installs and configures Amazon CloudWatch Agent on an EKS cluster, so that each node runs the agent to collect more system-level metrics from Amazon EC2 instances and ship them to Amazon CloudWatch.",
204204
},
205205
{
206-
testH1EcsCluster,
207-
".md",
208-
200,
209-
"Amazon ECS Cluster",
210-
"This service contains Terraform code to deploy a production-grade ECS cluster on AWS using Elastic Container Service (ECS).",
206+
content: testH1EcsCluster,
207+
fileExt: ".md",
208+
maxDescriptionLength: 200,
209+
expectedTitle: "Amazon ECS Cluster",
210+
expectedDescription: "This service contains Terraform code to deploy a production-grade ECS cluster on AWS using Elastic Container Service (ECS).",
211211
},
212212
{
213-
testH1EksAWSAuthMerger,
214-
".adoc",
215-
200,
216-
"EKS AWS Auth Merger",
217-
"This module contains a go CLI, docker container, and terraform module for deploying a Kubernetes controller for managing mappings between AWS IAM roles and users to RBAC groups in Kubernetes.",
213+
content: testH1EksAWSAuthMerger,
214+
fileExt: ".adoc",
215+
maxDescriptionLength: 200,
216+
expectedTitle: "EKS AWS Auth Merger",
217+
expectedDescription: "This module contains a go CLI, docker container, and terraform module for deploying a Kubernetes controller for managing mappings between AWS IAM roles and users to RBAC groups in Kubernetes.",
218218
},
219219
}
220220

cli/commands/catalog/module/repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ func (repo *Repo) ModuleURL(moduleDir string) (string, error) {
170170
}
171171

172172
type CloneOptions struct {
173-
SourceURL string
174-
TargetPath string
175173
Context context.Context
176174
Logger log.Logger
175+
SourceURL string
176+
TargetPath string
177177
}
178178

179179
func (repo *Repo) clone(ctx context.Context, l log.Logger) error {

0 commit comments

Comments
 (0)