Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
288 changes: 128 additions & 160 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -113,13 +18,9 @@ linters:
- goconst
- gocritic
- godot
- gofmt
- gofumpt
- gosec
- goheader
- goimports
- goprintffuncname
- gosimple
- gosec
- govet
- importas
- ineffassign
Expand All @@ -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$
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/malcontent/malcontent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/refresh/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

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

Expand Down
2 changes: 1 addition & 1 deletion pkg/report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func BenchmarkLongestUnique(b *testing.B) {
"cherrybanana",
"upload_content",
}
for i := 0; i < b.N; i++ {
for b.Loop() {
longestUnique(raw)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/report/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion tests/samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Loading