From 055a0f033c150dde55c6e77398529f0ab6ea0cd7 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Mon, 8 Jul 2024 11:48:01 +0200 Subject: [PATCH] Update golangci-lint and fix lints Signed-off-by: Sascha Grunert --- .golangci.yml | 86 ++++-------------------------------- go.mod | 2 +- hack/verify-golangci-lint.sh | 2 +- mdtoc_test.go | 3 -- pkg/mdtoc/mdtoc.go | 3 +- 5 files changed, 13 insertions(+), 83 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 3c4abcd..9d48484 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,7 @@ --- run: concurrency: 6 - deadline: 5m + timeout: 5m issues: linters: disable-all: true @@ -10,9 +10,11 @@ linters: - asciicheck - bidichk - bodyclose + - canonicalheader - containedctx - contextcheck - copyloopvar + - cyclop - decorder - dogsled - dupl @@ -22,9 +24,9 @@ linters: - errchkjson - errname - errorlint - - execinquery - exhaustive - exportloopref + - fatcontext - forcetypeassert - funlen - gci @@ -59,6 +61,7 @@ linters: - makezero - mirror - misspell + - mnd - musttag - nakedret - nestif @@ -97,14 +100,12 @@ linters: - whitespace - wrapcheck - zerologlint - # - cyclop # - depguard + # - err113 # - exhaustruct # - forbidigo # - gochecknoglobals # - gochecknoinits - # - goerr113 - # - gomnd # - ireturn # - lll # - nlreturn @@ -113,6 +114,8 @@ linters: # - varnamelen # - wsl linters-settings: + cyclop: + max-complexity: 15 godox: keywords: - BUG @@ -122,75 +125,4 @@ linters-settings: check-type-assertions: true check-blank: true gocritic: - enabled-checks: - - appendCombine - - badLock - - badRegexp - - badSorting - - badSyncOnceFunc - - boolExprSimplify - - builtinShadow - - builtinShadowDecl - - commentedOutCode - - commentedOutImport - - deferInLoop - - deferUnlambda - - docStub - - dupImport - - dynamicFmtString - - emptyDecl - - emptyFallthrough - - emptyStringTest - - equalFold - - evalOrder - - exposedSyncMutex - - externalErrorReassign - - filepathJoin - - hexLiteral - - httpNoBody - - hugeParam - - importShadow - - indexAlloc - - initClause - - methodExprCall - - nestingReduce - - nilValReturn - - octalLiteral - - paramTypeCombine - - preferDecodeRune - - preferFilepathJoin - - preferFprint - - preferStringWriter - - preferWriteByte - - ptrToRefParam - - rangeExprCopy - - rangeValCopy - - redundantSprint - - regexpPattern - - regexpSimplify - - returnAfterHttpError - - ruleguard - - sliceClear - - sloppyReassign - - sortSlice - - sprintfQuotedString - - sqlQuery - - stringConcatSimplify - - stringXbytes - - stringsCompare - - syncMapLoadAndDelete - - timeExprSimplify - - todoCommentWithoutDetail - - tooManyResultsChecker - - truncateCmp - - typeAssertChain - - typeDefFirst - - typeUnparen - - uncheckedInlineErr - - unlabelStmt - - unnamedResult - - unnecessaryBlock - - unnecessaryDefer - - weakCond - - whyNoLint - - yodaStyleExpr + enable-all: true diff --git a/go.mod b/go.mod index f477a8e..d1d827d 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module sigs.k8s.io/mdtoc -go 1.21 +go 1.22 require ( github.com/gomarkdown/markdown v0.0.0-20240328165702-4d01890c35c0 diff --git a/hack/verify-golangci-lint.sh b/hack/verify-golangci-lint.sh index 6dde6cf..027a575 100755 --- a/hack/verify-golangci-lint.sh +++ b/hack/verify-golangci-lint.sh @@ -18,7 +18,7 @@ set -o errexit set -o nounset set -o pipefail -VERSION=v1.57.1 +VERSION=v1.59.1 URL_BASE=https://raw.githubusercontent.com/golangci/golangci-lint URL=$URL_BASE/$VERSION/install.sh diff --git a/mdtoc_test.go b/mdtoc_test.go index c81e565..0859a46 100644 --- a/mdtoc_test.go +++ b/mdtoc_test.go @@ -84,7 +84,6 @@ func testdata(subpath string) string { func TestDryRun(t *testing.T) { t.Parallel() for _, test := range testcases { - test := test t.Run(test.file, func(t *testing.T) { t.Parallel() opts := utilityOptions{ @@ -111,7 +110,6 @@ func TestDryRun(t *testing.T) { func TestInplace(t *testing.T) { t.Parallel() for _, test := range testcases { - test := test t.Run(test.file, func(t *testing.T) { t.Parallel() original, err := os.ReadFile(test.file) @@ -157,7 +155,6 @@ func TestInplace(t *testing.T) { func TestOutput(t *testing.T) { t.Parallel() for _, test := range testcases { - test := test // Ignore the invalid cases, they're only for inplace tests. if !test.validTOCTags { continue diff --git a/pkg/mdtoc/mdtoc.go b/pkg/mdtoc/mdtoc.go index ccf648a..551774b 100644 --- a/pkg/mdtoc/mdtoc.go +++ b/pkg/mdtoc/mdtoc.go @@ -256,7 +256,8 @@ func GetTOC(file string, opts Options) (string, error) { // A temporary file is used so no changes are made to the original in the case of an error. func atomicWrite(filePath string, chunks ...string) error { tmpPath := filePath + "_tmp" - tmp, err := os.OpenFile(tmpPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o600) + const perms = 0o600 + tmp, err := os.OpenFile(tmpPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perms) if err != nil { return fmt.Errorf("unable to open tepmorary file %s: %w", tmpPath, err) }