on main help sign in
fix: lint noctx issues

ignored slog because in our case it doesn't matter.

commite698239ace608a9ea084be6fd8bc2c89f273306a authorCarlos Alexandro Becker <caarlos0@users.noreply.github.com> dateThu 31 Jul 2025, 12:26 (1 year ago) parent3e213e8
5 files changed+19−13
.golangci.yml+4 internal/fsext/fileutil.go+5−4 internal/llm/tools/glob.go+3−3 internal/llm/tools/grep.go+5−5 internal/tui/components/chat/editor/editor.go+2−1
.golangci.yml+4
@@ -33,6 +33,10 @@ linters:
3333 generated: lax
3434 presets:
3535 - common-false-positives
36+ rules:
37+ - text: '(slog|log)\.\w+'
38+ linters:
39+ - noctx
3640issues:
3741 max-issues-per-linter: 0
3842 max-same-issues: 0
internal/fsext/fileutil.go+5−4
@@ -1,6 +1,7 @@
11package fsext
22
33import (
4+ "context"
45 "fmt"
56 "log/slog"
67 "os"
@@ -29,7 +30,7 @@ func init() {
2930 }
3031}
3132
32−func GetRgCmd(globPattern string) *exec.Cmd {
33+func GetRgCmd(ctx context.Context, globPattern string) *exec.Cmd {
3334 if rgPath == "" {
3435 return nil
3536 }
@@ -44,10 +45,10 @@ func GetRgCmd(globPattern string) *exec.Cmd {
4445 }
4546 rgArgs = append(rgArgs, "--glob", globPattern)
4647 }
47− return exec.Command(rgPath, rgArgs...)
48+ return exec.CommandContext(ctx, rgPath, rgArgs...)
4849}
4950
50−func GetRgSearchCmd(pattern, path, include string) *exec.Cmd {
51+func GetRgSearchCmd(ctx context.Context, pattern, path, include string) *exec.Cmd {
5152 if rgPath == "" {
5253 return nil
5354 }
@@ -58,7 +59,7 @@ func GetRgSearchCmd(pattern, path, include string) *exec.Cmd {
5859 }
5960 args = append(args, path)
6061
61− return exec.Command(rgPath, args...)
62+ return exec.CommandContext(ctx, rgPath, args...)
6263}
6364
6465type FileInfo struct {
internal/llm/tools/glob.go+3−3
@@ -114,7 +114,7 @@ func (g *globTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
114114 searchPath = g.workingDir
115115 }
116116
117− files, truncated, err := globFiles(params.Pattern, searchPath, 100)
117+ files, truncated, err := globFiles(ctx, params.Pattern, searchPath, 100)
118118 if err != nil {
119119 return ToolResponse{}, fmt.Errorf("error finding files: %w", err)
120120 }
@@ -138,8 +138,8 @@ func (g *globTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
138138 ), nil
139139}
140140
141−func globFiles(pattern, searchPath string, limit int) ([]string, bool, error) {
142− cmdRg := fsext.GetRgCmd(pattern)
141+func globFiles(ctx context.Context, pattern, searchPath string, limit int) ([]string, bool, error) {
142+ cmdRg := fsext.GetRgCmd(ctx, pattern)
143143 if cmdRg != nil {
144144 cmdRg.Dir = searchPath
145145 matches, err := runRipgrep(cmdRg, searchPath, limit)
internal/llm/tools/grep.go+5−5
@@ -206,7 +206,7 @@ func (g *grepTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
206206 searchPath = g.workingDir
207207 }
208208
209− matches, truncated, err := searchFiles(searchPattern, searchPath, params.Include, 100)
209+ matches, truncated, err := searchFiles(ctx, searchPattern, searchPath, params.Include, 100)
210210 if err != nil {
211211 return ToolResponse{}, fmt.Errorf("error searching files: %w", err)
212212 }
@@ -247,8 +247,8 @@ func (g *grepTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
247247 ), nil
248248}
249249
250−func searchFiles(pattern, rootPath, include string, limit int) ([]grepMatch, bool, error) {
251− matches, err := searchWithRipgrep(pattern, rootPath, include)
250+func searchFiles(ctx context.Context, pattern, rootPath, include string, limit int) ([]grepMatch, bool, error) {
251+ matches, err := searchWithRipgrep(ctx, pattern, rootPath, include)
252252 if err != nil {
253253 matches, err = searchFilesWithRegex(pattern, rootPath, include)
254254 if err != nil {
@@ -268,8 +268,8 @@ func searchFiles(pattern, rootPath, include string, limit int) ([]grepMatch, boo
268268 return matches, truncated, nil
269269}
270270
271−func searchWithRipgrep(pattern, path, include string) ([]grepMatch, error) {
272− cmd := fsext.GetRgSearchCmd(pattern, path, include)
271+func searchWithRipgrep(ctx context.Context, pattern, path, include string) ([]grepMatch, error) {
272+ cmd := fsext.GetRgSearchCmd(ctx, pattern, path, include)
273273 if cmd == nil {
274274 return nil, fmt.Errorf("ripgrep not found in $PATH")
275275 }
internal/tui/components/chat/editor/editor.go+2−1
@@ -1,6 +1,7 @@
11package editor
22
33import (
4+ "context"
45 "fmt"
56 "math/rand"
67 "net/http"
@@ -110,7 +111,7 @@ func (m *editorCmp) openEditor(value string) tea.Cmd {
110111 if _, err := tmpfile.WriteString(value); err != nil {
111112 return util.ReportError(err)
112113 }
113− c := exec.Command(editor, tmpfile.Name())
114+ c := exec.CommandContext(context.TODO(), editor, tmpfile.Name())
114115 c.Stdin = os.Stdin
115116 c.Stdout = os.Stdout
116117 c.Stderr = os.Stderr