From 32ba7d4611e2d4a0ec956465abe52e35a18ea83a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:50:34 +0000 Subject: [PATCH] chore: fix linter --- .golangci.yml | 95 +++++++++++++++++++ ...t-1.51.2.pkg => .golangci-lint-1.61.0.pkg} | 0 bin/golangci-lint | 2 +- check.go | 4 +- def.go | 4 +- go.mod | 2 +- help_test.go | 2 +- 7 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 .golangci.yml rename bin/{.golangci-lint-1.51.2.pkg => .golangci-lint-1.61.0.pkg} (100%) diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..a042951 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,95 @@ +run: + tests: true + skip-dirs: + - _examples + +output: + print-issued-lines: false + +linters: + enable-all: true + disable: + - maligned + - megacheck + - lll + - gocyclo + - dupl + - gochecknoglobals + - funlen + - godox + - wsl + - gomnd + - gocognit + - goerr113 + - nolintlint + - testpackage + - godot + - nestif + - paralleltest + - nlreturn + - cyclop + - exhaustivestruct + - gci + - gofumpt + - errorlint + - exhaustive + - ifshort + - wrapcheck + - stylecheck + - thelper + - nonamedreturns + - revive + - dupword + - exhaustruct + - varnamelen + - forcetypeassert + - ireturn + - maintidx + - govet + - nosnakecase + - testableexamples + - musttag + - depguard + - goconst + - perfsprint + - mnd + - predeclared + - nilnil + +linters-settings: + govet: + check-shadowing: true + gocyclo: + min-complexity: 10 + dupl: + threshold: 100 + goconst: + min-len: 8 + min-occurrences: 3 + forbidigo: + #forbid: + # - (Must)?NewLexer$ + exclude_godoc_examples: false + +issues: + max-per-linter: 0 + max-same: 0 + exclude-use-default: false + exclude: + # Captured by errcheck. + - "^(G104|G204):" + # Very commonly not checked. + - 'Error return value of .(.*\.Help|.*\.MarkFlagRequired|(os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked' + - 'exported method (.*\.MarshalJSON|.*\.UnmarshalJSON|.*\.EntityURN|.*\.GoString|.*\.Pos) should have comment or be unexported' + - "composite literal uses unkeyed fields" + - 'declaration of "err" shadows declaration' + - "should not use dot imports" + - "Potential file inclusion via variable" + - "should have comment or be unexported" + - "comment on exported var .* should be of the form" + - "at least one file in a package should have a package comment" + - "string literal contains the Unicode" + - "methods on the same type should have the same receiver name" + - "_TokenType_name should be _TokenTypeName" + - "`_TokenType_map` should be `_TokenTypeMap`" + - "rewrite if-else to switch statement" diff --git a/bin/.golangci-lint-1.51.2.pkg b/bin/.golangci-lint-1.61.0.pkg similarity index 100% rename from bin/.golangci-lint-1.51.2.pkg rename to bin/.golangci-lint-1.61.0.pkg diff --git a/bin/golangci-lint b/bin/golangci-lint index 7d8886c..79bb386 120000 --- a/bin/golangci-lint +++ b/bin/golangci-lint @@ -1 +1 @@ -.golangci-lint-1.51.2.pkg \ No newline at end of file +.golangci-lint-1.61.0.pkg \ No newline at end of file diff --git a/check.go b/check.go index 1a0a325..e4976ff 100644 --- a/check.go +++ b/check.go @@ -29,7 +29,7 @@ func (e inexhaustiveError) Error() string { // Names returns a sorted list of names corresponding to the missing variant // cases. func (e inexhaustiveError) Names() []string { - var list []string + list := make([]string, 0, len(e.Missing)) for _, o := range e.Missing { list = append(list, o.Name()) } @@ -103,7 +103,7 @@ func missingVariantsInSwitch( // A catch-all case defeats all exhaustiveness checks. return def, nil } - var variantTypes []types.Type + variantTypes := make([]types.Type, 0, len(variantExprs)) for _, expr := range variantExprs { variantTypes = append(variantTypes, pkg.TypesInfo.TypeOf(expr)) } diff --git a/def.go b/def.go index 24729ac..df1aa4a 100644 --- a/def.go +++ b/def.go @@ -71,7 +71,7 @@ type sumTypeDef struct { // sum type declarations. If no such sum type definition could be found for // any of the given declarations, then an error is returned. func findSumTypeDefs(decls []sumTypeDecl) ([]sumTypeDef, []error) { - var defs []sumTypeDef + defs := make([]sumTypeDef, 0, len(decls)) var errs []error for _, decl := range decls { def, err := newSumTypeDef(decl.Package.Types, decl) @@ -104,7 +104,7 @@ func newSumTypeDef(pkg *types.Package, decl sumTypeDecl) (*sumTypeDef, error) { return nil, notInterfaceError{decl} } hasUnexported := false - for i := 0; i < iface.NumMethods(); i++ { + for i := range iface.NumMethods() { if !iface.Method(i).Exported() { hasUnexported = true break diff --git a/go.mod b/go.mod index b3103d1..5502df5 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/alecthomas/go-check-sumtype -go 1.22.0 +go 1.23.0 toolchain go1.23.3 diff --git a/help_test.go b/help_test.go index fa68233..c2f2920 100644 --- a/help_test.go +++ b/help_test.go @@ -15,7 +15,7 @@ func setupPackages(t *testing.T, code string) (string, []*packages.Package) { t.Fatal(err) } srcPath := filepath.Join(tmpdir, "src.go") - if err := ioutil.WriteFile(srcPath, []byte(code), 0666); err != nil { + if err := ioutil.WriteFile(srcPath, []byte(code), 0600); err != nil { t.Fatal(err) } pkgs, err := tycheckAll([]string{srcPath})