diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index 04c37ec..42cdf00 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -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 diff --git a/.golangci.yaml b/.golangci.yaml index a5e537e..0cb9c98 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,4 +1,7 @@ +version: "2" + linters: + default: none enable: - bodyclose - copyloopvar @@ -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 diff --git a/internal/app/app_test.go b/internal/app/app_test.go index 3914961..e0ec9a2 100644 --- a/internal/app/app_test.go +++ b/internal/app/app_test.go @@ -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, }, @@ -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 } }, diff --git a/internal/app/git/git_test.go b/internal/app/git/git_test.go index 56717ca..8818fbf 100644 --- a/internal/app/git/git_test.go +++ b/internal/app/git/git_test.go @@ -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() @@ -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() diff --git a/internal/config/config_test.go b/internal/config/config_test.go index fb30341..b89ae6c 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -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) } @@ -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() @@ -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()