From cff06cd1c65e1c9773927ea71f846f50842a6ce6 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Sat, 6 Jan 2024 15:10:29 -0800 Subject: [PATCH] Update linters and fumpt all files --- .golangci.yml | 13 +------------ .pre-commit-config.yaml | 2 -- job_test.go | 3 ++- main_test.go | 1 - metrics.go | 1 - restic.go | 6 ++++-- restic_test.go | 4 ++-- scheduler.go | 6 ++++-- 8 files changed, 13 insertions(+), 23 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index dc70944..b353428 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -31,10 +31,8 @@ linters: - gocognit - goconst - gocritic - # - gocyclo # Using cyclop - godot - # - goerr113 # Using errorlint - - gofmt + - gofumpt - goheader - goimports - gomnd @@ -44,7 +42,6 @@ linters: - gosec - grouper - importas - # - ireturn - lll - maintidx - makezero @@ -59,11 +56,9 @@ linters: - paralleltest - prealloc - predeclared - # - promlinter # Not common enough - revive - rowserrcheck - sqlclosecheck - # - stylecheck # Using revive - tagliatelle - tenv - testpackage @@ -71,17 +66,11 @@ linters: - tparallel - unconvert - unparam - - varnamelen - wastedassign - whitespace - wrapcheck - wsl - disable: - - gochecknoglobals - - godox - - forbidigo - linters-settings: gomnd: settings: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7998095..61f6d9e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,8 +13,6 @@ repos: - repo: https://github.com/dnephin/pre-commit-golang rev: v0.5.1 hooks: - - id: go-fmt - - id: go-imports - id: golangci-lint args: - --timeout=3m diff --git a/job_test.go b/job_test.go index 1f1048e..392bc3d 100644 --- a/job_test.go +++ b/job_test.go @@ -294,7 +294,8 @@ func TestConfigValidation(t *testing.T) { MySQL: []main.JobTaskMySQL{}, Postgres: []main.JobTaskPostgres{}, Sqlite: []main.JobTaskSqlite{}, - }}}, + }}, + }, expectedErr: main.ErrMissingField, }, } diff --git a/main_test.go b/main_test.go index 7a71d27..f5163a1 100644 --- a/main_test.go +++ b/main_test.go @@ -31,7 +31,6 @@ func TestReadJobs(t *testing.T) { t.Parallel() jobs, err := main.ReadJobs([]string{"./test/sample.hcl"}) - if err != nil { t.Errorf("Unexpected error reading jobs: %v", err) } diff --git a/metrics.go b/metrics.go index fc51c36..9708294 100644 --- a/metrics.go +++ b/metrics.go @@ -19,7 +19,6 @@ func (m ResticMetrics) PushToGateway(url string) error { err := push.New(url, "batch"). Gatherer(m.Registry). Add() - if err != nil { return fmt.Errorf("error pushing to registry %s: %w", url, err) } diff --git a/restic.go b/restic.go index 94498ad..cfcbf4d 100644 --- a/restic.go +++ b/restic.go @@ -11,8 +11,10 @@ import ( "time" ) -var ErrRestic = errors.New("restic error") -var ErrRepoNotFound = errors.New("repository not found or uninitialized") +var ( + ErrRestic = errors.New("restic error") + ErrRepoNotFound = errors.New("repository not found or uninitialized") +) func lineIn(needle string, haystack []string) bool { for _, line := range haystack { diff --git a/restic_test.go b/restic_test.go index b11dd87..692ce51 100644 --- a/restic_test.go +++ b/restic_test.go @@ -237,7 +237,7 @@ func TestResticInterface(t *testing.T) { } // Write test file to the data dir - err := os.WriteFile(dataFile, []byte("testing"), 0644) + err := os.WriteFile(dataFile, []byte("testing"), 0o644) AssertEqualFail(t, "unexpected error writing to test file", nil, err) // Make sure no existing repo is found @@ -297,7 +297,7 @@ func TestResticInterface(t *testing.T) { AssertEqualFail(t, "unexpected error checking repo", nil, err) // Change the data file - err = os.WriteFile(dataFile, []byte("unexpected"), 0644) + err = os.WriteFile(dataFile, []byte("unexpected"), 0o644) AssertEqualFail(t, "unexpected error writing to test file", nil, err) // Check that data wrote diff --git a/scheduler.go b/scheduler.go index 43c3714..af9bd49 100644 --- a/scheduler.go +++ b/scheduler.go @@ -13,8 +13,10 @@ import ( "github.com/robfig/cron/v3" ) -var jobResultsLock = sync.Mutex{} -var jobResults = map[string]JobResult{} +var ( + jobResultsLock = sync.Mutex{} + jobResults = map[string]JobResult{} +) type JobResult struct { JobName string