Skip to content

Commit

Permalink
chore: enable superfluous-else from revive (argoproj#21373)
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 6, 2025
1 parent 1029388 commit cb3024c
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 68 deletions.
3 changes: 2 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ linters-settings:
disabled: true
# for better readability, the errors should be last in the list of returned values by a function.
- name: error-return
disabled: false
# for better readability, error messages should not be capitalized or end with punctuation or a newline.
- name: error-strings
disabled: true
Expand All @@ -135,7 +136,7 @@ linters-settings:
disabled: false
# redundant else-blocks that can be eliminated from the code.
- name: superfluous-else
disabled: true
disabled: false
# prevent confusing name for variables when using `time` package
- name: time-naming
disabled: true
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 @@ -136,9 +136,8 @@ func NewRunDexCommand() *cobra.Command {
errors.CheckError(err)
}
break
} else {
log.Infof("dex config unmodified")
}
log.Infof("dex config unmodified")
}
}
},
Expand Down
17 changes: 7 additions & 10 deletions cmd/argocd/commands/admin/settings_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,11 @@ argocd admin settings rbac can someuser create application 'default/app' --defau
fmt.Println("Yes")
}
os.Exit(0)
} else {
if !quiet {
fmt.Println("No")
}
os.Exit(1)
}
if !quiet {
fmt.Println("No")
}
os.Exit(1)
},
}
clientConfig = cli.AddKubectlFlagsToCmd(command)
Expand Down Expand Up @@ -321,13 +320,11 @@ argocd admin settings rbac validate --namespace argocd
if err := rbac.ValidatePolicy(userPolicy); err == nil {
fmt.Printf("Policy is valid.\n")
os.Exit(0)
} else {
fmt.Printf("Policy is invalid: %v\n", err)
os.Exit(1)
}
} else {
log.Fatalf("Policy is empty or could not be loaded.")
fmt.Printf("Policy is invalid: %v\n", err)
os.Exit(1)
}
log.Fatalf("Policy is empty or could not be loaded.")
},
}
clientConfig = cli.AddKubectlFlagsToCmd(command)
Expand Down
42 changes: 21 additions & 21 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,11 @@ func NewApplicationGetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com

