fix: resolve golangci-lint issues
Kujtim Hoxha
created 6 months ago
- Fix gofumpt formatting in models.go
- Replace deprecated database methods with context-aware versions:
- db.Ping() -> db.PingContext()
- db.Exec() -> db.ExecContext()
- db.Begin() -> db.BeginTx()
- Update Taskfile.yaml to match CI lint configuration
Change summary
Taskfile.yaml | 4 ++--
internal/db/connect.go | 5 +++--
internal/history/file.go | 2 +-
internal/tui/components/dialogs/models/models.go | 4 ++--
4 files changed, 8 insertions(+), 7 deletions(-)
Detailed changes
@@ -6,12 +6,12 @@ tasks:
lint:
desc: Run base linters
cmds:
- - golangci-lint run
+ - golangci-lint run --path-mode=abs --config=".golangci.yml" --timeout=5m
lint-fix:
desc: Run base linters and fix issues
cmds:
- - golangci-lint run --fix
+ - golangci-lint run --path-mode=abs --config=".golangci.yml" --timeout=5m --fix
test:
desc: Run tests
@@ -1,6 +1,7 @@
package db
import (
+ "context"
"database/sql"
"fmt"
"os"
@@ -31,7 +32,7 @@ func Connect() (*sql.DB, error) {
}
// Verify connection
- if err = db.Ping(); err != nil {
+ if err = db.PingContext(context.Background()); err != nil {
db.Close()
return nil, fmt.Errorf("failed to connect to database: %w", err)
}
@@ -46,7 +47,7 @@ func Connect() (*sql.DB, error) {
}
for _, pragma := range pragmas {
- if _, err = db.Exec(pragma); err != nil {
+ if _, err = db.ExecContext(context.Background(), pragma); err != nil {
logging.Error("Failed to set pragma", pragma, err)
} else {
logging.Debug("Set pragma", "pragma", pragma)
@@ -83,7 +83,7 @@ func (s *service) createWithVersion(ctx context.Context, sessionID, path, conten
// Retry loop for transaction conflicts
for attempt := range maxRetries {
// Start a transaction
- tx, txErr := s.db.Begin()
+ tx, txErr := s.db.BeginTx(ctx, nil)
if txErr != nil {
return File{}, fmt.Errorf("failed to begin transaction: %w", txErr)
}
@@ -219,7 +219,7 @@ func (m *modelDialogCmp) SetModelType(modelType int) tea.Cmd {
providers := config.Providers()
modelItems := []util.Model{}
selectIndex := 0
-
+
cfg := config.Get()
var currentModel config.PreferredModel
if m.modelType == LargeModelType {
@@ -227,7 +227,7 @@ func (m *modelDialogCmp) SetModelType(modelType int) tea.Cmd {
} else {
currentModel = cfg.Models.Small
}
-
+
for _, provider := range providers {
name := provider.Name
if name == "" {