Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit 33539e2

Browse files
committed
feat: add golangci && resolve current lint errors
1 parent bce2ec5 commit 33539e2

26 files changed

Lines changed: 138 additions & 119 deletions

File tree

.github/workflows/golangci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
golangci:
13+
strategy:
14+
matrix:
15+
go: [stable]
16+
os: [ubuntu-latest, macos-latest, windows-latest]
17+
name: lint
18+
runs-on: ${{ matrix.os }}
19+
steps:
20+
- uses: actions/checkout@v4
21+
- uses: actions/setup-go@v5
22+
with:
23+
go-version: ${{ matrix.go }}
24+
- name: golangci-lint
25+
uses: golangci/golangci-lint-action@v7
26+
with:
27+
version: v2.0

cmd/root.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
tea "github.com/charmbracelet/bubbletea"
11+
zone "github.com/lrstanley/bubblezone"
1112
"github.com/opencode-ai/opencode/internal/app"
1213
"github.com/opencode-ai/opencode/internal/config"
1314
"github.com/opencode-ai/opencode/internal/db"
@@ -16,7 +17,6 @@ import (
1617
"github.com/opencode-ai/opencode/internal/pubsub"
1718
"github.com/opencode-ai/opencode/internal/tui"
1819
"github.com/opencode-ai/opencode/internal/version"
19-
zone "github.com/lrstanley/bubblezone"
2020
"github.com/spf13/cobra"
2121
)
2222

