Skip to content

Commit

Permalink
Merge pull request #20 from saschagrunert/golangci-lint
Browse files Browse the repository at this point in the history
Update golangci-lint to v1.57.1, config and fix lints
  • Loading branch information
k8s-ci-robot authored Mar 28, 2024
2 parents 25290e0 + 0363378 commit 4e21e81
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 97 deletions.
151 changes: 65 additions & 86 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@ run:
concurrency: 6
deadline: 5m
issues:
exclude-rules:
# counterfeiter fakes are usually named 'fake_<something>.go'
- path: fake_.*\.go
linters:
- gocritic
- dupl
linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- copyloopvar
- decorder
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
Expand All @@ -31,6 +28,9 @@ linters:
- forcetypeassert
- funlen
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gochecksumtype
- gocognit
- goconst
- gocritic
Expand All @@ -46,13 +46,20 @@ linters:
- goprintffuncname
- gosec
- gosimple
- gosmopolitan
- govet
- grouper
- importas
- inamedparam
- ineffassign
- interfacebloat
- intrange
- loggercheck
- maintidx
- makezero
- mirror
- misspell
- musttag
- nakedret
- nestif
- nilerr
Expand All @@ -61,28 +68,39 @@ linters:
- nolintlint
- nosprintfhostport
- paralleltest
- perfsprint
- prealloc
- predeclared
- promlinter
- protogetter
- reassign
- revive
- rowserrcheck
- sloglint
- spancheck
- sqlclosecheck
- staticcheck
- stylecheck
- tagalign
- tagliatelle
- tenv
- testableexamples
- testifylint
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
- wrapcheck
- zerologlint
# - cyclop
# - forbidigo
# - depguard
# - exhaustruct
# - forbidigo
# - gochecknoglobals
# - gochecknoinits
# - goerr113
Expand All @@ -105,113 +123,74 @@ linters-settings:
check-blank: true
gocritic:
enabled-checks:
# Diagnostic
- appendAssign
- argOrder
- badCall
- badCond
- appendCombine
- badLock
- badRegexp
- badSorting
- badSyncOnceFunc
- boolExprSimplify
- builtinShadow
- builtinShadowDecl
- caseOrder
- codegenComment
- commentedOutCode
- commentedOutImport
- deferInLoop
- deprecatedComment
- dupArg
- dupBranchBody
- dupCase
- dupSubExpr
- deferUnlambda
- docStub
- dupImport
- dynamicFmtString
- emptyDecl
- emptyFallthrough
- emptyStringTest
- equalFold
- evalOrder
- exitAfterDefer
- exposedSyncMutex
- externalErrorReassign
- filepathJoin
- flagDeref
- flagName
- mapKey
- nilValReturn
- offBy1
- regexpPattern
- returnAfterHttpError
- sloppyReassign
- sloppyTypeAssert
- sortSlice
- sprintfQuotedString
- sqlQuery
- syncMapLoadAndDelete
- truncateCmp
- unnecessaryDefer
- weakCond

# Performance
- appendCombine
- equalFold
- hexLiteral
- httpNoBody
- hugeParam
- importShadow
- indexAlloc
- initClause
- methodExprCall
- nestingReduce
- nilValReturn
- octalLiteral
- paramTypeCombine
- preferDecodeRune
- preferFilepathJoin
- preferFprint
- preferStringWriter
- preferWriteByte
- ptrToRefParam
- rangeExprCopy
- rangeValCopy
- sliceClear
- stringXbytes

# Style
- assignOp
- boolExprSimplify
- captLocal
- commentFormatting
- commentedOutImport
- defaultCaseOrder
- deferUnlambda
- docStub
- dupImport
- elseif
- emptyFallthrough
- emptyStringTest
- exposedSyncMutex
- hexLiteral
- httpNoBody
- ifElseChain
- methodExprCall
- newDeref
- octalLiteral
- preferFilepathJoin
- redundantSprint
- regexpMust
- regexpPattern
- regexpSimplify
- returnAfterHttpError
- ruleguard
- singleCaseSwitch
- sloppyLen
- sliceClear
- sloppyReassign
- sortSlice
- sprintfQuotedString
- sqlQuery
- stringConcatSimplify
- stringXbytes
- stringsCompare
- switchTrue
- syncMapLoadAndDelete
- timeExprSimplify
- todoCommentWithoutDetail
- tooManyResultsChecker
- truncateCmp
- typeAssertChain
- typeDefFirst
- typeSwitchVar
- underef
- unlabelStmt
- unlambda
- unslice
- valSwap
- whyNoLint
- wrapperFunc
- yodaStyleExpr

