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:
@@ -15,7 +15,7 @@ LDFLAGS := -s -w \
|
|||||||
# beyond switching net/dns to the pure-Go resolver.
|
# beyond switching net/dns to the pure-Go resolver.
|
||||||
export CGO_ENABLED := 0
|
export CGO_ENABLED := 0
|
||||||
|
|
||||||
.PHONY: help all build build-amd64 build-arm64 test pkg-deb fmt vet lint check clean
|
.PHONY: help all build build-amd64 build-arm64 test pkg-deb fmt fixstyle vet lint check clean
|
||||||
|
|
||||||
help: ## Show this help
|
help: ## Show this help
|
||||||
@printf "Usage: make <target>\n\nTargets:\n"
|
@printf "Usage: make <target>\n\nTargets:\n"
|
||||||
@@ -45,6 +45,9 @@ pkg-deb: build-amd64 build-arm64 ## Build .deb packages for amd64 and arm64
|
|||||||
fmt: ## go fmt everything
|
fmt: ## go fmt everything
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
|
|
||||||
|
fixstyle: ## Reformat the entire tree with gofmt
|
||||||
|
gofmt -w .
|
||||||
|
|
||||||
vet: ## go vet everything
|
vet: ## go vet everything
|
||||||
go vet ./...
|
go vet ./...
|
||||||
|
|
||||||
|
|||||||
@@ -245,12 +245,13 @@ func ProcessDir(topDir string, opts *Options) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot create file %s: %w", indexPath, err)
|
return fmt.Errorf("cannot create file %s: %w", indexPath, err)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
if err := GetHTMLTemplate().Execute(file, templateData); err != nil {
|
||||||
|
_ = file.Close()
|
||||||
err = GetHTMLTemplate().Execute(file, templateData)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to execute template: %w", err)
|
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 {
|
if opts.Recursive {
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ func TestReadDirEntries(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to write to file: %v", err)
|
t.Fatalf("Failed to write to file: %v", err)
|
||||||
}
|
}
|
||||||
f.Close()
|
_ = f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a subdirectory
|
// Create a subdirectory
|
||||||
@@ -328,7 +328,7 @@ func TestReadDirEntriesWithHidden(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create test file %s: %v", file, err)
|
t.Fatalf("Failed to create test file %s: %v", file, err)
|
||||||
}
|
}
|
||||||
f.Close()
|
_ = f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := &Options{
|
opts := &Options{
|
||||||
@@ -365,7 +365,7 @@ func TestReadDirEntriesWithRegexExclusion(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create test file %s: %v", file, err)
|
t.Fatalf("Failed to create test file %s: %v", file, err)
|
||||||
}
|
}
|
||||||
f.Close()
|
_ = f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
regex := regexp.MustCompile("(build|node_modules)")
|
regex := regexp.MustCompile("(build|node_modules)")
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func TestProcessDirBasic(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to write to file: %v", err)
|
t.Fatalf("Failed to write to file: %v", err)
|
||||||
}
|
}
|
||||||
f.Close()
|
_ = f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := &Options{
|
opts := &Options{
|
||||||
@@ -85,7 +85,7 @@ func TestProcessDirRecursive(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create root file: %v", err)
|
t.Fatalf("Failed to create root file: %v", err)
|
||||||
}
|
}
|
||||||
f.Close()
|
_ = f.Close()
|
||||||
|
|
||||||
// Create subdirectory with files
|
// Create subdirectory with files
|
||||||
subDir := filepath.Join(tempDir, "subdir")
|
subDir := filepath.Join(tempDir, "subdir")
|
||||||
@@ -98,7 +98,7 @@ func TestProcessDirRecursive(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create sub file: %v", err)
|
t.Fatalf("Failed to create sub file: %v", err)
|
||||||
}
|
}
|
||||||
subFile.Close()
|
_ = subFile.Close()
|
||||||
|
|
||||||
// Create nested subdirectory
|
// Create nested subdirectory
|
||||||
nestedDir := filepath.Join(subDir, "nested")
|
nestedDir := filepath.Join(subDir, "nested")
|
||||||
@@ -111,7 +111,7 @@ func TestProcessDirRecursive(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create nested file: %v", err)
|
t.Fatalf("Failed to create nested file: %v", err)
|
||||||
}
|
}
|
||||||
nestedFile.Close()
|
_ = nestedFile.Close()
|
||||||
|
|
||||||
opts := &Options{
|
opts := &Options{
|
||||||
TopDir: tempDir,
|
TopDir: tempDir,
|
||||||
@@ -174,7 +174,7 @@ func TestProcessDirWithExcludeRegex(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create test file %s: %v", file, err)
|
t.Fatalf("Failed to create test file %s: %v", file, err)
|
||||||
}
|
}
|
||||||
f.Close()
|
_ = f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
regex := regexp.MustCompile("(tmp|node_modules)")
|
regex := regexp.MustCompile("(tmp|node_modules)")
|
||||||
@@ -259,7 +259,7 @@ func TestProcessDirVerbose(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create test file: %v", err)
|
t.Fatalf("Failed to create test file: %v", err)
|
||||||
}
|
}
|
||||||
f.Close()
|
_ = f.Close()
|
||||||
|
|
||||||
opts := &Options{
|
opts := &Options{
|
||||||
TopDir: tempDir,
|
TopDir: tempDir,
|
||||||
@@ -308,7 +308,7 @@ func TestProcessDirWithSymlinks(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to write to file: %v", err)
|
t.Fatalf("Failed to write to file: %v", err)
|
||||||
}
|
}
|
||||||
f.Close()
|
_ = f.Close()
|
||||||
|
|
||||||
// Create a symlink to the file (skip on Windows)
|
// Create a symlink to the file (skip on Windows)
|
||||||
symlinkFile := filepath.Join(tempDir, "symlink.txt")
|
symlinkFile := filepath.Join(tempDir, "symlink.txt")
|
||||||
|
|||||||
Reference in New Issue
Block a user