From 442b793524e485c2e2601da5d4c4ce3c8eb77c31 Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Wed, 14 Jun 2023 15:56:26 +0200 Subject: [PATCH] code cleanup, new linter conf --- .golangci.yaml | 62 +++++++++++++++++++++++++------------------ buildmanager.go | 8 +++--- package.go | 2 +- proto_package.go | 8 +++--- proto_package_test.go | 2 +- utils.go | 2 +- 6 files changed, 46 insertions(+), 38 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index f5bab82..bb1b199 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -47,31 +47,41 @@ linters-settings: allow-unused: false # report any unused nolint directives require-explanation: false # don't require an explanation for nolint directives require-specific: false # don't require nolint directives to be specific about which linter is being skipped + tagliatelle: + case: + use-field-name: true + rules: + # Any struct tag type can be used. + # Support string case: `camel`, `pascal`, `kebab`, `snake`, `upperSnake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower`, `header`. + json: snake + yaml: snake + xml: camel linters: - disable-all: true - enable: - - bodyclose - - dogsled - - dupl - - errcheck - - exportloopref - - gochecknoinits - - gocritic - - gofmt - - gomnd - - goprintffuncname - - gosec - - gosimple - - govet - - lll - - misspell - - noctx - - nolintlint - - staticcheck - - stylecheck - - typecheck - - unconvert - - unparam - - unused - - whitespace + enable-all: true + disable: + - gochecknoglobals + - depguard + - gci + - gofumpt + - goimports + - varnamelen + - funlen + - cyclop + - wsl + - nosnakecase + - nlreturn + - godot + - nestif + - wrapcheck + - gocognit + - gocyclo + - maintidx + - nonamedreturns + - exhaustivestruct + - exhaustruct + - forcetypeassert + - godox + # remove for new projects + - errname + - goerr113 diff --git a/buildmanager.go b/buildmanager.go index 6a24fdc..bec4f1f 100644 --- a/buildmanager.go +++ b/buildmanager.go @@ -30,7 +30,7 @@ type BuildManager struct { queueSignal chan struct{} } -func (b *BuildManager) buildQueue(queue []*ProtoPackage, ctx context.Context) error { +func (b *BuildManager) buildQueue(ctx context.Context, queue []*ProtoPackage) error { var ( doneQ []*ProtoPackage doneQLock = new(sync.RWMutex) @@ -281,7 +281,7 @@ func (b *BuildManager) htmlWorker(ctx context.Context) { db.DBPackage.Query().GroupBy(dbpackage.FieldStatus).Aggregate(ent.Count()).ScanX(ctx, &v) for _, c := range v { - switch c.Status { + switch c.Status { //nolint:exhaustive case dbpackage.StatusFailed: gen.Failed = c.Count case dbpackage.StatusSkipped: @@ -294,7 +294,7 @@ func (b *BuildManager) htmlWorker(ctx context.Context) { } var v2 []struct { - Status dbpackage.Lto `json:"lto"` + Status dbpackage.Lto `json:"lto"` //nolint:tagliatelle Count int `json:"count"` } @@ -522,7 +522,7 @@ func (b *BuildManager) syncWorker(ctx context.Context) error { log.Errorf("error building queue: %v", err) } else { log.Debugf("build-queue with %d items", len(queue)) - err = b.buildQueue(queue, ctx) + err = b.buildQueue(ctx, queue) if err != nil { return err } diff --git a/package.go b/package.go index f1c773e..a737691 100644 --- a/package.go +++ b/package.go @@ -85,7 +85,7 @@ func (pkg Package) DBPackageIsolated(march string, repo dbpackage.Repository, db ) }).Only(context.Background()) if ent.IsNotFound(err) { - log.Debugf("Not found in database: %s", pkg.Name()) + log.Debugf("not found in database: %s", pkg.Name()) return nil, err } else if err != nil { return nil, err diff --git a/proto_package.go b/proto_package.go index f385cd7..93f06e2 100644 --- a/proto_package.go +++ b/proto_package.go @@ -69,9 +69,8 @@ func (p *ProtoPackage) isEligible(ctx context.Context) bool { p.DBPackage = p.DBPackage.Update().SetUpdated(time.Now()).SetVersion(p.Version).SetStatus(p.DBPackage.Status). SetSkipReason(p.DBPackage.SkipReason).SetTagRev(p.State.TagRev).SaveX(ctx) return false - } else { - p.DBPackage = p.DBPackage.Update().SetUpdated(time.Now()).SetVersion(p.Version).SaveX(ctx) } + p.DBPackage = p.DBPackage.Update().SetUpdated(time.Now()).SetVersion(p.Version).SaveX(ctx) if Contains(conf.Blacklist.LTO, p.Pkgbase) && p.DBPackage.Lto != dbpackage.LtoDisabled { p.DBPackage = p.DBPackage.Update().SetLto(dbpackage.LtoDisabled).SaveX(ctx) @@ -359,8 +358,7 @@ func (p *ProtoPackage) setupBuildDir() (string, error) { } func (p *ProtoPackage) repoVersion() (string, error) { - err := p.findPkgFiles() - if err != nil { + if err := p.findPkgFiles(); err != nil { return "", err } @@ -694,7 +692,7 @@ func (p *ProtoPackage) isMirrorLatest(h *alpm.Handle) (latest bool, foundPkg alp return false, nil, "", UnableToSatisfyError{err} } - svn2gitVer, err := (&ProtoPackage{ + svn2gitVer, err := (&ProtoPackage{ //nolint:exhaustruct,exhaustivestruct Pkgbase: pkg.Base(), March: p.March, }).GitVersion(h) diff --git a/proto_package_test.go b/proto_package_test.go index 9d0a48a..e1cd051 100644 --- a/proto_package_test.go +++ b/proto_package_test.go @@ -51,7 +51,7 @@ package() { # vim:set sw=2 et: ` -func TestIncreasePkgRel(t *testing.T) { +func TestIncreasePkgRel(t *testing.T) { //nolint:paralleltest pkgbuild, err := os.CreateTemp("", "") if err != nil { t.Fatal("Unable to setup temp. PKGBUILD") diff --git a/utils.go b/utils.go index 62f65ee..99b534a 100644 --- a/utils.go +++ b/utils.go @@ -112,7 +112,7 @@ func updateLastUpdated() error { } func statusID2string(s dbpackage.Status) string { - switch s { + switch s { //nolint:exhaustive case dbpackage.StatusSkipped: return conf.Status.Class.Skipped case dbpackage.StatusQueued: