From e698239ace608a9ea084be6fd8bc2c89f273306a Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 31 Jul 2025 12:26:57 -0300 Subject: [PATCH] fix: lint noctx issues ignored slog because in our case it doesn't matter. --- .golangci.yml | 4 ++++ internal/fsext/fileutil.go | 9 +++++---- internal/llm/tools/glob.go | 6 +++--- internal/llm/tools/grep.go | 10 +++++----- internal/tui/components/chat/editor/editor.go | 3 ++- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 6c235c71adb9bb68e2f41a3bfafbfd248abcba12..64474889efd1129fe35b247bcf389f646cb03922 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -33,6 +33,10 @@ linters: generated: lax presets: - common-false-positives + rules: + - text: '(slog|log)\.\w+' + linters: + - noctx issues: max-issues-per-linter: 0 max-same-issues: 0 diff --git a/internal/fsext/fileutil.go b/internal/fsext/fileutil.go index 4a64b96859f5b9da1122816e1c2685b769c714c1..aee72bb1a5fa1affbd36e86e73f02d8407fa982b 100644 --- a/internal/fsext/fileutil.go +++ b/internal/fsext/fileutil.go @@ -1,6 +1,7 @@ package fsext import ( + "context" "fmt" "log/slog" "os" @@ -29,7 +30,7 @@ func init() { } } -func GetRgCmd(globPattern string) *exec.Cmd { +func GetRgCmd(ctx context.Context, globPattern string) *exec.Cmd { if rgPath == "" { return nil } @@ -44,10 +45,10 @@ func GetRgCmd(globPattern string) *exec.Cmd { } rgArgs = append(rgArgs, "--glob", globPattern) } - return exec.Command(rgPath, rgArgs...) + return exec.CommandContext(ctx, rgPath, rgArgs...) } -func GetRgSearchCmd(pattern, path, include string) *exec.Cmd { +func GetRgSearchCmd(ctx context.Context, pattern, path, include string) *exec.Cmd { if rgPath == "" { return nil } @@ -58,7 +59,7 @@ func GetRgSearchCmd(pattern, path, include string) *exec.Cmd { } args = append(args, path) - return exec.Command(rgPath, args...) + return exec.CommandContext(ctx, rgPath, args...) } type FileInfo struct { diff --git a/internal/llm/tools/glob.go b/internal/llm/tools/glob.go index 5af6e055574e3f85b68d8616b44d361790c0a3fb..3fe71fa3a9a9f4ae65835eb1f5be5fc66b75deab 100644 --- a/internal/llm/tools/glob.go +++ b/internal/llm/tools/glob.go @@ -114,7 +114,7 @@ func (g *globTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error) searchPath = g.workingDir } - files, truncated, err := globFiles(params.Pattern, searchPath, 100) + files, truncated, err := globFiles(ctx, params.Pattern, searchPath, 100) if err != nil { return ToolResponse{}, fmt.Errorf("error finding files: %w", err) } @@ -138,8 +138,8 @@ func (g *globTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error) ), nil } -func globFiles(pattern, searchPath string, limit int) ([]string, bool, error) { - cmdRg := fsext.GetRgCmd(pattern) +func globFiles(ctx context.Context, pattern, searchPath string, limit int) ([]string, bool, error) { + cmdRg := fsext.GetRgCmd(ctx, pattern) if cmdRg != nil { cmdRg.Dir = searchPath matches, err := runRipgrep(cmdRg, searchPath, limit) diff --git a/internal/llm/tools/grep.go b/internal/llm/tools/grep.go index 0b39c63484bb9508e14865215bf5e57430efe468..b8af7cb22261316feeee3d9db25100a1d4bd72de 100644 --- a/internal/llm/tools/grep.go +++ b/internal/llm/tools/grep.go @@ -206,7 +206,7 @@ func (g *grepTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error) searchPath = g.workingDir } - matches, truncated, err := searchFiles(searchPattern, searchPath, params.Include, 100) + matches, truncated, err := searchFiles(ctx, searchPattern, searchPath, params.Include, 100) if err != nil { return ToolResponse{}, fmt.Errorf("error searching files: %w", err) } @@ -247,8 +247,8 @@ func (g *grepTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error) ), nil } -func searchFiles(pattern, rootPath, include string, limit int) ([]grepMatch, bool, error) { - matches, err := searchWithRipgrep(pattern, rootPath, include) +func searchFiles(ctx context.Context, pattern, rootPath, include string, limit int) ([]grepMatch, bool, error) { + matches, err := searchWithRipgrep(ctx, pattern, rootPath, include) if err != nil { matches, err = searchFilesWithRegex(pattern, rootPath, include) if err != nil { @@ -268,8 +268,8 @@ func searchFiles(pattern, rootPath, include string, limit int) ([]grepMatch, boo return matches, truncated, nil } -func searchWithRipgrep(pattern, path, include string) ([]grepMatch, error) { - cmd := fsext.GetRgSearchCmd(pattern, path, include) +func searchWithRipgrep(ctx context.Context, pattern, path, include string) ([]grepMatch, error) { + cmd := fsext.GetRgSearchCmd(ctx, pattern, path, include) if cmd == nil { return nil, fmt.Errorf("ripgrep not found in $PATH") } diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index 6a9973da83a91111f1652bd59a03351a2e4216bd..4c7df84daad5b911be66dcd7f7cf6d832d714293 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -1,6 +1,7 @@ package editor import ( + "context" "fmt" "math/rand" "net/http" @@ -110,7 +111,7 @@ func (m *editorCmp) openEditor(value string) tea.Cmd { if _, err := tmpfile.WriteString(value); err != nil { return util.ReportError(err) } - c := exec.Command(editor, tmpfile.Name()) + c := exec.CommandContext(context.TODO(), editor, tmpfile.Name()) c.Stdin = os.Stdin c.Stdout = os.Stdout c.Stderr = os.Stderr