Skip to content

Commit

Permalink
chore: enable indent-error-flow from revive (#21394)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 authored Jan 7, 2025
1 parent 53bc19b commit 947a7b8
Show file tree
Hide file tree
Showing 44 changed files with 337 additions and 416 deletions.
11 changes: 8 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 123,11 @@ linters-settings:
# incrementing an integer variable by 1 is recommended to be done using the ` ` operator
- name: increment-decrement
disabled: false
# highlights redundant else-blocks that can be eliminated from the code
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#indent-error-flow
- name: indent-error-flow
disabled: true
disabled: false
arguments:
- "preserveScope"
# This rule suggests a shorter way of writing ranges that do not use the second value.
- name: range
disabled: false
Expand All @@ -135,12 137,15 @@ linters-settings:
# redefining built in names (true, false, append, make) can lead to bugs very difficult to detect.
- name: redefines-builtin-id
disabled: true
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#redundant-import-alias
- name: redundant-import-alias
disabled: false
# redundant else-blocks that can be eliminated from the code.
- name: superfluous-else
disabled: false
# prevent confusing name for variables when using `time` package
arguments:
- "preserveScope"
# prevent confusing name for variables when using `time` package
- name: time-naming
disabled: true
# warns when an exported function or method returns a value of an un-exported type.
Expand Down
3 changes: 1 addition & 2 deletions applicationset/generators/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 169,8 @@ func (m *MatrixGenerator) GetRequeueAfter(appSetGenerator *argoprojiov1alpha1.Ap

if found {
return res
} else {
return NoRequeueAfter
}
return NoRequeueAfter
}

func getMatrixGenerator(r argoprojiov1alpha1.ApplicationSetNestedGenerator) (*argoprojiov1alpha1.MatrixGenerator, error) {
Expand Down
3 changes: 1 addition & 2 deletions applicationset/generators/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 224,8 @@ func (m *MergeGenerator) GetRequeueAfter(appSetGenerator *argoprojiov1alpha1.App

if found {
return res
} else {
return NoRequeueAfter
}
return NoRequeueAfter
}

func getMergeGenerator(r argoprojiov1alpha1.ApplicationSetNestedGenerator) (*argoprojiov1alpha1.MergeGenerator, error) {
Expand Down
6 changes: 2 additions & 4 deletions applicationset/generators/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 176,8 @@ func (g *PullRequestGenerator) selectServiceProvider(ctx context.Context, genera
return nil, fmt.Errorf("error fetching Secret token: %w", err)
}
return pullrequest.NewBitbucketServiceBasicAuth(ctx, providerConfig.BasicAuth.Username, password, providerConfig.API, providerConfig.Project, providerConfig.Repo, g.scmRootCAPath, providerConfig.Insecure, caCerts)
} else {
return pullrequest.NewBitbucketServiceNoAuth(ctx, providerConfig.API, providerConfig.Project, providerConfig.Repo, g.scmRootCAPath, providerConfig.Insecure, caCerts)
}
return pullrequest.NewBitbucketServiceNoAuth(ctx, providerConfig.API, providerConfig.Project, providerConfig.Repo, g.scmRootCAPath, providerConfig.Insecure, caCerts)
}
if generatorConfig.Bitbucket != nil {
providerConfig := generatorConfig.Bitbucket
Expand All @@ -194,9 193,8 @@ func (g *PullRequestGenerator) selectServiceProvider(ctx context.Context, genera
return nil, fmt.Errorf("error fetching Secret token: %w", err)
}
return pullrequest.NewBitbucketCloudServiceBasicAuth(providerConfig.API, providerConfig.BasicAuth.Username, password, providerConfig.Owner, providerConfig.Repo)
} else {
return pullrequest.NewBitbucketCloudServiceNoAuth(providerConfig.API, providerConfig.Owner, providerConfig.Repo)
}
return pullrequest.NewBitbucketCloudServiceNoAuth(providerConfig.API, providerConfig.Owner, providerConfig.Repo)
}
if generatorConfig.AzureDevOps != nil {
providerConfig := generatorConfig.AzureDevOps
Expand Down
3 changes: 1 addition & 2 deletions cmd/argocd-dex/commands/argocd_dex.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 242,8 @@ func redactor(dirtyString string) string {
iterateStringFields(config, func(name string, val string) string {
if name == "clientSecret" || name == "secret" || name == "bindPW" {
return "********"
} else {
return val
}
return val
})
data, err := yaml.Marshal(config)
errors.CheckError(err)
Expand Down
3 changes: 1 addition & 2 deletions cmd/argocd/commands/admin/settings_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 463,8 @@ func checkPolicy(subject, action, resource, subResource, builtinPolicy, userPoli
func resolveRBACResourceName(name string) string {
if res, ok := resourceMap[name]; ok {
return res
} else {
return name
}
return name
}

// validateRBACResourceAction checks whether a given resource is a valid RBAC resource.
Expand Down
38 changes: 18 additions & 20 deletions cmd/argocd/commands/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,22 599,21 @@ func modifyResourcesList(list *[]metav1.GroupKind, add bool, listDesc string, gr
fmt.Printf("Group '%s' and kind '%s' is added to %s resources\n", group, kind, listDesc)
*list = append(*list, metav1.GroupKind{Group: group, Kind: kind})
return true
} else {
index := -1
for i, item := range *list {
if item.Group == group && item.Kind == kind {
index = i
break
}
}
if index == -1 {
fmt.Printf("Group '%s' and kind '%s' not in %s resources\n", group, kind, listDesc)
return false
}
index := -1
for i, item := range *list {
if item.Group == group && item.Kind == kind {
index = i
break
}
*list = append((*list)[:index], (*list)[index 1:]...)
fmt.Printf("Group '%s' and kind '%s' is removed from %s resources\n", group, kind, listDesc)
return true
}
if index == -1 {
fmt.Printf("Group '%s' and kind '%s' not in %s resources\n", group, kind, listDesc)
return false
}
*list = append((*list)[:index], (*list)[index 1:]...)
fmt.Printf("Group '%s' and kind '%s' is removed from %s resources\n", group, kind, listDesc)
return true
}

func modifyResourceListCmd(cmdUse, cmdDesc, examples string, clientOpts *argocdclient.ClientOptions, allow bool, namespacedList bool) *cobra.Command {
Expand Down Expand Up @@ -1111,12 1110,11 @@ func NewProjectAddDestinationServiceAccountCommand(clientOpts *argocdclient.Clie
Namespace: namespace,
DefaultServiceAccount: fmt.Sprintf("%s:%s", serviceAccountNamespace, serviceAccount),
}
} else {
return v1alpha1.ApplicationDestinationServiceAccount{
Server: destination,
Namespace: namespace,
DefaultServiceAccount: serviceAccount,
}
}
return v1alpha1.ApplicationDestinationServiceAccount{
Server: destination,
Namespace: namespace,
DefaultServiceAccount: serviceAccount,
}
}

Expand Down
12 changes: 6 additions & 6 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,20 354,20 @@ const (

// GetGnuPGHomePath retrieves the path to use for GnuPG home directory, which is either taken from GNUPGHOME environment or a default value
func GetGnuPGHomePath() string {
if gnuPgHome := os.Getenv(EnvGnuPGHome); gnuPgHome == "" {
gnuPgHome := os.Getenv(EnvGnuPGHome)
if gnuPgHome == "" {
return DefaultGnuPgHomePath
} else {
return gnuPgHome
}
return gnuPgHome
}

// GetPluginSockFilePath retrieves the path of plugin sock file, which is either taken from PluginSockFilePath environment or a default value
func GetPluginSockFilePath() string {
if pluginSockFilePath := os.Getenv(EnvPluginSockFilePath); pluginSockFilePath == "" {
pluginSockFilePath := os.Getenv(EnvPluginSockFilePath)
if pluginSockFilePath == "" {
return DefaultPluginSockFilePath
} else {
return pluginSockFilePath
}
return pluginSockFilePath
}

// GetCMPChunkSize will return the env var EnvCMPChunkSize value if defined or DefaultCMPChunkSize otherwise.
Expand Down
34 changes: 14 additions & 20 deletions controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 400,8 @@ func (ctrl *ApplicationController) getAppProj(app *appv1.Application) (*appv1.Ap
if err != nil {
if apierrors.IsNotFound(err) {
return nil, err
} else {
return nil, fmt.Errorf("could not retrieve AppProject '%s' from cache: %w", app.Spec.Project, err)
}
return nil, fmt.Errorf("could not retrieve AppProject '%s' from cache: %w", app.Spec.Project, err)
}
if !proj.IsAppNamespacePermitted(app, ctrl.namespace) {
return nil, argo.ErrProjectNotPermitted(app.GetName(), app.GetNamespace(), proj.GetName())
Expand Down Expand Up @@ -1052,12 1051,12 @@ func (ctrl *ApplicationController) processAppComparisonTypeQueueItem() (processN
if parts := strings.Split(key, "/"); len(parts) != 3 {
log.Warnf("Unexpected key format in appComparisonTypeRefreshTypeQueue. Key should consists of namespace/name/comparisonType but got: %s", key)
} else {
if compareWith, err := strconv.Atoi(parts[2]); err != nil {
compareWith, err := strconv.Atoi(parts[2])
if err != nil {
log.Warnf("Unable to parse comparison type: %v", err)
return
} else {
ctrl.requestAppRefresh(ctrl.toAppQualifiedName(parts[1], parts[0]), CompareWith(compareWith).Pointer(), nil)
}
ctrl.requestAppRefresh(ctrl.toAppQualifiedName(parts[1], parts[0]), CompareWith(compareWith).Pointer(), nil)
}
return
}
Expand Down Expand Up @@ -1112,9 1111,8 @@ func (ctrl *ApplicationController) finalizeProjectDeletion(proj *appv1.AppProjec
}
if appsCount == 0 {
return ctrl.removeProjectFinalizer(proj)
} else {
log.Infof("Cannot remove project '%s' finalizer as is referenced by %d applications", proj.Name, appsCount)
}
log.Infof("Cannot remove project '%s' finalizer as is referenced by %d applications", proj.Name, appsCount)
return nil
}

Expand Down Expand Up @@ -1398,14 1396,13 @@ func (ctrl *ApplicationController) processRequestedAppOperation(app *appv1.Appli
logCtx.Infof("Skipping retrying in-progress operation. Attempting again at: %s", retryAt.Format(time.RFC3339))
ctrl.requestAppRefresh(app.QualifiedName(), CompareWithLatest.Pointer(), &retryAfter)
return
} else {
// retrying operation. remove previous failure time in app since it is used as a trigger
// that previous failed and operation should be retried
state.FinishedAt = nil
ctrl.setOperationState(app, state)
// Get rid of sync results and null out previous operation completion time
state.SyncResult = nil
}
// retrying operation. remove previous failure time in app since it is used as a trigger
// that previous failed and operation should be retried
state.FinishedAt = nil
ctrl.setOperationState(app, state)
// Get rid of sync results and null out previous operation completion time
state.SyncResult = nil
} else if ctrl.syncTimeout != time.Duration(0) && time.Now().After(state.StartedAt.Add(ctrl.syncTimeout)) && !terminating {
state.Phase = synccommon.OperationTerminating
state.Message = "operation is terminating due to timeout"
Expand Down Expand Up @@ -2169,9 2166,8 @@ func (ctrl *ApplicationController) autoSync(app *appv1.Application, syncStatus *

logCtx.Errorf("Failed to initiate auto-sync to %s: %v", desiredCommitSHA, err)
return &appv1.ApplicationCondition{Type: appv1.ApplicationConditionSyncError, Message: err.Error()}, setOpTime
} else {
ctrl.writeBackToInformer(updatedApp)
}
ctrl.writeBackToInformer(updatedApp)
ts.AddCheckpoint("write_back_to_informer_ms")

var target string
Expand Down Expand Up @@ -2213,9 2209,8 @@ func alreadyAttemptedSync(app *appv1.Application, commitSHA string, commitSHAsMS

if hasMultipleSources {
return reflect.DeepEqual(app.Spec.Sources, app.Status.OperationState.SyncResult.Sources), app.Status.OperationState.Phase
} else {
return reflect.DeepEqual(app.Spec.GetSource(), app.Status.OperationState.SyncResult.Source), app.Status.OperationState.Phase
}
return reflect.DeepEqual(app.Spec.GetSource(), app.Status.OperationState.SyncResult.Source), app.Status.OperationState.Phase
}

func (ctrl *ApplicationController) shouldSelfHeal(app *appv1.Application) (bool, time.Duration) {
Expand Down Expand Up @@ -2502,9 2497,8 @@ func (ctrl *ApplicationController) toAppKey(appName string) string {
return ctrl.namespace "/" appName
} else if strings.Contains(appName, "/") {
return appName
} else {
return strings.ReplaceAll(appName, "_", "/")
}
return strings.ReplaceAll(appName, "_", "/")
}

func (ctrl *ApplicationController) toAppQualifiedName(appName, appNamespace string) string {
Expand Down
Loading

0 comments on commit 947a7b8

Please sign in to comment.