From e82ae8bd38873a145b2a279d534f026d370fc37e Mon Sep 17 00:00:00 2001 From: Nicholas Wiersma Date: Thu, 14 May 2026 09:24:16 +0200 Subject: [PATCH 1/3] feat: always write report --- main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 1e02c7c..3f180a8 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,19 @@ func realMain() int { } if len(fixes) == 0 { - fmt.Fprintln(os.Stderr, "vulnfix: no fixable vulnerabilities found") + if *outFile != "" && *outFile != "-" { + f, err := os.Create(*outFile) + if err != nil { + fmt.Fprintf(os.Stderr, "vulnfix: %v\n", err) + return 1 + } + defer func() { _ = f.Close() }() + + f.Write([]byte("# Vulnerability Report\n\n")) + f.Write([]byte("No vulnerabilities found.\n")) + } + + fmt.Fprintln(os.Stdout, "vulnfix: no fixable vulnerabilities found") return 0 } From 625ef898e39d0a40d82d68c314203ca07f9a414e Mon Sep 17 00:00:00 2001 From: Nicholas Wiersma Date: Thu, 14 May 2026 09:32:27 +0200 Subject: [PATCH 2/3] fix: linter --- main.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 3f180a8..875cf3a 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,7 @@ func realMain() int { fixes, err := govulncheck.Parse(os.Stdin) if err != nil { - fmt.Fprintf(os.Stderr, "vulnfix: %v\n", err) + _, _ = fmt.Fprintf(os.Stderr, "vulnfix: %v\n", err) return 1 } @@ -41,11 +41,10 @@ func realMain() int { } defer func() { _ = f.Close() }() - f.Write([]byte("# Vulnerability Report\n\n")) - f.Write([]byte("No vulnerabilities found.\n")) + _, _ = f.WriteString("# Vulnerability Report\n\nNo vulnerabilities found.\n") } - fmt.Fprintln(os.Stdout, "vulnfix: no fixable vulnerabilities found") + _, _ = fmt.Fprintln(os.Stdout, "vulnfix: no fixable vulnerabilities found") return 0 } @@ -54,14 +53,14 @@ func realMain() int { versions[mod] = fix.Version } if err = modfix.Apply(ctx, *dir, versions); err != nil { - fmt.Fprintf(os.Stderr, "vulnfix: %v\n", err) + _, _ = fmt.Fprintf(os.Stderr, "vulnfix: %v\n", err) return 1 } if *outFile != "" && *outFile != "-" { f, err := os.Create(*outFile) if err != nil { - fmt.Fprintf(os.Stderr, "vulnfix: %v\n", err) + _, _ = fmt.Fprintf(os.Stderr, "vulnfix: %v\n", err) return 1 } defer func() { _ = f.Close() }() From 7bca0283bc237cb84b5783de9738b24382041440 Mon Sep 17 00:00:00 2001 From: Nicholas Wiersma Date: Thu, 14 May 2026 09:34:42 +0200 Subject: [PATCH 3/3] fix: refactor --- main.go | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index 875cf3a..6b61c3b 100644 --- a/main.go +++ b/main.go @@ -32,15 +32,18 @@ func realMain() int { return 1 } - if len(fixes) == 0 { - if *outFile != "" && *outFile != "-" { - f, err := os.Create(*outFile) - if err != nil { - fmt.Fprintf(os.Stderr, "vulnfix: %v\n", err) - return 1 - } - defer func() { _ = f.Close() }() + var f *os.File + if *outFile != "" && *outFile != "-" { + f, err = os.Create(*outFile) + if err != nil { + _, _ = fmt.Fprintf(os.Stderr, "vulnfix: %v\n", err) + return 1 + } + defer func() { _ = f.Close() }() + } + if len(fixes) == 0 { + if f != nil { _, _ = f.WriteString("# Vulnerability Report\n\nNo vulnerabilities found.\n") } @@ -57,14 +60,7 @@ func realMain() int { return 1 } - if *outFile != "" && *outFile != "-" { - f, err := os.Create(*outFile) - if err != nil { - _, _ = fmt.Fprintf(os.Stderr, "vulnfix: %v\n", err) - return 1 - } - defer func() { _ = f.Close() }() - + if f != nil { report.Write(f, fixes) } return 0