Skip to content

Commit

Permalink
chore: fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
renovate[bot] authored and alecthomas committed Nov 9, 2024
1 parent bd4d721 commit 32ba7d4
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 7 deletions.
95 changes: 95 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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"
File renamed without changes.
2 changes: 1 addition & 1 deletion bin/golangci-lint
4 changes: 2 additions & 2 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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))
}
Expand Down
4 changes: 2 additions & 2 deletions def.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/alecthomas/go-check-sumtype

go 1.22.0
go 1.23.0

toolchain go1.23.3

Expand Down
2 changes: 1 addition & 1 deletion help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit 32ba7d4

Please sign in to comment.