if sourceName != "" {
sourceNameToPosition := getSourceNameToPositionMap(app)
if pos, ok := sourceNameToPosition[sourceName]; !ok {
pos, ok := sourceNameToPosition[sourceName]
if !ok {
log.Fatalf("Unknown source name '%s'", sourceName)
} else {
sourcePosition = int(pos)
}
sourcePosition = int(pos)
}

// check for source position if --show-params is set
Expand Down Expand Up @@ -840,11 +840,11 @@ func NewApplicationSetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com

if sourceName != "" {
sourceNameToPosition := getSourceNameToPositionMap(app)
if pos, ok := sourceNameToPosition[sourceName]; !ok {
pos, ok := sourceNameToPosition[sourceName]
if !ok {
log.Fatalf("Unknown source name '%s'", sourceName)
} else {
sourcePosition = int(pos)
}
sourcePosition = int(pos)
}

if app.Spec.HasMultipleSources() {
Expand Down Expand Up @@ -953,11 +953,11 @@ func NewApplicationUnsetCommand(clientOpts *argocdclient.ClientOptions) *cobra.C

if sourceName != "" {
sourceNameToPosition := getSourceNameToPositionMap(app)
if pos, ok := sourceNameToPosition[sourceName]; !ok {
pos, ok := sourceNameToPosition[sourceName]
if !ok {
log.Fatalf("Unknown source name '%s'", sourceName)
} else {
sourcePosition = int(pos)
}
sourcePosition = int(pos)
}

if app.Spec.HasMultipleSources() {
Expand Down Expand Up @@ -1271,11 +1271,11 @@ func NewApplicationDiffCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
sourceNameToPosition := getSourceNameToPositionMap(app)

for _, name := range sourceNames {
if pos, ok := sourceNameToPosition[name]; !ok {
pos, ok := sourceNameToPosition[name]
if !ok {
log.Fatalf("Unknown source name '%s'", name)
} else {
sourcePositions = append(sourcePositions, pos)
}
sourcePositions = append(sourcePositions, pos)
}
}

Expand Down Expand Up @@ -2033,11 +2033,11 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
sourceNameToPosition := getSourceNameToPositionMap(app)

for _, name := range sourceNames {
if pos, ok := sourceNameToPosition[name]; !ok {
pos, ok := sourceNameToPosition[name]
if !ok {
log.Fatalf("Unknown source name '%s'", name)
} else {
sourcePositions = append(sourcePositions, pos)
}
sourcePositions = append(sourcePositions, pos)
}
}

Expand Down Expand Up @@ -3004,11 +3004,11 @@ func NewApplicationManifestsCommand(clientOpts *argocdclient.ClientOptions) *cob
sourceNameToPosition := getSourceNameToPositionMap(app)

for _, name := range sourceNames {
if pos, ok := sourceNameToPosition[name]; !ok {
pos, ok := sourceNameToPosition[name]
if !ok {
log.Fatalf("Unknown source name '%s'", name)
} else {
sourcePositions = append(sourcePositions, pos)
}
sourcePositions = append(sourcePositions, pos)
}
}

Expand Down Expand Up @@ -3339,11 +3339,11 @@ func NewApplicationRemoveSourceCommand(clientOpts *argocdclient.ClientOptions) *

if sourceName != "" {
sourceNameToPosition := getSourceNameToPositionMap(app)
if pos, ok := sourceNameToPosition[sourceName]; !ok {
pos, ok := sourceNameToPosition[sourceName]
if !ok {
log.Fatalf("Unknown source name '%s'", sourceName)
} else {
sourcePosition = int(pos)
}
sourcePosition = int(pos)
}

if !app.Spec.HasMultipleSources() {
Expand Down
3 changes: 1 addition & 2 deletions cmd/argocd/commands/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ func NewCertAddTLSCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command
if subjectMap[x509cert.Subject.String()] != nil {
fmt.Printf("ERROR: Cert with subject '%s' already seen in the input stream.\n", x509cert.Subject.String())
continue
} else {
subjectMap[x509cert.Subject.String()] = x509cert
}
subjectMap[x509cert.Subject.String()] = x509cert
}

serverName := args[0]
Expand Down
21 changes: 9 additions & 12 deletions cmd/argocd/commands/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,10 @@ func NewProjectRemoveSignatureKeyCommand(clientOpts *argocdclient.ClientOptions)
}
if index == -1 {
log.Fatal("Specified signature key is not configured for project")
} else {
proj.Spec.SignatureKeys = append(proj.Spec.SignatureKeys[:index], proj.Spec.SignatureKeys[index+1:]...)
_, err = projIf.Update(ctx, &projectpkg.ProjectUpdateRequest{Project: proj})
errors.CheckError(err)
}
proj.Spec.SignatureKeys = append(proj.Spec.SignatureKeys[:index], proj.Spec.SignatureKeys[index+1:]...)
_, err = projIf.Update(ctx, &projectpkg.ProjectUpdateRequest{Project: proj})
errors.CheckError(err)
},
}

Expand Down Expand Up @@ -352,11 +351,10 @@ func NewProjectRemoveDestinationCommand(clientOpts *argocdclient.ClientOptions)
}
if index == -1 {
log.Fatal("Specified destination does not exist in project")
} else {
proj.Spec.Destinations = append(proj.Spec.Destinations[:index], proj.Spec.Destinations[index+1:]...)
_, err = projIf.Update(ctx, &projectpkg.ProjectUpdateRequest{Project: proj})
errors.CheckError(err)
}
proj.Spec.Destinations = append(proj.Spec.Destinations[:index], proj.Spec.Destinations[index+1:]...)
_, err = projIf.Update(ctx, &projectpkg.ProjectUpdateRequest{Project: proj})
errors.CheckError(err)
},
}