@@ -29,8 +29,7 @@ to assist developers in writing, debugging, and understanding code directly from
2929
RunE: func(cmd *cobra.Command, args []string) error {
3030
// If the help flag is set, show the help message
3131
if cmd.Flag("help").Changed {
32-
cmd.Help()
33-
return nil
32+
return cmd.Help()
3433
}
3534
if cmd.Flag("version").Changed {
3635
fmt.Println(version.Version)

internal/app/lsp.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (app *App) initLSPClients(ctx context.Context) {
2525
func (app *App) createAndStartLSPClient(ctx context.Context, name string, command string, args ...string) {
2626
// Create a specific context for initialization with a timeout
2727
logging.Info("Creating LSP client", "name", name, "command", command, "args", args)
28-
28+
2929
// Create the LSP client
3030
lspClient, err := lsp.NewClient(ctx, command, args...)
3131
if err != nil {
@@ -36,13 +36,13 @@ func (app *App) createAndStartLSPClient(ctx context.Context, name string, comman
3636
// Create a longer timeout for initialization (some servers take time to start)
3737
initCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
3838
defer cancel()
39-
39+
4040
// Initialize with the initialization context
4141
_, err = lspClient.InitializeLSPClient(initCtx, config.WorkingDirectory())
4242
if err != nil {
4343
logging.Error("Initialize failed", "name", name, "error", err)
4444
// Clean up the client to prevent resource leaks
45-
lspClient.Close()
45+
lspClient.Close() //nolint:errcheck
4646
return
4747
}
4848

@@ -57,13 +57,15 @@ func (app *App) createAndStartLSPClient(ctx context.Context, name string, comman
5757
}
5858

5959
logging.Info("LSP client initialized", "name", name)
60-
60+
6161
// Create a child context that can be canceled when the app is shutting down
6262
watchCtx, cancelFunc := context.WithCancel(ctx)
63-
63+
6464
// Create a context with the server name for better identification
65+
//nolint:staticcheck
66+
//lint:ignore SA1029 will be resolved in the future
6567
watchCtx = context.WithValue(watchCtx, "serverName", name)
66-
68+
6769
// Create the workspace watcher
6870
workspaceWatcher := watcher.NewWorkspaceWatcher(lspClient)
6971

internal/config/config.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ func Load(workingDir string, debug bool) (*Config, error) {
127127
}
128128

129129
// Load and merge local config
130-
mergeLocalConfig(workingDir)
130+
if err := mergeLocalConfig(workingDir); err != nil {
131+
return cfg, err
132+
}
131133

132134
// Apply configuration to the struct
133135
if err := viper.Unmarshal(cfg); err != nil {
@@ -315,16 +317,17 @@ func readConfig(err error) error {
315317
}
316318

317319
// mergeLocalConfig loads and merges configuration from the local directory.
318-
func mergeLocalConfig(workingDir string) {
320+
func mergeLocalConfig(workingDir string) error {
319321
local := viper.New()
320322
local.SetConfigName(fmt.Sprintf(".%s", appName))
321323
local.SetConfigType("json")
322324
local.AddConfigPath(workingDir)
323325

324326
// Merge local config if it exists
325327
if err := local.ReadInConfig(); err == nil {
326-
viper.MergeConfigMap(local.AllSettings())
328+
return viper.MergeConfigMap(local.AllSettings())
327329
}
330+
return nil
328331
}
329332

330333
// applyDefaultValues sets default values for configuration fields that need processing.

internal/config/init.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ func MarkProjectInitialized() error {
5454
if err != nil {
5555
return fmt.Errorf("failed to create init flag file: %w", err)
5656
}
57-
defer file.Close()
57+
defer file.Close() //nolint:errcheck
5858

5959
return nil
6060
}
61-

internal/db/connect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func Connect() (*sql.DB, error) {
3232

3333
// Verify connection
3434
if err = db.Ping(); err != nil {
35-
db.Close()
35+
db.Close() //nolint:errcheck
3636
return nil, fmt.Errorf("failed to connect to database: %w", err)
3737
}
3838

internal/history/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (s *service) createWithVersion(ctx context.Context, sessionID, path, conten
121121
})
122122
if txErr != nil {
123123
// Rollback the transaction
124-
tx.Rollback()
124+
tx.Rollback() //nolint:errcheck
125125

126126
// Check if this is a uniqueness constraint violation
127127
if strings.Contains(txErr.Error(), "UNIQUE constraint failed") {

internal/llm/agent/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func (a *agent) processGeneration(ctx context.Context, sessionID, content string
222222
if err != nil {
223223
if errors.Is(err, context.Canceled) {
224224
agentMessage.AddFinish(message.FinishReasonCanceled)
225-
a.messages.Update(context.Background(), agentMessage)
225+
a.messages.Update(context.Background(), agentMessage) //nolint:errcheck
226226
return a.err(ErrRequestCancelled)
227227
}
228228
return a.err(fmt.Errorf("failed to process events: %w", err))

internal/llm/agent/mcp-tools.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (b *mcpTool) Info() tools.ToolInfo {
4242
}
4343

4444
func runTool(ctx context.Context, c MCPClient, toolName string, input string) (tools.ToolResponse, error) {
45-
defer c.Close()
45+
defer c.Close() //nolint:errcheck
4646
initRequest := mcp.InitializeRequest{}
4747
initRequest.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION
4848
initRequest.Params.ClientInfo = mcp.Implementation{
@@ -158,7 +158,7 @@ func getTools(ctx context.Context, name string, m config.MCPServer, permissions
158158
for _, t := range tools.Tools {
159159
stdioTools = append(stdioTools, NewMcpTool(name, t, permissions, m))
160160
}
161-
defer c.Close()
161+
defer c.Close() //nolint:errcheck
162162
return stdioTools
163163
}
164164

internal/llm/prompt/prompt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func processContextPaths(workDir string, paths []string) string {
7171
defer wg.Done()
7272

7373
if strings.HasSuffix(p, "/") {
74-
filepath.WalkDir(filepath.Join(workDir, p), func(path string, d os.DirEntry, err error) error {
74+
filepath.WalkDir(filepath.Join(workDir, p), func(path string, d os.DirEntry, err error) error { //nolint:errcheck
7575
if err != nil {
7676
return err
7777
}

0 commit comments

Comments
 (0)