Skip to content

chore: migrate to golangci-lint v2 #962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
version: "2"
run:
timeout: 5m

output:
formats:
- format: colored-line-number

text:
path: stdout
linters:
disable-all: true
default: none
enable:
- errcheck
- gofmt
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- thelper
- unused
- goimports
- whitespace
- revive
fast: false
- errcheck
- govet
- ineffassign
- revive
- staticcheck
- thelper
- unused
- whitespace
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
issues:
max-same-issues: 50
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ smoke: build
smoke:
go test -v -tags='smoke' ./pkg/tests/smoke/...

GOLANGCI_LINT_VERSION ?= v1.60.1
GOLANGCI_LINT_VERSION ?= v2.1.2
lint:
if ! command -v golangci-lint &> /dev/null; then \
echo "Could not find golangci-lint, installing version $(GOLANGCI_LINT_VERSION)."; \
Expand Down
4 changes: 2 additions & 2 deletions pkg/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ func DefaultModel(name, defaultModel string) (types.Tool, bool) {
// Legacy syntax not used anymore
name = strings.TrimSuffix(name, "?")
t, ok := tools[name]
t.Parameters.Name = name
t.Parameters.ModelName = defaultModel
t.Name = name
t.ModelName = defaultModel
t.ID = name
t.Instructions = "#!" + name
return SetDefaults(t), ok
Expand Down
4 changes: 2 additions & 2 deletions pkg/builtin/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func SetDefaultModel(model string) {
}

func SetDefaults(tool types.Tool) types.Tool {
if tool.Parameters.ModelName == "" {
tool.Parameters.ModelName = GetDefaultModel()
if tool.ModelName == "" {
tool.ModelName = GetDefaultModel()
}
return tool
}
2 changes: 1 addition & 1 deletion pkg/chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func Start(ctx context.Context, prevState runner.ChatState, chatter Chatter, prg
if startInput != "" {
input = startInput
startInput = ""
} else if targetTool := prog.ToolSet[prog.EntryToolID]; !((prevState == nil || prevState == "") && targetTool.Arguments == nil && targetTool.Instructions != "") {
} else if targetTool := prog.ToolSet[prog.EntryToolID]; prevState != nil && prevState != "" || targetTool.Arguments != nil || targetTool.Instructions == "" {
// The above logic will skip prompting if this is the first loop and the chat expects no args
input, ok, err = prompter.Readline()
if !ok || err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/cli/gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {

// If the file is external, then set the SCRIPTS_PATH to the current working directory. Otherwise,
// set it to the directory of the script and set the file to the base.
if !(strings.HasPrefix(file, "http://") || strings.HasPrefix(file, "https://") || strings.HasPrefix(file, "github.com")) {
if !strings.HasPrefix(file, "http://") && !strings.HasPrefix(file, "https://") && !strings.HasPrefix(file, "github.com") {
absPathToScript, err := filepath.Abs(file)
if err != nil {
return fmt.Errorf("cannot determine absolute path to script %s: %v", file, err)
Expand Down Expand Up @@ -469,8 +469,8 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
// Don't use cmd.Context() because then sigint will cancel everything
return tui.Run(context.Background(), args[0], tui.RunOptions{
ClientOpts: &gptscript2.GlobalOptions{
OpenAIAPIKey: r.OpenAIOptions.APIKey,
OpenAIBaseURL: r.OpenAIOptions.BaseURL,
OpenAIAPIKey: r.APIKey,
OpenAIBaseURL: r.BaseURL,
DefaultModel: r.DefaultModel,
DefaultModelProvider: r.DefaultModelProvider,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (e *Engine) runCommand(ctx Context, tool types.Tool, input string, toolCate
// If this is a sub-call, then don't return the error; return the error as a message so that the LLM can retry.
return fmt.Sprintf("ERROR: got (%v) while running tool, OUTPUT: %s", err, stdoutAndErr), nil
}
log.Errorf("failed to run tool [%s] cmd %v: %v", tool.Parameters.Name, cmd.Args, err)
log.Errorf("failed to run tool [%s] cmd %v: %v", tool.Name, cmd.Args, err)
return "", fmt.Errorf("ERROR: %s: %w", stdoutAndErr, err)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/engine/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (e *Engine) startDaemon(tool types.Tool) (string, error) {
return w.Close()
}

log.Infof("launched [%s][%s] port [%d] %v", tool.Parameters.Name, tool.ID, port, cmd.Args)
log.Infof("launched [%s][%s] port [%d] %v", tool.Name, tool.ID, port, cmd.Args)
if err := cmd.Start(); err != nil {
stop()
return url, err
Expand All @@ -195,7 +195,7 @@ func (e *Engine) startDaemon(tool types.Tool) (string, error) {
go func() {
err := cmd.Wait()
if err != nil {
log.Debugf("daemon exited tool [%s] %v: %v", tool.Parameters.Name, cmd.Args, err)
log.Debugf("daemon exited tool [%s] %v: %v", tool.Name, cmd.Args, err)
}
_ = r.Close()
_ = w.Close()
Expand Down
14 changes: 7 additions & 7 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,13 @@ func (c *Context) WrappedContext(e *Engine) context.Context {
}

func populateMessageParams(ctx Context, completion *types.CompletionRequest, tool types.Tool) error {
completion.Model = tool.Parameters.ModelName
completion.MaxTokens = tool.Parameters.MaxTokens
completion.JSONResponse = tool.Parameters.JSONResponse
completion.Cache = tool.Parameters.Cache
completion.Chat = tool.Parameters.Chat
completion.Temperature = tool.Parameters.Temperature
completion.InternalSystemPrompt = tool.Parameters.InternalPrompt
completion.Model = tool.ModelName
completion.MaxTokens = tool.MaxTokens
completion.JSONResponse = tool.JSONResponse
completion.Cache = tool.Cache
completion.Chat = tool.Chat
completion.Temperature = tool.Temperature
completion.InternalSystemPrompt = tool.InternalPrompt

if tool.Chat && completion.InternalSystemPrompt == nil {
completion.InternalSystemPrompt = new(bool)
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (e *Engine) runHTTP(ctx Context, tool types.Tool, input string) (cmdRet *Re
}
}

req.Header.Set("X-GPTScript-Tool-Name", tool.Parameters.Name)
req.Header.Set("X-GPTScript-Tool-Name", tool.Name)

if err := json.Unmarshal([]byte(input), &map[string]any{}); err == nil {
req.Header.Set("Content-Type", "application/json")
Expand Down
22 changes: 11 additions & 11 deletions pkg/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
// Probably a better way to come up with an ID
tool.ID = tool.Source.Location + ":" + tool.Name

if i != 0 && tool.Parameters.Name == "" {
if i != 0 && tool.Name == "" {
return nil, parser.NewErrLine(tool.Source.Location, tool.Source.LineNo, fmt.Errorf("only the first tool in a file can have no name"))
}

if i != 0 && tool.Parameters.GlobalModelName != "" {
if i != 0 && tool.GlobalModelName != "" {
return nil, parser.NewErrLine(tool.Source.Location, tool.Source.LineNo, fmt.Errorf("only the first tool in a file can have global model name"))
}

if i != 0 && len(tool.Parameters.GlobalTools) > 0 {
if i != 0 && len(tool.GlobalTools) > 0 {
return nil, parser.NewErrLine(tool.Source.Location, tool.Source.LineNo, fmt.Errorf("only the first tool in a file can have global tools"))
}

Expand All @@ -245,8 +245,8 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
targetTools = append(targetTools, tool)
}

if targetToolName != "" && tool.Parameters.Name != "" {
if strings.EqualFold(tool.Parameters.Name, targetToolName) {
if targetToolName != "" && tool.Name != "" {
if strings.EqualFold(tool.Name, targetToolName) {
targetTools = append(targetTools, tool)
} else if strings.Contains(targetToolName, "*") {
var patterns []string
Expand All @@ -257,7 +257,7 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
}

for _, pattern := range patterns {
match, err := filepath.Match(strings.ToLower(pattern), strings.ToLower(tool.Parameters.Name))
match, err := filepath.Match(strings.ToLower(pattern), strings.ToLower(tool.Name))
if err != nil {
return nil, parser.NewErrLine(tool.Source.Location, tool.Source.LineNo, err)
}
Expand All @@ -270,13 +270,13 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
}
}

if existing, ok := localTools[strings.ToLower(tool.Parameters.Name)]; ok {
if existing, ok := localTools[strings.ToLower(tool.Name)]; ok {
return nil, parser.NewErrLine(tool.Source.Location, tool.Source.LineNo,
fmt.Errorf("duplicate tool name [%s] in %s found at lines %d and %d", tool.Parameters.Name, tool.Source.Location,
fmt.Errorf("duplicate tool name [%s] in %s found at lines %d and %d", tool.Name, tool.Source.Location,
tool.Source.LineNo, existing.Source.LineNo))
}

localTools[strings.ToLower(tool.Parameters.Name)] = tool
localTools[strings.ToLower(tool.Name)] = tool
}

return linkAll(ctx, cache, prg, base, targetTools, localTools, defaultModel)
Expand All @@ -285,7 +285,7 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
func linkAll(ctx context.Context, cache *cache.Client, prg *types.Program, base *source, tools []types.Tool, localTools types.ToolSet, defaultModel string) (result []types.Tool, _ error) {
localToolsMapping := make(map[string]string, len(tools))
for _, localTool := range localTools {
localToolsMapping[strings.ToLower(localTool.Parameters.Name)] = localTool.ID
localToolsMapping[strings.ToLower(localTool.Name)] = localTool.ID
}

for _, tool := range tools {
Expand Down Expand Up @@ -314,7 +314,7 @@ func link(ctx context.Context, cache *cache.Client, prg *types.Program, base *so
// The below is done in two loops so that local names stay as the tool names
// and don't get mangled by external references

for _, targetToolName := range tool.Parameters.ToolRefNames() {
for _, targetToolName := range tool.ToolRefNames() {
noArgs, _ := types.SplitArg(targetToolName)
localTool, ok := localTools[strings.ToLower(noArgs)]
if ok {
Expand Down
10 changes: 5 additions & 5 deletions pkg/loader/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ func getOpenAPITools(t *openapi3.T, defaultHost, source, targetToolName string)
}

// Add the new arg to the tool's arguments
tool.Parameters.Arguments.Properties[param.Value.Name] = &openapi3.SchemaRef{Value: arg}
tool.Arguments.Properties[param.Value.Name] = &openapi3.SchemaRef{Value: arg}

// Check whether it is required
if param.Value.Required {
tool.Parameters.Arguments.Required = append(tool.Parameters.Arguments.Required, param.Value.Name)
tool.Arguments.Required = append(tool.Arguments.Required, param.Value.Name)
}

// Add the parameter to the appropriate list for the tool's instructions
Expand Down Expand Up @@ -227,7 +227,7 @@ func getOpenAPITools(t *openapi3.T, defaultHost, source, targetToolName string)
}
// Unfortunately, the request body doesn't contain any good descriptor for it,
// so we just use "requestBodyContent" as the name of the arg.
tool.Parameters.Arguments.Properties["requestBodyContent"] = &openapi3.SchemaRef{Value: arg}
tool.Arguments.Properties["requestBodyContent"] = &openapi3.SchemaRef{Value: arg}
break
}

Expand Down Expand Up @@ -310,7 +310,7 @@ func getOpenAPITools(t *openapi3.T, defaultHost, source, targetToolName string)
}

// Register
toolNames = append(toolNames, tool.Parameters.Name)
toolNames = append(toolNames, tool.Name)
tools = append(tools, tool)
operationNum++
}
Expand Down Expand Up @@ -457,7 +457,7 @@ func getOpenAPIToolsRevamp(t *openapi3.T, source, targetToolName string) ([]type
exportTool := types.Tool{
ToolDef: types.ToolDef{
Parameters: types.Parameters{
Export: []string{list.Parameters.Name, getSchema.Parameters.Name, run.Parameters.Name},
Export: []string{list.Name, getSchema.Name, run.Name},
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/monitor/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func (c callName) String() string {

for {
tool := c.prg.ToolSet[currentCall.ToolID]
name := tool.Parameters.Name
name := tool.Name
if name == "" {
name = tool.Source.Location
}
Expand Down
Loading