diff --git a/.golangci.yml b/.golangci.yml index e319ee292..89028d58f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,101 +1,6 @@ -run: - # The default runtime timeout is 1m, which doesn't work well on Github Actions. - timeout: 10m - -# NOTE: This file is populated by the lint-install tool. Local adjustments may be overwritten. -linters-settings: - cyclop: - # NOTE: This is a very high transitional threshold - max-complexity: 37 - package-average: 34.0 - skip-tests: true - - gocognit: - # NOTE: This is a very high transitional threshold - min-complexity: 98 - - dupl: - threshold: 200 - - goconst: - min-len: 4 - min-occurrences: 5 - ignore-tests: true - - gosec: - excludes: - - G107 # Potential HTTP request made with variable url - - G204 # Subprocess launched with function call as argument or cmd arguments - - G404 # Use of weak random number generator (math/rand instead of crypto/rand - - errorlint: - # these are still common in Go: for instance, exit errors. - asserts: false - # Forcing %w in error wrapping forces authors to make errors part of their package APIs. The decision to make - # an error part of a package API should be a concious decision by the author. - # Also see Hyrums Law. - errorf: false - - exhaustive: - default-signifies-exhaustive: true - - nestif: - min-complexity: 8 - - nolintlint: - require-explanation: true - allow-unused: false - require-specific: true - - revive: - ignore-generated-header: true - severity: warning - rules: - - name: atomic - - name: blank-imports - - name: bool-literal-in-expr - - name: confusing-naming - - name: constant-logical-expr - - name: context-as-argument - - name: context-keys-type - - name: deep-exit - - name: defer - - name: range-val-in-closure - - name: range-val-address - - name: dot-imports - - name: error-naming - - name: error-return - - name: error-strings - - name: errorf - - name: exported - - name: identical-branches - - name: if-return - - name: import-shadowing - - name: increment-decrement - - name: indent-error-flow - - name: indent-error-flow - - name: package-comments - - name: range - - name: receiver-naming - - name: redefines-builtin-id - - name: superfluous-else - - name: struct-tag - - name: time-naming - - name: unexported-naming - - name: unexported-return - - name: unnecessary-stmt - - name: unreachable-code - - name: unused-parameter - - name: var-declaration - - name: var-naming - - name: unconditional-recursion - - name: waitgroup-by-value - -output: - sort-results: true - +version: "2" linters: - disable-all: true + default: none enable: - asciicheck - bodyclose @@ -113,13 +18,9 @@ linters: - goconst - gocritic - godot - - gofmt - - gofumpt - - gosec - goheader - - goimports - goprintffuncname - - gosimple + - gosec - govet - importas - ineffassign @@ -132,72 +33,139 @@ linters: - nolintlint - prealloc - predeclared - # disabling for the initial iteration of the linting tool - # - promlinter - revive - # - rowserrcheck - disabled because of generics, https://github.com/golangci/golangci-lint/issues/2649 - # - sqlclosecheck - disabled because of generics, https://github.com/golangci/golangci-lint/issues/2649 - staticcheck - # - structcheck - disabled because of generics, https://github.com/golangci/golangci-lint/issues/2649 - - stylecheck - thelper - tparallel - - typecheck - unconvert - unparam - unused - # - wastedassign - disabled because of generics, https://github.com/golangci/golangci-lint/issues/2649 - whitespace - - # Disabled linters, due to being misaligned with Go practices - # - exhaustivestruct - # - gochecknoglobals - # - gochecknoinits - # - goconst - # - godox - # - goerr113 - # - gomnd - # - lll - # - nlreturn - # - testpackage - # - wsl - # Disabled linters, due to not being relevant to our code base: - # - maligned - # - prealloc "For most programs usage of prealloc will be a premature optimization." - # Disabled linters due to bad error messages or bugs - # - tagliatelle - + settings: + cyclop: + # NOTE: This is a very high transitional threshold + max-complexity: 37 + package-average: 34 + dupl: + threshold: 200 + errorlint: + # Forcing %w in error wrapping forces authors to make errors part of their package APIs. The decision to make + # an error part of a package API should be a concious decision by the author. + # Also see Hyrums Law. + errorf: false + # these are still common in Go: for instance, exit errors. + asserts: false + exhaustive: + default-signifies-exhaustive: true + gocognit: + # NOTE: This is a very high transitional threshold + min-complexity: 98 + goconst: + min-len: 4 + min-occurrences: 5 + gosec: + excludes: + - G107 # Potential HTTP request made with variable url + - G204 # Subprocess launched with function call as argument or cmd arguments + - G404 # Use of weak random number generator (math/rand instead of crypto/rand + nestif: + min-complexity: 8 + nolintlint: + require-explanation: true + require-specific: true + allow-unused: false + revive: + severity: warning + rules: + - name: atomic + - name: blank-imports + - name: bool-literal-in-expr + - name: confusing-naming + - name: constant-logical-expr + - name: context-as-argument + - name: context-keys-type + - name: deep-exit + - name: defer + - name: range-val-in-closure + - name: range-val-address + - name: dot-imports + - name: error-naming + - name: error-return + - name: error-strings + - name: errorf + - name: exported + - name: identical-branches + - name: if-return + - name: import-shadowing + - name: increment-decrement + - name: indent-error-flow + - name: indent-error-flow + - name: package-comments + - name: range + - name: receiver-naming + - name: redefines-builtin-id + - name: superfluous-else + - name: struct-tag + - name: time-naming + - name: unexported-naming + - name: unexported-return + - name: unnecessary-stmt + - name: unreachable-code + - name: unused-parameter + - name: var-declaration + - name: var-naming + - name: unconditional-recursion + - name: waitgroup-by-value + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - dupl + - errcheck + - forcetypeassert + - gocyclo + - gosec + - noctx + path: _test\.go + - linters: + - noctx + path: .*cmd.* + - linters: + - noctx + path: main\.go + - path: .*cmd.* + text: deep-exit + - path: main\.go + text: deep-exit + - linters: + # This check is of questionable value + - tparallel + text: call t.Parallel on the top level as well as its subtests + - linters: + - cyclop + - goconst + path: (.+)_test\.go + paths: + - third_party$ + - builtin$ + - examples$ issues: - # Excluding configuration per-path, per-linter, per-text and per-source - exclude-rules: - - path: _test\.go - linters: - - dupl - - errcheck - - forcetypeassert - - gocyclo - - gosec - - noctx - - - path: .*cmd.* - linters: - - noctx - - - path: main\.go - linters: - - noctx - - - path: .*cmd.* - text: "deep-exit" - - - path: main\.go - text: "deep-exit" - - # This check is of questionable value - - linters: - - tparallel - text: "call t.Parallel on the top level as well as its subtests" - # Don't hide lint issues just because there are many of them - max-same-issues: 0 max-issues-per-linter: 0 + max-same-issues: 0 +formatters: + enable: + - gofmt + - gofumpt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index 5cea22143..e029b31c1 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ LINTERS := FIXERS := GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml -GOLANGCI_LINT_VERSION ?= v1.64.8 +GOLANGCI_LINT_VERSION ?= v2.1.6 GOLANGCI_LINT_BIN := $(LINT_ROOT)/out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH) $(GOLANGCI_LINT_BIN): mkdir -p $(LINT_ROOT)/out/linters diff --git a/pkg/compile/compile.go b/pkg/compile/compile.go index 8668751f3..07d44e3be 100644 --- a/pkg/compile/compile.go +++ b/pkg/compile/compile.go @@ -190,7 +190,7 @@ func findRoot(start string) string { func replaceGlobal(data []byte, path string) []byte { modified := data if bytes.Contains(data, []byte(globalInclude)) { - modified = bytes.Replace(data, []byte(globalInclude), []byte(fmt.Sprintf(`include "%s"`, path)), 1) + modified = bytes.Replace(data, []byte(globalInclude), fmt.Appendf(nil, `include "%s"`, path), 1) } return modified } diff --git a/pkg/malcontent/malcontent.go b/pkg/malcontent/malcontent.go index 537e714c1..16c83abb5 100644 --- a/pkg/malcontent/malcontent.go +++ b/pkg/malcontent/malcontent.go @@ -116,9 +116,9 @@ type DiffReport struct { } type Report struct { - Files sync.Map `json:",omitempty" yaml:",omitempty"` - Diff *DiffReport `json:",omitempty" yaml:",omitempty"` - Filter string `json:",omitempty" yaml:",omitempty"` + Files sync.Map + Diff *DiffReport + Filter string } type IntMetric struct { diff --git a/pkg/refresh/refresh.go b/pkg/refresh/refresh.go index 75f53a877..217fcb698 100644 --- a/pkg/refresh/refresh.go +++ b/pkg/refresh/refresh.go @@ -117,10 +117,10 @@ func prepareRefresh(ctx context.Context, rc Config) ([]TestData, error) { ext := filepath.Ext(data) format := strings.TrimPrefix(ext, ".") - switch { - case format == "sdiff": + switch format { + case "sdiff": format = "simple" - case format == "mdiff" || format == "md": + case "mdiff", "md": format = "markdown" } diff --git a/pkg/render/markdown.go b/pkg/render/markdown.go index 253c5f594..671ccca31 100644 --- a/pkg/render/markdown.go +++ b/pkg/render/markdown.go @@ -216,7 +216,7 @@ func markdownTable(ctx context.Context, fr *malcontent.FileReport, w io.Writer, risk := k.Behavior.RiskLevel - if rc.SkipExisting && !(k.Behavior.DiffAdded || k.Behavior.DiffRemoved) { + if rc.SkipExisting && !k.Behavior.DiffAdded && !k.Behavior.DiffRemoved { continue } diff --git a/pkg/report/report_test.go b/pkg/report/report_test.go index 71fa24b78..997c95327 100644 --- a/pkg/report/report_test.go +++ b/pkg/report/report_test.go @@ -60,7 +60,7 @@ func BenchmarkLongestUnique(b *testing.B) { "cherrybanana", "upload_content", } - for i := 0; i < b.N; i++ { + for b.Loop() { longestUnique(raw) } } diff --git a/pkg/report/strings.go b/pkg/report/strings.go index 11e9e70b1..a214f9e1e 100644 --- a/pkg/report/strings.go +++ b/pkg/report/strings.go @@ -64,7 +64,7 @@ func newMatchProcessor(fc []byte, matches []yarax.Match, mp []yarax.Pattern) *ma } var matchResultPool = sync.Pool{ - New: func() interface{} { + New: func() any { s := make([]string, 0, 32) return &s }, diff --git a/tests/samples_test.go b/tests/samples_test.go index 85e0465c4..9563d6ea4 100644 --- a/tests/samples_test.go +++ b/tests/samples_test.go @@ -646,7 +646,7 @@ func Benchmarks(b *testing.B, p string) { if p != "" { paths = strings.Split(p, ",") } - for i := 0; i < b.N; i++ { + for b.Loop() { bench := Template(b, paths) bench() }