Skip to content

Commit cc523eb

Browse files
greynewellclaude
andcommitted
fix(lint): resolve golangci-lint failures from compact feature
- defer os.RemoveAll now discards the error explicitly via _ = (errcheck) - Remove space around % operator in name generation (goimports) - 0o755 → 0o750 and 0o644 → 0o600 for dir/file creation (gosec G301/G306) - Add nolint:gocyclo to shortenFuncLocals and stripComments (state machines) - Add comment to exported Language const block (revive) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ec0c22f commit cc523eb

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

cmd/compact.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func compactDir(errOut io.Writer, dir, outDir string, dryRun bool) error {
104104
if err != nil {
105105
return err
106106
}
107-
defer os.RemoveAll(tmp)
107+
defer func() { _ = os.RemoveAll(tmp) }()
108108
stats, walkErr = compact.CompactDir(dir, tmp)
109109
if walkErr != nil {
110110
return walkErr

internal/compact/handler.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
// Language is a recognised source language.
1818
type Language string
1919

20+
// Supported language values for Language.
2021
const (
2122
Go Language = "go"
2223
Python Language = "python"
@@ -191,7 +192,7 @@ func shortenIdents(f *ast.File) {
191192
}
192193

193194
// shortenFuncLocals renames long local identifiers inside fn.
194-
func shortenFuncLocals(fn *ast.FuncDecl) {
195+
func shortenFuncLocals(fn *ast.FuncDecl) { //nolint:gocyclo
195196
// Phase 1: collect all existing identifier names to avoid collisions.
196197
existing := map[string]bool{}
197198
ast.Inspect(fn, func(n ast.Node) bool {
@@ -316,7 +317,7 @@ func nextShortName(counter *int, existing map[string]bool) string {
316317
} else {
317318
n -= len(letters)
318319
rows := len(letters)
319-
name = string([]byte{letters[(n/rows) % rows], letters[n%rows]})
320+
name = string([]byte{letters[(n/rows)%rows], letters[n%rows]})
320321
}
321322
if !existing[name] && !goBuiltins[name] {
322323
return name
@@ -333,7 +334,7 @@ func compactGeneric(src []byte, lang Language) []byte {
333334
// stripComments removes line and block comments from src.
334335
// It tracks string literal state to avoid treating comment-like sequences
335336
// inside strings as comments.
336-
func stripComments(src []byte, lang Language) []byte {
337+
func stripComments(src []byte, lang Language) []byte { //nolint:gocyclo
337338
out := make([]byte, 0, len(src))
338339
i, n := 0, len(src)
339340

@@ -482,11 +483,11 @@ func CompactDir(dir, outDir string) (Stats, error) {
482483
if outDir != "" {
483484
rel, _ := filepath.Rel(dir, path)
484485
dest = filepath.Join(outDir, rel)
485-
if mkErr := os.MkdirAll(filepath.Dir(dest), 0o755); mkErr != nil {
486+
if mkErr := os.MkdirAll(filepath.Dir(dest), 0o750); mkErr != nil {
486487
return mkErr
487488
}
488489
}
489-
return os.WriteFile(dest, compacted, 0o644)
490+
return os.WriteFile(dest, compacted, 0o600)
490491
})
491492
return stats, err
492493
}

0 commit comments

Comments
 (0)