fix: lint noctx issues

ignored slog because in our case it doesn't matter.
This commit is contained in:
Carlos Alexandro Becker
2025-07-31 12:26:57 -03:00
committed by Kujtim Hoxha
parent 3e213e89aa
commit e698239ace
5 changed files with 19 additions and 13 deletions

View File

@@ -33,6 +33,10 @@ linters:
generated: lax generated: lax
presets: presets:
- common-false-positives - common-false-positives
rules:
- text: '(slog|log)\.\w+'
linters:
- noctx
issues: issues:
max-issues-per-linter: 0 max-issues-per-linter: 0
max-same-issues: 0 max-same-issues: 0

View File

@@ -1,6 +1,7 @@
package fsext package fsext
import ( import (
"context"
"fmt" "fmt"
"log/slog" "log/slog"
"os" "os"
@@ -29,7 +30,7 @@ func init() {
} }
} }
func GetRgCmd(globPattern string) *exec.Cmd { func GetRgCmd(ctx context.Context, globPattern string) *exec.Cmd {
if rgPath == "" { if rgPath == "" {
return nil return nil
} }
@@ -44,10 +45,10 @@ func GetRgCmd(globPattern string) *exec.Cmd {
} }
rgArgs = append(rgArgs, "--glob", globPattern) 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 == "" { if rgPath == "" {
return nil return nil
} }
@@ -58,7 +59,7 @@ func GetRgSearchCmd(pattern, path, include string) *exec.Cmd {
} }
args = append(args, path) args = append(args, path)
return exec.Command(rgPath, args...) return exec.CommandContext(ctx, rgPath, args...)
} }
type FileInfo struct { type FileInfo struct {

View File

@@ -114,7 +114,7 @@ func (g *globTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
searchPath = g.workingDir searchPath = g.workingDir
} }
files, truncated, err := globFiles(params.Pattern, searchPath, 100) files, truncated, err := globFiles(ctx, params.Pattern, searchPath, 100)
if err != nil { if err != nil {
return ToolResponse{}, fmt.Errorf("error finding files: %w", err) 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 ), nil
} }
func globFiles(pattern, searchPath string, limit int) ([]string, bool, error) { func globFiles(ctx context.Context, pattern, searchPath string, limit int) ([]string, bool, error) {
cmdRg := fsext.GetRgCmd(pattern) cmdRg := fsext.GetRgCmd(ctx, pattern)
if cmdRg != nil { if cmdRg != nil {
cmdRg.Dir = searchPath cmdRg.Dir = searchPath
matches, err := runRipgrep(cmdRg, searchPath, limit) matches, err := runRipgrep(cmdRg, searchPath, limit)

View File

@@ -206,7 +206,7 @@ func (g *grepTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
searchPath = g.workingDir 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 { if err != nil {
return ToolResponse{}, fmt.Errorf("error searching files: %w", err) 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 ), nil
} }
func searchFiles(pattern, rootPath, include string, limit int) ([]grepMatch, bool, error) { func searchFiles(ctx context.Context, pattern, rootPath, include string, limit int) ([]grepMatch, bool, error) {
matches, err := searchWithRipgrep(pattern, rootPath, include) matches, err := searchWithRipgrep(ctx, pattern, rootPath, include)
if err != nil { if err != nil {
matches, err = searchFilesWithRegex(pattern, rootPath, include) matches, err = searchFilesWithRegex(pattern, rootPath, include)
if err != nil { if err != nil {
@@ -268,8 +268,8 @@ func searchFiles(pattern, rootPath, include string, limit int) ([]grepMatch, boo
return matches, truncated, nil return matches, truncated, nil
} }
func searchWithRipgrep(pattern, path, include string) ([]grepMatch, error) { func searchWithRipgrep(ctx context.Context, pattern, path, include string) ([]grepMatch, error) {
cmd := fsext.GetRgSearchCmd(pattern, path, include) cmd := fsext.GetRgSearchCmd(ctx, pattern, path, include)
if cmd == nil { if cmd == nil {
return nil, fmt.Errorf("ripgrep not found in $PATH") return nil, fmt.Errorf("ripgrep not found in $PATH")
} }

View File

@@ -1,6 +1,7 @@
package editor package editor
import ( import (
"context"
"fmt" "fmt"
"math/rand" "math/rand"
"net/http" "net/http"
@@ -110,7 +111,7 @@ func (m *editorCmp) openEditor(value string) tea.Cmd {
if _, err := tmpfile.WriteString(value); err != nil { if _, err := tmpfile.WriteString(value); err != nil {
return util.ReportError(err) return util.ReportError(err)
} }
c := exec.Command(editor, tmpfile.Name()) c := exec.CommandContext(context.TODO(), editor, tmpfile.Name())
c.Stdin = os.Stdin c.Stdin = os.Stdin
c.Stdout = os.Stdout c.Stdout = os.Stdout
c.Stderr = os.Stderr c.Stderr = os.Stderr