Expand Down Expand Up @@ -456,11 +454,10 @@ func NewProjectRemoveOrphanedIgnoreCommand(clientOpts *argocdclient.ClientOption
}
if index == -1 {
log.Fatal("Specified resource does not exist in the orphaned ignore of project")
} else {
proj.Spec.OrphanedResources.Ignore = append(proj.Spec.OrphanedResources.Ignore[:index], proj.Spec.OrphanedResources.Ignore[index+1:]...)
_, err = projIf.Update(ctx, &projectpkg.ProjectUpdateRequest{Project: proj})
errors.CheckError(err)
}
proj.Spec.OrphanedResources.Ignore = append(proj.Spec.OrphanedResources.Ignore[:index], proj.Spec.OrphanedResources.Ignore[index+1:]...)
_, err = projIf.Update(ctx, &projectpkg.ProjectUpdateRequest{Project: proj})
errors.CheckError(err)
},
}
command.Flags().StringVar(&name, "name", "", "Resource name pattern")
Expand Down
20 changes: 9 additions & 11 deletions cmd/util/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ func (opts *ProjectOpts) GetDestinations() []v1alpha1.ApplicationDestination {
parts := strings.Split(destStr, ",")
if len(parts) != 2 {
log.Fatalf("Expected destination of the form: server,namespace. Received: %s", destStr)
} else {
destinations = append(destinations, v1alpha1.ApplicationDestination{
Server: parts[0],
Namespace: parts[1],
})
}
destinations = append(destinations, v1alpha1.ApplicationDestination{
Server: parts[0],
Namespace: parts[1],
})
}
return destinations
}
Expand All @@ -102,13 +101,12 @@ func (opts *ProjectOpts) GetDestinationServiceAccounts() []v1alpha1.ApplicationD
parts := strings.Split(destStr, ",")
if len(parts) != 3 {
log.Fatalf("Expected destination service account of the form: server,namespace, defaultServiceAccount. Received: %s", destStr)
} else {
destinationServiceAccounts = append(destinationServiceAccounts, v1alpha1.ApplicationDestinationServiceAccount{
Server: parts[0],
Namespace: parts[1],
DefaultServiceAccount: parts[2],
})
}
destinationServiceAccounts = append(destinationServiceAccounts, v1alpha1.ApplicationDestinationServiceAccount{
Server: parts[0],
Namespace: parts[1],
DefaultServiceAccount: parts[2],
})
}
return destinationServiceAccounts
}
Expand Down
7 changes: 3 additions & 4 deletions reposerver/gpgwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ func StartGPGWatcher(sourcePath string) error {
log.Infof("Retrying to re-create watcher, attempt %d of %d", attempt, maxRecreateRetries)
time.Sleep(1 * time.Second)
continue
} else {
log.Errorf("Maximum retries exceeded.")
close(done)
return
}
log.Errorf("Maximum retries exceeded.")
close(done)
return
}
break
}
Expand Down
3 changes: 1 addition & 2 deletions util/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,8 @@ func InteractiveEdit(filePattern string, data []byte, save func(input []byte) er
if string(updated) == "" || string(updated) == string(data) {
errors.CheckError(stderrors.New("edit cancelled, no valid changes were saved"))
break
} else {
data = stripComments(updated)
}
data = stripComments(updated)

err = save(data)
if err == nil {
Expand Down
6 changes: 3 additions & 3 deletions util/git/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ var (

func init() {
if countStr := os.Getenv(common.EnvGitAttemptsCount); countStr != "" {
if cnt, err := strconv.Atoi(countStr); err != nil {
cnt, err := strconv.Atoi(countStr)
if err != nil {
panic(fmt.Sprintf("Invalid value in %s env variable: %v", common.EnvGitAttemptsCount, err))
} else {
maxAttemptsCount = int(math.Max(float64(cnt), 1))
}
maxAttemptsCount = int(math.Max(float64(cnt), 1))
}

maxRetryDuration = env.ParseDurationFromEnv(common.EnvGitRetryMaxDuration, common.DefaultGitRetryMaxDuration, 0, math.MaxInt64)
Expand Down

0 comments on commit cb3024c

Please sign in to comment.