Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 66cf5cc

Browse files
committed
chore: fix gosimple issues
Signed-off-by: Yves Brissaud <yves.brissaud@docker.com>
1 parent 7fcd084 commit 66cf5cc

10 files changed

Lines changed: 19 additions & 34 deletions

File tree

format/cve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,6 @@ func Cves(cve string, cves *[]types.Cve, sb *types.Sbom, remediate bool, dockerC
102102
Remediation(remediation)
103103
}
104104
} else {
105-
fmt.Println(fmt.Sprintf("%s not detected", cve))
105+
fmt.Printf("%s not detected\n", cve)
106106
}
107107
}

format/format.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,19 @@ func Cve(sb *types.Sbom, c *types.Cve) {
174174
sourceId = c.Cve.SourceId
175175
}
176176
fmt.Println("")
177-
fmt.Println(defaultColors.underline.Sprintf(fmt.Sprintf("Detected %s %s", sourceId, ColorizeSeverity(ToSeverity(*c)))))
178-
fmt.Println(fmt.Sprintf("https://dso.docker.com/cve/%s", sourceId))
177+
defaultColors.underline.Printf("Detected %s %s\n", sourceId, ColorizeSeverity(ToSeverity(*c)))
178+
fmt.Printf("https://dso.docker.com/cve/%s\n", sourceId)
179179
fmt.Println("")
180180
purl := c.Purl
181181
for _, p := range sb.Artifacts {
182182
if p.Purl == purl {
183-
fmt.Println(defaultColors.cyan.Sprintf(p.Purl))
183+
defaultColors.cyan.Println(p.Purl)
184184
loc := p.Locations[0]
185185
for i, l := range sb.Source.Image.Config.RootFS.DiffIDs {
186186
if l.String() == loc.DiffId {
187187
h := sb.Source.Image.Config.History[i]
188188
fmt.Println(formatCreatedBy(h.CreatedBy))
189-
fmt.Println(fmt.Sprintf("%d: %s", i, loc.Digest))
189+
fmt.Printf("%d: %s\n", i, loc.Digest)
190190
}
191191
}
192192
}
@@ -196,9 +196,9 @@ func Cve(sb *types.Sbom, c *types.Cve) {
196196
func Remediation(remediation []string) {
197197
if len(remediation) > 0 {
198198
fmt.Println("")
199-
fmt.Println(defaultColors.underline.Sprintf("Suggested remediation"))
199+
defaultColors.underline.Println("Suggested remediation")
200200
for i, r := range remediation {
201-
fmt.Println(fmt.Sprintf("\n%d. %s", i+1, r))
201+
fmt.Printf("\n%d. %s\n", i+1, r)
202202
}
203203
}
204204
}

query/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func ForImageInGraphQL(sb *types.Sbom) (*types.ImageByDigestQuery, error) {
295295
}
296296

297297
func normalizeRepository(image *types.BaseImage) *types.BaseImage {
298-
if image.Repository.Host == "hub.docker.com" && strings.Index(image.Repository.Repo, "/") < 0 {
298+
if image.Repository.Host == "hub.docker.com" && strings.Contains(image.Repository.Repo, "/") {
299299
image.Repository.Badge = "OFFICIAL"
300300
}
301301
if image.Repository.Badge != "" {

registry/save.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (c *ImageCache) StoreImage() error {
111111
spinner.Stop()
112112
} else if format == "tar" {
113113
if c.remote {
114-
u := make(chan v1.Update, 0)
114+
u := make(chan v1.Update)
115115
errchan := make(chan error)
116116
go func() {
117117
if err := tarball.WriteToFile(c.ImagePath, *c.Ref, *c.Image, tarball.WithProgress(u)); err != nil {

sbom/detect/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
func nodePackageDetector() PackageDetector {
26-
expr := regexp.MustCompile("node\\.js/v(.*)")
26+
expr := regexp.MustCompile(`node\.js/v(.*)`)
2727
pkg := types.Package{
2828
Type: "github",
2929
Namespace: "nodejs",

sbom/diff.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,8 @@ func toPackageName(pkg packageurl.PackageURL) string {
100100

101101
func toImageName(result ImageIndexResult) string {
102102
imageName := result.Sbom.Source.Image.Name
103-
if strings.HasPrefix(imageName, "index.docker.io/") {
104-
imageName = imageName[len("index.docker.io/"):]
105-
}
106-
if strings.HasPrefix(imageName, "library/") {
107-
imageName = imageName[len("library/"):]
108-
}
103+
imageName = strings.TrimPrefix(imageName, "index.docker.io/")
104+
imageName = strings.TrimPrefix(imageName, "library/")
109105
return imageName
110106
}
111107

sbom/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func init() {
1919
}
2020

2121
func WatchImages(cli command.Cli) error {
22-
indexJobs := make(chan types.ImageSummary, 0)
22+
indexJobs := make(chan types.ImageSummary)
2323
for w := 1; w <= maxIndexWorkers; w++ {
2424
go indexImageWorker(cli, indexJobs)
2525
}

sbom/upload.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,7 @@ func parseReference(sb *types.Sbom) (string, string, error) {
326326
host = "hub.docker.com"
327327
}
328328
name := ref.Context().RepositoryStr()
329-
if strings.HasPrefix(name, "library/") {
330-
name = name[len("library/"):]
331-
}
329+
name = strings.TrimPrefix(name, "library/")
332330
return host, name, nil
333331
}
334332

types/purl.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ func NormalizePackages(pkgs []Package) ([]Package, error) {
4141
}
4242
purl.Namespace = toNamespace(purl)
4343

44-
// some versions strings (e.g. such of Go) have a v prefix that we drop
45-
if strings.HasPrefix(purl.Version, "v") {
46-
purl.Version = purl.Version[1:]
47-
}
44+
// some version strings (e.g. such of Go) have a v prefix that we drop
45+
purl.Version = strings.TrimPrefix(purl.Version, "v")
4846
if purl.Version == "" {
4947
purl.Version = "0.0.0"
5048
}
@@ -94,9 +92,7 @@ func NormalizePackages(pkgs []Package) ([]Package, error) {
9492
}
9593

9694
func ToPackageUrl(url string) (packageurl.PackageURL, error) {
97-
if strings.HasSuffix(url, "/") {
98-
url = url[0 : len(url)-1]
99-
}
95+
url = strings.TrimSuffix(url, "/")
10096
purl, err := packageurl.FromString(url)
10197
return purl, err
10298
}

types/query_types.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,8 @@ type Image struct {
8080
}
8181

8282
func ImageTags(image *Image) []string {
83-
tags := make([]string, 0)
84-
for _, tag := range image.Tags {
85-
tags = append(tags, tag)
86-
}
87-
sort.Slice(tags, func(i, j int) bool {
88-
return len(tags[i]) < len(tags[j])
89-
})
83+
tags := append([]string{}, image.Tags...)
84+
sort.Strings(tags)
9085
return tags
9186
}
9287

0 commit comments

Comments
 (0)