Fix golangci-lint errcheck warnings; add make fixstyle
errcheck flagged six unchecked Close() calls. The production write path in indexgen.ProcessDir now closes the index file explicitly after Execute and surfaces the close error so a deferred flush failure isn't lost; tests use _ = f.Close() since they don't care. Also adds a 'make fixstyle' target that runs gofmt -w over the tree, matching the convention used elsewhere. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -245,12 +245,13 @@ func ProcessDir(topDir string, opts *Options) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create file %s: %w", indexPath, err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
err = GetHTMLTemplate().Execute(file, templateData)
|
||||
if err != nil {
|
||||
if err := GetHTMLTemplate().Execute(file, templateData); err != nil {
|
||||
_ = file.Close()
|
||||
return fmt.Errorf("failed to execute template: %w", err)
|
||||
}
|
||||
if err := file.Close(); err != nil {
|
||||
return fmt.Errorf("failed to close file %s: %w", indexPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Recursive {
|
||||
|
||||
@@ -271,7 +271,7 @@ func TestReadDirEntries(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to write to file: %v", err)
|
||||
}
|
||||
f.Close()
|
||||
_ = f.Close()
|
||||
}
|
||||
|
||||
// Create a subdirectory
|
||||
@@ -328,7 +328,7 @@ func TestReadDirEntriesWithHidden(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test file %s: %v", file, err)
|
||||
}
|
||||
f.Close()
|
||||
_ = f.Close()
|
||||
}
|
||||
|
||||
opts := &Options{
|
||||
@@ -365,7 +365,7 @@ func TestReadDirEntriesWithRegexExclusion(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test file %s: %v", file, err)
|
||||
}
|
||||
f.Close()
|
||||
_ = f.Close()
|
||||
}
|
||||
|
||||
regex := regexp.MustCompile("(build|node_modules)")
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestProcessDirBasic(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to write to file: %v", err)
|
||||
}
|
||||
f.Close()
|
||||
_ = f.Close()
|
||||
}
|
||||
|
||||
opts := &Options{
|
||||
@@ -85,7 +85,7 @@ func TestProcessDirRecursive(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create root file: %v", err)
|
||||
}
|
||||
f.Close()
|
||||
_ = f.Close()
|
||||
|
||||
// Create subdirectory with files
|
||||
subDir := filepath.Join(tempDir, "subdir")
|
||||
@@ -98,7 +98,7 @@ func TestProcessDirRecursive(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create sub file: %v", err)
|
||||
}
|
||||
subFile.Close()
|
||||
_ = subFile.Close()
|
||||
|
||||
// Create nested subdirectory
|
||||
nestedDir := filepath.Join(subDir, "nested")
|
||||
@@ -111,7 +111,7 @@ func TestProcessDirRecursive(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create nested file: %v", err)
|
||||
}
|
||||
nestedFile.Close()
|
||||
_ = nestedFile.Close()
|
||||
|
||||
opts := &Options{
|
||||
TopDir: tempDir,
|
||||
@@ -174,7 +174,7 @@ func TestProcessDirWithExcludeRegex(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test file %s: %v", file, err)
|
||||
}
|
||||
f.Close()
|
||||
_ = f.Close()
|
||||
}
|
||||
|
||||
regex := regexp.MustCompile("(tmp|node_modules)")
|
||||
@@ -259,7 +259,7 @@ func TestProcessDirVerbose(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test file: %v", err)
|
||||
}
|
||||
f.Close()
|
||||
_ = f.Close()
|
||||
|
||||
opts := &Options{
|
||||
TopDir: tempDir,
|
||||
@@ -308,7 +308,7 @@ func TestProcessDirWithSymlinks(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to write to file: %v", err)
|
||||
}
|
||||
f.Close()
|
||||
_ = f.Close()
|
||||
|
||||
// Create a symlink to the file (skip on Windows)
|
||||
symlinkFile := filepath.Join(tempDir, "symlink.txt")
|
||||
|
||||
Reference in New Issue
Block a user