# Opinionated
- builtinShadow
- importShadow
- initClause
- nestingReduce
- paramTypeCombine
- ptrToRefParam
- todoCommentWithoutDetail
- typeUnparen
- uncheckedInlineErr
- unlabelStmt
- unnamedResult
- unnecessaryBlock
- unnecessaryDefer
- weakCond
- whyNoLint
- yodaStyleExpr
2 changes: 1 addition & 1 deletion hack/verify-golangci-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set -o errexit
set -o nounset
set -o pipefail

VERSION=v1.54.2
VERSION=v1.57.1
URL_BASE=https://raw.githubusercontent.com/golangci/golangci-lint
URL=$URL_BASE/$VERSION/install.sh

Expand Down
7 changes: 4 additions & 3 deletions mdtoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package main

import (
"errors"
"flag"
"fmt"
"log"
Expand Down Expand Up @@ -78,13 +79,13 @@ func main() {

func validateArgs(opts utilityOptions, args []string) error {
if len(args) < 1 {
return fmt.Errorf("must specify at least 1 file")
return errors.New("must specify at least 1 file")
}
if !opts.Inplace && len(args) > 1 {
return fmt.Errorf("non-inplace updates require exactly 1 file")
return errors.New("non-inplace updates require exactly 1 file")
}
if opts.Dryrun && !opts.Inplace {
return fmt.Errorf("--dryrun requires --inplace")
return errors.New("--dryrun requires --inplace")
}
return nil
}
8 changes: 4 additions & 4 deletions mdtoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestDryRun(t *testing.T) {
},
Inplace: true,
}
assert.NoError(t, validateArgs(opts, []string{test.file}), test.file)
require.NoError(t, validateArgs(opts, []string{test.file}), test.file)

err := mdtoc.WriteTOC(test.file, opts.Options)

Expand Down Expand Up @@ -139,7 +139,7 @@ func TestInplace(t *testing.T) {
if test.validTOCTags {
require.NoError(t, err, test.file)
} else {
assert.Error(t, err, test.file)
require.Error(t, err, test.file)
}

updated, err := os.ReadFile(tmpFile.Name())
Expand Down Expand Up @@ -173,10 +173,10 @@ func TestOutput(t *testing.T) {
MaxDepth: mdtoc.MaxHeaderDepth,
},
}
assert.NoError(t, validateArgs(opts, []string{test.file}), test.file)
require.NoError(t, validateArgs(opts, []string{test.file}), test.file)

toc, err := mdtoc.GetTOC(test.file, opts.Options)
assert.NoError(t, err, test.file)
require.NoError(t, err, test.file)

if test.expectedTOC != "" {
assert.Equal(t, test.expectedTOC, toc, test.file)
Expand Down
7 changes: 4 additions & 3 deletions pkg/mdtoc/mdtoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package mdtoc

import (
"bytes"
"errors"
"fmt"
"math"
"os"
Expand Down Expand Up @@ -190,13 +191,13 @@ func WriteTOC(file string, opts Options) error {
start, end := findTOCTags(raw)

if start == -1 {
return fmt.Errorf("missing opening TOC tag")
return errors.New("missing opening TOC tag")
}
if end == -1 {
return fmt.Errorf("missing closing TOC tag")
return errors.New("missing closing TOC tag")
}
if end < start {
return fmt.Errorf("TOC closing tag before start tag")
return errors.New("TOC closing tag before start tag")
}

var doc []byte
Expand Down

0 comments on commit 4e21e81

Please sign in to comment.