Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
with:
go-version: '1.24'
- name: golangci-lint
# NOTE: https://github.com/golangci/golangci-lint-action/releases/tag/v6.5.2
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84
# NOTE: https://github.com/golangci/golangci-lint-action/releases/tag/v8.0.0
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9
with:
version: v1.64.5
version: v2.5.0

static-check:
name: Staticcheck
Expand Down
19 changes: 3 additions & 16 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
version: "2"

linters:
default: none
enable:
- bodyclose
- copyloopvar
Expand All @@ -7,28 +10,12 @@ linters:
- gocritic
- gocyclo
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- prealloc
# - revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
fast: false
disable-all: true

issues:
exclude-dirs:
- docs
- vendor
exclude-rules:
- path: _test\.go
linters:
- gosec
- dupl
22 changes: 17 additions & 5 deletions internal/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ func Test_Run(t *testing.T) {
t.Setenv("OPENAI_API_KEY", "test-api-key")
tmpDir := t.TempDir()
originalWd, _ := os.Getwd()
os.Chdir(tmpDir)
return func() { os.Chdir(originalWd) }
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("failed to change directory: %v", err)
}
return func() {
if err := os.Chdir(originalWd); err != nil {
t.Errorf("failed to restore directory: %v", err)
}
}
},
expectedExitCode: 1,
},
Expand All @@ -47,13 +53,19 @@ func Test_Run(t *testing.T) {
originalArgs := os.Args

configPath := filepath.Join(tmpDir, "cmt.yaml")
os.WriteFile(configPath, []byte("gpt:\n model: gpt-4\n"), 0644)
if err := os.WriteFile(configPath, []byte("gpt:\n model: gpt-4\n"), 0600); err != nil {
t.Fatalf("failed to write config: %v", err)
}

os.Chdir(tmpDir)
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("failed to change directory: %v", err)
}
os.Args = []string{"cmt", "help"}

return func() {
os.Chdir(originalWd)
if err := os.Chdir(originalWd); err != nil {
t.Errorf("failed to restore directory: %v", err)
}
os.Args = originalArgs
}
},
Expand Down
2 changes: 2 additions & 0 deletions internal/app/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func Test_Diff(t *testing.T) {
}
}

//nolint:dupl
func Test_Log(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down Expand Up @@ -234,6 +235,7 @@ func Test_Log(t *testing.T) {
}
}

//nolint:dupl
func Test_Status(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down
22 changes: 17 additions & 5 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func writeTempConfig(t *testing.T, contents string) string {
t.Helper()
tmpDir := t.TempDir()
configPath := filepath.Join(tmpDir, "cmt.yaml")
err := os.WriteFile(configPath, []byte(contents), 0644)
err := os.WriteFile(configPath, []byte(contents), 0600)
if err != nil {
t.Fatalf("failed to write temp config: %v", err)
}
Expand Down Expand Up @@ -53,8 +53,14 @@ func Test_Load_WithInvalidConfig(t *testing.T) {

tmpDir := writeTempConfig(t, configContent)
originalWd, _ := os.Getwd()
os.Chdir(tmpDir)
defer os.Chdir(originalWd)
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("failed to change directory: %v", err)
}
defer func() {
if err := os.Chdir(originalWd); err != nil {
t.Errorf("failed to restore directory: %v", err)
}
}()

cfg, err := Load()

Expand All @@ -70,8 +76,14 @@ func Test_Load_WithBadYAML(t *testing.T) {

tmpDir := writeTempConfig(t, configContent)
originalWd, _ := os.Getwd()
os.Chdir(tmpDir)
defer os.Chdir(originalWd)
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("failed to change directory: %v", err)
}
defer func() {
if err := os.Chdir(originalWd); err != nil {
t.Errorf("failed to restore directory: %v", err)
}
}()

cfg, err := Load()

Expand Down