Skip to content

Commit 43a74f4

Browse files
committed
feat: add golangci-lint config and fix lint issues
1 parent c9d6dd9 commit 43a74f4

4 files changed

Lines changed: 56 additions & 7 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
*.dylib
77
*.test
88
*.out
9+
.cache/
10+
.gocache/
11+
12+
# Test artifacts
13+
reports/
914

1015
# Common Go outputs
1116
/bin/

.golangci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version: "2"
2+
3+
run:
4+
timeout: "5m"
5+
tests: true
6+
7+
linters:
8+
enable:
9+
- govet
10+
- errcheck
11+
- staticcheck
12+
- unused
13+
- ineffassign
14+
- whitespace
15+
- gocyclo
16+
17+
formatters:
18+
enable:
19+
- gofmt
20+
- gci
21+
settings:
22+
gci:
23+
sections:
24+
- standard
25+
- default
26+
- localmodule
27+
28+
issues:
29+
new: false
30+
fix: true
31+
32+
output:
33+
show-stats: true
34+
formats:
35+
text:
36+
path: reports/linters-out.txt
37+
print-linter-name: true
38+
print-issued-lines: true
39+
colors: true

internal/config/config.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
"path/filepath"
88
"strings"
99

10-
"github.com/singl3focus/pmp/internal/block"
1110
"gopkg.in/yaml.v3"
11+
12+
"github.com/singl3focus/pmp/internal/block"
1213
)
1314

1415
var ErrConfigNotFound = errors.New("no pmp config found; run `pmp init` or `pmp init --global`")
@@ -198,18 +199,21 @@ func discoverProjectRoot(start string) (string, error) {
198199
}
199200
}
200201

201-
func loadFile(path string) (fileConfig, error) {
202+
func loadFile(path string) (cfg fileConfig, err error) {
202203
file, err := os.Open(path)
203204
if err != nil {
204205
return fileConfig{}, fmt.Errorf("read config %s: %w", path, err)
205206
}
206-
defer file.Close()
207+
defer func() {
208+
if closeErr := file.Close(); err == nil && closeErr != nil {
209+
err = fmt.Errorf("close config %s: %w", path, closeErr)
210+
}
211+
}()
207212

208-
var cfg fileConfig
209213
dec := yaml.NewDecoder(file)
210214
dec.KnownFields(true)
211-
if err := dec.Decode(&cfg); err != nil {
212-
return fileConfig{}, fmt.Errorf("parse config %s: %w", path, err)
215+
if decodeErr := dec.Decode(&cfg); decodeErr != nil {
216+
return fileConfig{}, fmt.Errorf("parse config %s: %w", path, decodeErr)
213217
}
214218
if cfg.MessagePosition != "" &&
215219
cfg.MessagePosition != MessagePositionTop &&

internal/engine/engine.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import (
88
"text/template"
99
"time"
1010

11+
"github.com/tiktoken-go/tokenizer"
12+
1113
"github.com/singl3focus/pmp/internal/block"
1214
"github.com/singl3focus/pmp/internal/config"
13-
"github.com/tiktoken-go/tokenizer"
1415
)
1516

1617
type BuildRequest struct {

0 commit comments

Comments
 (0)