Skip to content

Commit 72f8188

Browse files
authored
fix: issues affecting code quality (#471)
* Replace `t.Sub(time.Now())` with `time.Until` * Remove unnecessary wrapping of function call * Remove unnecessary blank (_) identifier * Fix check for empty string
1 parent 069b0c3 commit 72f8188

File tree

5 files changed

+13
-19
lines changed

5 files changed

+13
-19
lines changed

cmd/src/headers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func parseAdditionalHeadersFromMap(environ []string) map[string]string {
2929
}
3030

3131
// Ensure we have a non-empty value
32-
if len(parts[1]) == 0 {
32+
if parts[1] == "" {
3333
continue
3434
}
3535

cmd/src/search.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,7 @@ var searchTemplateFuncs = map[string]interface{}{
511511
"searchHighlightPreview": func(preview interface{}) string {
512512
return searchHighlightPreview(preview, "", "")
513513
},
514-
"searchHighlightDiffPreview": func(diffPreview interface{}) string {
515-
return searchHighlightDiffPreview(diffPreview)
516-
},
514+
"searchHighlightDiffPreview": searchHighlightDiffPreview,
517515
"searchMaxRepoNameLength": func(results []map[string]interface{}) int {
518516
max := 0
519517
for _, r := range results {
@@ -526,12 +524,8 @@ var searchTemplateFuncs = map[string]interface{}{
526524
}
527525
return max
528526
},
529-
"htmlToPlainText": func(input string) string {
530-
return htmlToPlainText(input)
531-
},
532-
"buildVersionHasNewSearchInterface": func(input string) bool {
533-
return buildVersionHasNewSearchInterface(input)
534-
},
527+
"htmlToPlainText": htmlToPlainText,
528+
"buildVersionHasNewSearchInterface": buildVersionHasNewSearchInterface,
535529
"renderResult": func(searchResult map[string]interface{}) string {
536530
searchResultBody := searchResult["body"].(map[string]interface{})
537531
html := searchResultBody["html"].(string)

internal/campaigns/executor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func (x *executor) do(ctx context.Context, task *Task) (err error) {
308308
// add it to the list of specs that are displayed to the user and
309309
// send to the server. Instead, we can just report that the task is
310310
// complete and move on.
311-
if len(result.Diff) == 0 {
311+
if result.Diff == "" {
312312
x.updateTaskStatus(task, func(status *TaskStatus) {
313313
status.Cached = true
314314
status.FinishedAt = time.Now()
@@ -398,7 +398,7 @@ func (x *executor) do(ctx context.Context, task *Task) (err error) {
398398

399399
// If the steps didn't result in any diff, we don't need to add it to the
400400
// list of specs that are displayed to the user and send to the server.
401-
if len(result.Diff) == 0 {
401+
if result.Diff == "" {
402402
return
403403
}
404404

internal/campaigns/templating.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func parseGitStatus(out []byte) (StepChanges, error) {
250250
result := StepChanges{}
251251

252252
stripped := strings.TrimSpace(string(out))
253-
if len(stripped) == 0 {
253+
if stripped == "" {
254254
return result, nil
255255
}
256256

internal/output/_examples/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func demo(out *output.Output, duration time.Duration) {
5050
defer wg.Done()
5151

5252
i := 0
53-
for _ = range ticker.C {
53+
for range ticker.C {
5454
i += 1
5555
if i > 20 {
5656
return
@@ -68,7 +68,7 @@ func demo(out *output.Output, duration time.Duration) {
6868

6969
start := time.Now()
7070
until := start.Add(duration)
71-
for _ = range ticker.C {
71+
for range ticker.C {
7272
now := time.Now()
7373
if now.After(until) {
7474
return
@@ -91,13 +91,13 @@ func demo(out *output.Output, duration time.Duration) {
9191
defer pending.Complete(output.Line(output.EmojiSuccess, output.StyleSuccess, "Ticker done!"))
9292

9393
until := time.Now().Add(duration)
94-
for _ = range ticker.C {
94+
for range ticker.C {
9595
now := time.Now()
9696
if now.After(until) {
9797
return
9898
}
9999

100-
pending.Updatef("Waiting for another %s", until.Sub(time.Now()))
100+
pending.Updatef("Waiting for another %s", time.Until(until))
101101
}
102102
}()
103103

@@ -123,7 +123,7 @@ func demoProgressWithBars(out *output.Output, duration time.Duration) {
123123
defer wg.Done()
124124

125125
i := 0
126-
for _ = range ticker.C {
126+
for range ticker.C {
127127
i += 1
128128
if i > 10 {
129129
return
@@ -141,7 +141,7 @@ func demoProgressWithBars(out *output.Output, duration time.Duration) {
141141

142142
start := time.Now()
143143
until := start.Add(duration)
144-
for _ = range ticker.C {
144+
for range ticker.C {
145145
now := time.Now()
146146
if now.After(until) {
147147
return

0 commit comments

Comments
 (0)