Skip to content

Commit

Permalink
chore: add gofmt to golangci-lint in Makefile and .github/workflows/c…
Browse files Browse the repository at this point in the history
…i-build.yaml (#13729)

* fix: add gofmt to golangci-lint in Makefile and .github/workflows/ci-build.yaml

Signed-off-by: Denis Dupeyron <[email protected]>

* fix go formatting issues using gofmt

Signed-off-by: Denis Dupeyron <[email protected]>

* chore: simplify go code using gofmt

Signed-off-by: Denis Dupeyron <[email protected]>

---------

Signed-off-by: Denis Dupeyron <[email protected]>
  • Loading branch information
Calchan authored Jul 5, 2023
1 parent f0b8ffb commit 4a50a31
Show file tree
Hide file tree
Showing 24 changed files with 102 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
uses: golangci/golangci-lint-action@639cd343e1d3b897ff35927a75193d57cfcba299 # v3.6.0
with:
version: v1.51.0
args: --timeout 10m --exclude SA5011 --verbose
args: --enable gofmt --timeout 10m --exclude SA5011 --verbose --max-issues-per-linter 0 --max-same-issues 0

test-go:
name: Run unit tests for Go packages
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ lint-local:
golangci-lint --version
# NOTE: If you get a "Killed" OOM message, try reducing the value of GOGC
# See https://github.com/golangci/golangci-lint#memory-usage-of-golangci-lint
GOGC=$(ARGOCD_LINT_GOGC) GOMAXPROCS=2 golangci-lint run --fix --verbose --timeout 3000s
GOGC=$(ARGOCD_LINT_GOGC) GOMAXPROCS=2 golangci-lint run --enable gofmt --fix --verbose --timeout 3000s --max-issues-per-linter 0 --max-same-issues 0

.PHONY: lint-ui
lint-ui: test-tools-image
Expand Down Expand Up @@ -651,4 +651,4 @@ help:
@echo 'codegen:'
@echo ' codegen(-local) -- if using -local, run the following targets first'
@echo ' install-codegen-tools-local -- run this to install the codegen tools'
@echo ' install-go-tools-local -- run this to install go libraries for codegen'
@echo ' install-go-tools-local -- run this to install go libraries for codegen'
2 changes: 1 addition & 1 deletion applicationset/generators/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (g *ListGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.Appli
if err != nil {
return nil, fmt.Errorf("error unmarshling decoded ElementsYaml %v", err)
}
res = append(res, yamlElements...)
res = append(res, yamlElements...)
}

return res, nil
Expand Down
10 changes: 5 additions & 5 deletions applicationset/generators/pull_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
return pullrequest.NewFakeService(
ctx,
[]*pullrequest.PullRequest{
&pullrequest.PullRequest{
{
Number: 1,
Branch: "branch1",
TargetBranch: "master",
Expand Down Expand Up @@ -56,7 +56,7 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
return pullrequest.NewFakeService(
ctx,
[]*pullrequest.PullRequest{
&pullrequest.PullRequest{
{
Number: 2,
Branch: "feat/areally+long_pull_request_name_to_test_argo_slugification_and_branch_name_shortening_feature",
TargetBranch: "feat/anotherreally+long_pull_request_name_to_test_argo_slugification_and_branch_name_shortening_feature",
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
return pullrequest.NewFakeService(
ctx,
[]*pullrequest.PullRequest{
&pullrequest.PullRequest{
{
Number: 1,
Branch: "a-very-short-sha",
TargetBranch: "master",
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
return pullrequest.NewFakeService(
ctx,
[]*pullrequest.PullRequest{
&pullrequest.PullRequest{
{
Number: 1,
Branch: "branch1",
TargetBranch: "master",
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
return pullrequest.NewFakeService(
ctx,
[]*pullrequest.PullRequest{
&pullrequest.PullRequest{
{
Number: 1,
Branch: "branch1",
TargetBranch: "master",
Expand Down
32 changes: 16 additions & 16 deletions applicationset/generators/scm_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,26 @@ func TestSCMProviderGenerateParams(t *testing.T) {
},
expected: []map[string]interface{}{
{
"organization": "myorg",
"repository": "repo1",
"url": "[email protected]:myorg/repo1.git",
"branch": "main",
"organization": "myorg",
"repository": "repo1",
"url": "[email protected]:myorg/repo1.git",
"branch": "main",
"branchNormalized": "main",
"sha": "0bc57212c3cbbec69d20b34c507284bd300def5b",
"short_sha": "0bc57212",
"short_sha_7": "0bc5721",
"labels": "prod,staging",
"sha": "0bc57212c3cbbec69d20b34c507284bd300def5b",
"short_sha": "0bc57212",
"short_sha_7": "0bc5721",
"labels": "prod,staging",
},
{
"organization": "myorg",
"repository": "repo2",
"url": "[email protected]:myorg/repo2.git",
"branch": "main",
"organization": "myorg",
"repository": "repo2",
"url": "[email protected]:myorg/repo2.git",
"branch": "main",
"branchNormalized": "main",
"sha": "59d0",
"short_sha": "59d0",
"short_sha_7": "59d0",
"labels": "",
"sha": "59d0",
"short_sha": "59d0",
"short_sha_7": "59d0",
"labels": "",
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions applicationset/services/pull_request/gitea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ func TestGetGiteaPRLabelNames(t *testing.T) {
{
Name: "PR has labels",
PullLabels: []*gitea.Label{
&gitea.Label{Name: "label1"},
&gitea.Label{Name: "label2"},
&gitea.Label{Name: "label3"},
{Name: "label1"},
{Name: "label2"},
{Name: "label3"},
},
ExpectedResult: []string{"label1", "label2", "label3"},
},
Expand Down
24 changes: 12 additions & 12 deletions applicationset/services/pull_request/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ func TestContainLabels(t *testing.T) {
Name: "Match labels",
Labels: []string{"label1", "label2"},
PullLabels: []*github.Label{
&github.Label{Name: toPtr("label1")},
&github.Label{Name: toPtr("label2")},
&github.Label{Name: toPtr("label3")},
{Name: toPtr("label1")},
{Name: toPtr("label2")},
{Name: toPtr("label3")},
},
Expect: true,
},
{
Name: "Not match labels",
Labels: []string{"label1", "label4"},
PullLabels: []*github.Label{
&github.Label{Name: toPtr("label1")},
&github.Label{Name: toPtr("label2")},
&github.Label{Name: toPtr("label3")},
{Name: toPtr("label1")},
{Name: toPtr("label2")},
{Name: toPtr("label3")},
},
Expect: false,
},
{
Name: "No specify",
Labels: []string{},
PullLabels: []*github.Label{
&github.Label{Name: toPtr("label1")},
&github.Label{Name: toPtr("label2")},
&github.Label{Name: toPtr("label3")},
{Name: toPtr("label1")},
{Name: toPtr("label2")},
{Name: toPtr("label3")},
},
Expect: true,
},
Expand All @@ -68,9 +68,9 @@ func TestGetGitHubPRLabelNames(t *testing.T) {
{
Name: "PR has labels",
PullLabels: []*github.Label{
&github.Label{Name: toPtr("label1")},
&github.Label{Name: toPtr("label2")},
&github.Label{Name: toPtr("label3")},
{Name: toPtr("label1")},
{Name: toPtr("label2")},
{Name: toPtr("label3")},
},
ExpectedResult: []string{"label1", "label2", "label3"},
},
Expand Down
1 change: 1 addition & 0 deletions assets/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package assets
import "embed"

// Embedded contains embedded assets
//
//go:embed *
var Embedded embed.FS
4 changes: 2 additions & 2 deletions cmd/argocd/commands/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ func Test_groupObjsByKey(t *testing.T) {
}

expected := map[kube.ResourceKey]*unstructured.Unstructured{
kube.ResourceKey{Group: "", Kind: "Pod", Namespace: "default", Name: "pod-name"}: localObjs[0],
kube.ResourceKey{Group: "apiextensions.k8s.io", Kind: "CustomResourceDefinition", Namespace: "", Name: "certificates.cert-manager.io"}: localObjs[1],
{Group: "", Kind: "Pod", Namespace: "default", Name: "pod-name"}: localObjs[0],
{Group: "apiextensions.k8s.io", Kind: "CustomResourceDefinition", Namespace: "", Name: "certificates.cert-manager.io"}: localObjs[1],
}

objByKey := groupObjsByKey(localObjs, liveObjs, "default")
Expand Down
18 changes: 9 additions & 9 deletions cmd/argocd/commands/applicationset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ func TestPrintApplicationSetTable(t *testing.T) {
},
Spec: v1alpha1.ApplicationSetSpec{
Generators: []v1alpha1.ApplicationSetGenerator{
v1alpha1.ApplicationSetGenerator{
{
Git: &v1alpha1.GitGenerator{
RepoURL: "https://github.com/argoproj/argo-cd.git",
Revision: "head",
Directories: []v1alpha1.GitDirectoryGeneratorItem{
v1alpha1.GitDirectoryGeneratorItem{
{
Path: "applicationset/examples/git-generator-directory/cluster-addons/*",
},
},
Expand All @@ -60,7 +60,7 @@ func TestPrintApplicationSetTable(t *testing.T) {
},
Status: v1alpha1.ApplicationSetStatus{
Conditions: []v1alpha1.ApplicationSetCondition{
v1alpha1.ApplicationSetCondition{
{
Status: v1alpha1.ApplicationSetConditionStatusTrue,
Type: v1alpha1.ApplicationSetConditionResourcesUpToDate,
},
Expand All @@ -75,12 +75,12 @@ func TestPrintApplicationSetTable(t *testing.T) {
},
Spec: v1alpha1.ApplicationSetSpec{
Generators: []v1alpha1.ApplicationSetGenerator{
v1alpha1.ApplicationSetGenerator{
{
Git: &v1alpha1.GitGenerator{
RepoURL: "https://github.com/argoproj/argo-cd.git",
Revision: "head",
Directories: []v1alpha1.GitDirectoryGeneratorItem{
v1alpha1.GitDirectoryGeneratorItem{
{
Path: "applicationset/examples/git-generator-directory/cluster-addons/*",
},
},
Expand All @@ -95,7 +95,7 @@ func TestPrintApplicationSetTable(t *testing.T) {
},
Status: v1alpha1.ApplicationSetStatus{
Conditions: []v1alpha1.ApplicationSetCondition{
v1alpha1.ApplicationSetCondition{
{
Status: v1alpha1.ApplicationSetConditionStatusTrue,
Type: v1alpha1.ApplicationSetConditionResourcesUpToDate,
},
Expand All @@ -118,12 +118,12 @@ func TestPrintAppSetSummaryTable(t *testing.T) {
},
Spec: v1alpha1.ApplicationSetSpec{
Generators: []v1alpha1.ApplicationSetGenerator{
v1alpha1.ApplicationSetGenerator{
{
Git: &v1alpha1.GitGenerator{
RepoURL: "https://github.com/argoproj/argo-cd.git",
Revision: "head",
Directories: []v1alpha1.GitDirectoryGeneratorItem{
v1alpha1.GitDirectoryGeneratorItem{
{
Path: "applicationset/examples/git-generator-directory/cluster-addons/*",
},
},
Expand All @@ -138,7 +138,7 @@ func TestPrintAppSetSummaryTable(t *testing.T) {
},
Status: v1alpha1.ApplicationSetStatus{
Conditions: []v1alpha1.ApplicationSetCondition{
v1alpha1.ApplicationSetCondition{
{
Status: v1alpha1.ApplicationSetConditionStatusTrue,
Type: v1alpha1.ApplicationSetConditionResourcesUpToDate,
},
Expand Down
1 change: 1 addition & 0 deletions resource_customizations/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import (
)

// Embedded contains embedded resource customization
//
//go:embed *
var Embedded embed.FS
8 changes: 4 additions & 4 deletions server/badge/badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
"github.com/argoproj/argo-cd/v2/util/settings"
)

//NewHandler creates handler serving to do api/badge endpoint
// NewHandler creates handler serving to do api/badge endpoint
func NewHandler(appClientset versioned.Interface, settingsMrg *settings.SettingsManager, namespace string) http.Handler {
return &Handler{appClientset: appClientset, namespace: namespace, settingsMgr: settingsMrg}
}

//Handler used to get application in order to access health/sync
// Handler used to get application in order to access health/sync
type Handler struct {
namespace string
appClientset versioned.Interface
Expand Down Expand Up @@ -62,8 +62,8 @@ func replaceFirstGroupSubMatch(re *regexp.Regexp, str string, repl string) strin
return result + str[lastIndex:]
}

//ServeHTTP returns badge with health and sync status for application
//(or an error badge if wrong query or application name is given)
// ServeHTTP returns badge with health and sync status for application
// (or an error badge if wrong query or application name is given)
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
health := healthutil.HealthStatusUnknown
status := appv1.SyncStatusCodeUnknown
Expand Down
2 changes: 1 addition & 1 deletion server/logout/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/argoproj/argo-cd/v2/util/settings"
)

//NewHandler creates handler serving to do api/logout endpoint
// NewHandler creates handler serving to do api/logout endpoint
func NewHandler(appClientset versioned.Interface, settingsMrg *settings.SettingsManager, sessionMgr *session.SessionManager, rootPath, baseHRef, namespace string) *Handler {
return &Handler{
appClientset: appClientset,
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/jsonnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestJsonnetExtVarEnv(t *testing.T) {
})
}

//Jsonnet file located in nested sub directory uses import
// Jsonnet file located in nested sub directory uses import
func TestJsonnetNestedDirWithImports(t *testing.T) {
Given(t).
Path("jsonnet-nested-dir-with-imports/apps").
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestNotificationsListServices(t *testing.T) {
SetParamInNotificationConfigMap("service.webhook.test", "url: https://test.com").
Then().Services(func(services *notification.ServiceList, err error) {
assert.Nil(t, err)
assert.Equal(t, []*notification.Service{&notification.Service{Name: pointer.String("test")}}, services.Items)
assert.Equal(t, []*notification.Service{{Name: pointer.String("test")}}, services.Items)
})
}

Expand All @@ -25,7 +25,7 @@ func TestNotificationsListTemplates(t *testing.T) {
SetParamInNotificationConfigMap("template.app-created", "email:\n subject: Application {{.app.metadata.name}} has been created.\nmessage: Application {{.app.metadata.name}} has been created.\nteams:\n title: Application {{.app.metadata.name}} has been created.\n").
Then().Templates(func(templates *notification.TemplateList, err error) {
assert.Nil(t, err)
assert.Equal(t, []*notification.Template{&notification.Template{Name: pointer.String("app-created")}}, templates.Items)
assert.Equal(t, []*notification.Template{{Name: pointer.String("app-created")}}, templates.Items)
})
}

Expand All @@ -35,6 +35,6 @@ func TestNotificationsListTriggers(t *testing.T) {
SetParamInNotificationConfigMap("trigger.on-created", "- description: Application is created.\n oncePer: app.metadata.name\n send:\n - app-created\n when: \"true\"\n").
Then().Triggers(func(triggers *notification.TriggerList, err error) {
assert.Nil(t, err)
assert.Equal(t, []*notification.Trigger{&notification.Trigger{Name: pointer.String("on-created")}}, triggers.Items)
assert.Equal(t, []*notification.Trigger{{Name: pointer.String("on-created")}}, triggers.Items)
})
}
2 changes: 1 addition & 1 deletion test/e2e/selective_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestSelectiveSyncWithoutNamespace(t *testing.T) {
Expect(ResourceSyncStatusWithNamespaceIs("Deployment", "guestbook-ui", fixture.DeploymentNamespace(), SyncStatusCodeSynced))
}

//In selectedResource to sync, namespace is provided
// In selectedResource to sync, namespace is provided
func TestSelectiveSyncWithNamespace(t *testing.T) {
selectedResourceNamespace := getNewNamespace(t)
defer func() {
Expand Down
1 change: 1 addition & 0 deletions ui/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package ui
import "embed"

// Embedded contains embedded UI resources
//
//go:embed dist/app
var Embedded embed.FS
7 changes: 3 additions & 4 deletions util/db/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ type CertificateListSelector struct {
// the certificates, and only returns the metadata including CertInfo field.
//
// The CertInfo field in the returned entries will contain the following data:
// - For SSH keys, the SHA256 fingerprint of the key as string, prepended by
// the string "SHA256:"
// - For TLS certs, the Subject of the X509 cert as a string in DN notation
//
// - For SSH keys, the SHA256 fingerprint of the key as string, prepended by
// the string "SHA256:"
// - For TLS certs, the Subject of the X509 cert as a string in DN notation
func (db *db) ListRepoCertificates(ctx context.Context, selector *CertificateListSelector) (*appsv1.RepositoryCertificateList, error) {

// selector may be given as nil, but we need at least an empty data structure
Expand Down
8 changes: 4 additions & 4 deletions util/db/helmrepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func (db *db) getHelmRepo(repoURL string, helmRepositories []settings.HelmRepoCr
Name: repoInfo.Name,
}
err := db.unmarshalFromSecretsStr(map[*SecretMaperValidation]*v1.SecretKeySelector{
&SecretMaperValidation{Dest: &repo.Username, Transform: StripCRLFCharacter}: repoInfo.UsernameSecret,
&SecretMaperValidation{Dest: &repo.Password, Transform: StripCRLFCharacter}: repoInfo.PasswordSecret,
&SecretMaperValidation{Dest: &repo.TLSClientCertData, Transform: StripCRLFCharacter}: repoInfo.CertSecret,
&SecretMaperValidation{Dest: &repo.TLSClientCertKey, Transform: StripCRLFCharacter}: repoInfo.KeySecret,
{Dest: &repo.Username, Transform: StripCRLFCharacter}: repoInfo.UsernameSecret,
{Dest: &repo.Password, Transform: StripCRLFCharacter}: repoInfo.PasswordSecret,
{Dest: &repo.TLSClientCertData, Transform: StripCRLFCharacter}: repoInfo.CertSecret,
{Dest: &repo.TLSClientCertKey, Transform: StripCRLFCharacter}: repoInfo.KeySecret,
}, make(map[string]*v1.Secret))
return repo, err
}
Expand Down
Loading

0 comments on commit 4a50a31

Please sign in to comment.