From 6e3fb122393f5679e4df8fe750a41014e9a0a409 Mon Sep 17 00:00:00 2001 From: Alexander Menshchikov Date: Thu, 29 Oct 2026 15:52:40 +0300 Subject: [PATCH 1/9] Update closer golangci-lint config --- closer/.golangci.yml | 161 ++++++++++++++++++++++++++++++++++-------- closer/closer_test.go | 22 ++++-- 2 files changed, 146 insertions(+), 37 deletions(-) diff --git a/closer/.golangci.yml b/closer/.golangci.yml index 6d6d7d1..7f28cfa 100644 --- a/closer/.golangci.yml +++ b/closer/.golangci.yml @@ -20,50 +20,106 @@ formatters: linters: default: none enable: + - asasalint # Check for pass []any as any in variadic func(…any). - asciicheck # Checks that all code identifiers does not have non-ASCII symbols in the name. - bidichk # Checks for dangerous unicode character sequences. - - bodyclose # Checks whether HTTP response body is closed successfully. - - canonicalheader # Canonicalheader checks whether net/http.Header uses canonical header. + - containedctx # Containedctx is a linter that detects struct contained context.Context field. - contextcheck # Check whether the function uses a non-inherited context. + - copyloopvar # Copyloopvar is a linter detects places where loop variables are copied. + - depguard # Go linter that checks if package imports are in a list of acceptable packages. + - dupword # Checks for duplicate words in the source code. - durationcheck # Check for two durations multiplied together. + - embeddedstructfieldcheck # Embedded types should be at the top of the field list of a struct, and there must be an empty line separating embedded fields from regular fields. - errcheck # Errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases. - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error. - errorlint # Errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. + - exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. + - fatcontext # Detects nested contexts in loops and function literals. + - forcetypeassert # Find forced type assertions. - funcorder # Checks the order of functions, methods, and constructors. - gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. - gocognit # Computes and checks the cognitive complexity of functions. - goconst # Finds repeated strings that could be replaced by a constant. - gocritic # Provides diagnostics that check for bugs, performance and style issues. - goheader # Checks if file header matches to pattern. + - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. - gosec # Inspects source code for security problems. - govet # Vet examines Go source code and reports suspicious constructs. - - ineffassign # Detects when assignments to existing variables are not used. + - iface # Detect the incorrect use of interfaces, helping developers avoid interface pollution. + - inamedparam # Reports interfaces with unnamed method parameters. + - intrange # Intrange is a linter to find places where for loops could make use of an integer range. + - iotamixing # Checks if iotas are being used in const blocks with other non-iota declarations. - makezero # Finds slice declarations with non-zero initial length. + - mirror # Reports wrong mirror patterns of bytes/strings usage. - mnd # An analyzer to detect magic numbers. + - modernize # A suite of analyzers that suggest simplifications to Go code, using modern language and library features. - nakedret # Checks that functions with naked returns are not longer than a maximum size (can be zero). - nilnil # Checks that there is no simultaneous return of nil error and an invalid value. - - noctx # Finds sending http request without context.Context. - nolintlint # Reports ill-formed or insufficient nolint directives. - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. - perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. - prealloc # Finds slice declarations that could potentially be pre-allocated. + - reassign # Checks that package variables are not reassigned. - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. - staticcheck # It's a set of rules from staticcheck. + - testifylint # Checks usage of github.com/stretchr/testify. - testpackage # Linter that makes you use a separate _test package. + - thelper # Thelper detects tests helpers which do not start with the t.Helper() method. + - tparallel # Tparallel detects inappropriate usage of t.Parallel() method in your Go test codes. - unconvert # Remove unnecessary type conversions. - unused # Checks Go code for unused constants, variables, functions and types. - - usetesting # Reports uses of functions with replacement inside the testing package. - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. + - usetesting # Reports uses of functions with replacement inside the testing package. - wastedassign # Finds wasted assignment statements. + - whitespace # Checks for unnecessary newlines at the start and end of functions, if, for, etc. exclusions: rules: - text: 'Error return value of .((os\.)?std(out|err)\..*|.*print(f|ln)?). is not checked' linters: [ errcheck ] - path: (.+)_test\.go - linters: [ gocognit, mnd ] + linters: [ gocognit, goconst, mnd ] + - text: 'assigned to ctx' + linters: [ wastedassign ] + - text: 'ctx is never used' + linters: [ staticcheck ] + + paths: + - \\.git$ + - assets$ + - bench(mark)?s?$ + - bin$ + - build$ + - configs?$ + - deploy(ment)?s?$ + - docs$ + - githooks$ + - scripts$ + + generated: strict settings: + depguard: + rules: + main: + list-mode: lax + deny: + - pkg: 'math/rand$' + desc: 'use math/rand/v2' + - pkg: 'github.com/pkg/errors' + desc: 'Should be replaced by standard lib errors package' + + dupword: + comments-only: true + + embeddedstructfieldcheck: + forbid-mutex: true + + errcheck: + exclude-functions: + - encoding/json.Marshal + - encoding/json.MarshalIndent + gocognit: min-complexity: 10 @@ -92,6 +148,7 @@ linters: - dupArg # Detects suspicious duplicated arguments. - dupBranchBody # Detects duplicated branch bodies inside conditional statements. - dupCase # Detects duplicated case clauses inside switch or select statements. + - dupOption # Detects duplicated option function arguments in variadic function calls. - dupSubExpr # Detects suspicious duplicated sub-expressions. - dynamicFmtString # Detects suspicious formatting strings usage. - emptyDecl # Detects suspicious empty declarations blocks. @@ -184,10 +241,14 @@ linters: - rangeValCopy # Detects loops that copy big objects during each iteration. - sliceClear # Detects slice clear loops, suggests an idiom that is recognized by the Go compiler. - stringXbytes # Detects redundant conversions between string and []byte. + - zeroByteRepeat # Detects bytes.Repeat with 0 value. goheader: template-path: ../.github/goheader.tmpl + gomoddirectives: + replace-local: true + gosec: excludes: # _ instead of err checks @@ -196,6 +257,17 @@ linters: govet: enable-all: true + iface: + enable: + - identical + - opaque + + inamedparam: + skip-single-param: true + + iotamixing: + report-individual: true + nakedret: max-func-lines: 10 @@ -208,33 +280,62 @@ linters: prealloc: range-loops: true + reassign: + patterns: + - '.*' + revive: severity: error rules: - - name: atomic # Check for commonly mistaken usages of the sync/atomic package. - - name: confusing-naming # Methods or fields of struct that have names different only by capitalization could be confusing. - - name: confusing-results # Function or methods that return multiple, no named, values of the same type could induce error. - - name: constant-logical-expr # The rule spots logical expressions that evaluate always to the same value. - - name: context-keys-type # Basic types should not be used as a key in context.WithValue. - - name: deep-exit # Packages exposing functions that can stop program execution by exiting are hard to reuse. This rule looks for program exits in functions other than main() or init(). - - name: early-return # In GO it is idiomatic to minimize nesting statements, a typical example is to avoid if-then-else constructions. - - name: empty-block # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. - - name: empty-lines # Sometimes gofmt is not enough to enforce a common formatting of a code-base; this rule warns when there are heading or trailing newlines in code blocks. - - name: error-return # By convention, for the sake of readability, the errors should be last in the list of returned values by a function. - - name: error-strings # By convention, for better readability, error messages should not be capitalized or end with punctuation or a newline. - - name: errorf # It is possible to get a simpler program by replacing errors.New(fmt.Sprintf()) with fmt.Errorf(). This rule spots that kind of simplification opportunities. - - name: identical-branches # An if-then-else conditional with identical implementations in both branches is an error. - - name: if-return # Checking if an error is nil to just after return the error or nil is redundant. - - name: increment-decrement # By convention, for better readability, incrementing an integer variable by 1 is recommended to be done using the ++ operator. This rule spots expressions like i += 1 and i -= 1 and proposes to change them into i++ and i--. - - name: range # This rule suggests a shorter way of writing ranges that do not use the second value. - - name: redefines-builtin-id # Constant names like false, true, nil, function names like append, make, and basic type names like bool, and byte are not reserved words of the language; therefore the can be redefined. Even if possible, redefining these built in names can lead to bugs very difficult to detect. - - name: redundant-build-tag # This rule warns about redundant build tag comments // +build when //go:build is present. gofmt in Go 1.17+ automatically adds the //go:build constraint, making the // +build comment unnecessary. - - name: string-of-int # Explicit type conversion string(i) where i has an integer type other than rune might behave not as expected by the developer (e.g. string(42) is not "42"). This rule spot that kind of suspicious conversions. - - name: use-any # Since Go 1.18, interface{} has an alias: any. This rule proposes to replace instances of interface{} with any. - - name: use-errors-new # This rules identifies calls to fmt.Errorf that can be safely replaced by, the more efficient, errors.New. - - name: unnecessary-stmt # This rule suggests to remove redundant statements like a break at the end of a case block, for improving the code's readability. - - name: unreachable-code # This rule spots and proposes to remove unreachable code. - - name: waitgroup-by-value # Function parameters that are passed by value, are in fact a copy of the original argument. Passing a copy of a sync.WaitGroup is usually not what the developer wants to do. This rule warns when a sync.WaitGroup expected as a by-value parameter in a function or method. + - name: atomic # Check for commonly mistaken usages of the sync/atomic package. + - name: confusing-naming # Methods or fields of struct that have names different only by capitalization could be confusing. + - name: confusing-results # Function or methods that return multiple, no named, values of the same type could induce error. + - name: constant-logical-expr # The rule spots logical expressions that evaluate always to the same value. + - name: context-as-argument # By convention, context.Context should be the first parameter of a function. This rule spots function declarations that do not follow the convention. + - name: context-keys-type # Basic types should not be used as a key in context.WithValue. + - name: deep-exit # Packages exposing functions that can stop program execution by exiting are hard to reuse. This rule looks for program exits in functions other than main() or init(). + - name: defer # This rule warns on some common mistakes when using defer statement. + arguments: + - - 'call-chain' + - 'loop' + - 'method-call' + - 'recover' + - 'immediate-recover' + - 'return' + - name: duplicated-imports # It is possible to unintentionally import the same package twice. This rule looks for packages that are imported two or more times. + - name: early-return # In GO it is idiomatic to minimize nesting statements, a typical example is to avoid if-then-else constructions. + - name: empty-block # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. + - name: empty-lines # Sometimes gofmt is not enough to enforce a common formatting of a code-base; this rule warns when there are heading or trailing newlines in code blocks. + - name: error-return # By convention, for the sake of readability, the errors should be last in the list of returned values by a function. + - name: error-strings # By convention, for better readability, error messages should not be capitalized or end with punctuation or a newline. + - name: errorf # It is possible to get a simpler program by replacing errors.New(fmt.Sprintf()) with fmt.Errorf(). This rule spots that kind of simplification opportunities. + - name: forbidden-call-in-wg-go # Warns on forbidden calls inside calls to wg.Go. + - name: identical-branches # An if-then-else conditional with identical implementations in both branches is an error. + - name: identical-ifelseif-branches # An if ... else if chain with identical branches makes maintenance harder and might be a source of bugs. Duplicated branches should be consolidated in one. + - name: identical-ifelseif-conditions # An if ... else if chain with identical conditions can lead to unreachable code and is a potential source of bugs while making the code harder to read and maintain. + - name: identical-switch-branches # A switch with identical branches makes maintenance harder and might be a source of bugs. Duplicated branches should be consolidated in one case clause. + - name: identical-switch-conditions # A switch statement with cases with the same condition can lead to unreachable code and is a potential source of bugs while making the code harder to read and maintain. + - name: if-return # Checking if an error is nil to just after return the error or nil is redundant. + - name: increment-decrement # By convention, for better readability, incrementing an integer variable by 1 is recommended to be done using the ++ operator. This rule spots expressions like i += 1 and i -= 1 and proposes to change them into i++ and i--. + - name: inefficient-map-lookup # This rule identifies code that iteratively searches for a key in a map. + - name: optimize-operands-order # Conditional expressions can be written to take advantage of short circuit evaluation and speed up its average evaluation time by forcing the evaluation of less time-consuming terms before more costly ones. This rule spots logical expressions where the order of evaluation of terms seems non optimal. + - name: range # This rule suggests a shorter way of writing ranges that do not use the second value. + - name: redefines-builtin-id # Constant names like false, true, nil, function names like append, make, and basic type names like bool, and byte are not reserved words of the language; therefore the can be redefined. Even if possible, redefining these built in names can lead to bugs very difficult to detect. + - name: redundant-build-tag # This rule warns about redundant build tag comments // +build when //go:build is present. gofmt in Go 1.17+ automatically adds the //go:build constraint, making the // +build comment unnecessary. + - name: string-of-int # Explicit type conversion string(i) where i has an integer type other than rune might behave not as expected by the developer (e.g. string(42) is not "42"). This rule spot that kind of suspicious conversions. + - name: unchecked-type-assertion # This rule checks whether a type assertion result is checked (the ok value), preventing unexpected panics. + arguments: + - accept-ignored-assertion-result: true + - name: use-any # Since Go 1.18, interface{} has an alias: any. This rule proposes to replace instances of interface{} with any. + - name: use-errors-new # This rules identifies calls to fmt.Errorf that can be safely replaced by, the more efficient, errors.New. + - name: use-fmt-print # This rule proposes to replace calls to built-in print and println with their equivalents from fmt standard package. + - name: use-waitgroup-go # Since Go 1.25 the sync package proposes the WaitGroup.Go method. This method is a shorter and safer replacement for the idiom wg.Add ... go { ... wg.Done ... }. + - name: useless-break # This rule warns on useless break statements in case clauses of switch and select statements. + - name: useless-fallthrough # This rule warns on useless fallthrough statements in case clauses of switch statements. A fallthrough is considered useless if it's the single statement of a case clause block. + - name: unnecessary-if # Identifies `if-else` statements that can be replaced by simpler statements. + - name: unnecessary-stmt # This rule suggests to remove redundant statements like a break at the end of a case block, for improving the code's readability. + - name: unreachable-code # This rule spots and proposes to remove unreachable code. + - name: waitgroup-by-value # Function parameters that are passed by value, are in fact a copy of the original argument. Passing a copy of a sync.WaitGroup is usually not what the developer wants to do. This rule warns when a sync.WaitGroup expected as a by-value parameter in a function or method. issues: max-issues-per-linter: 0 diff --git a/closer/closer_test.go b/closer/closer_test.go index 7e2f3d0..29997c4 100644 --- a/closer/closer_test.go +++ b/closer/closer_test.go @@ -24,22 +24,28 @@ func TestCloser(t *testing.T) { goleak.VerifyNone(t, goleak.IgnoreCurrent()) SetContext(context.WithValue(context.Background(), key, "testvalue")) + + var ctxErr error Add(func(ctx context.Context) error { - require.NoError(t, ctx.Err()) + ctxErr = ctx.Err() assert.Equal(t, "testvalue", ctx.Value(key)) return nil }) wg := sync.WaitGroup{} wg.Add(1) + var err error go func() { + defer wg.Done() <-Done() - require.NoError(t, Err()) - wg.Done() + err = Err() }() CloseAll() wg.Wait() + + require.NoError(t, ctxErr) + require.NoError(t, err) }) t.Run("with context cancel", func(t *testing.T) { @@ -66,17 +72,19 @@ func TestCloser(t *testing.T) { wg := sync.WaitGroup{} wg.Add(1) + var err error go func() { + defer wg.Done() <-c.Done() - err := c.Err() - require.ErrorContains(t, err, "test error #1") - require.ErrorContains(t, err, "test error #2") - wg.Done() + err = c.Err() }() cancel() wg.Wait() + require.ErrorContains(t, err, "test error #1") + require.ErrorContains(t, err, "test error #2") + assert.Equal(t, uint32(2), cnt.Load()) }) From 24fb2716153c518cb778f38941773054cca9bac7 Mon Sep 17 00:00:00 2001 From: Alexander Menshchikov Date: Thu, 29 Oct 2026 16:02:12 +0300 Subject: [PATCH 2/9] Update ctxkey golangci-lint config --- ctxkey/.golangci.yml | 160 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 131 insertions(+), 29 deletions(-) diff --git a/ctxkey/.golangci.yml b/ctxkey/.golangci.yml index b24f867..ac96fb5 100644 --- a/ctxkey/.golangci.yml +++ b/ctxkey/.golangci.yml @@ -20,50 +20,106 @@ formatters: linters: default: none enable: + - asasalint # Check for pass []any as any in variadic func(…any). - asciicheck # Checks that all code identifiers does not have non-ASCII symbols in the name. - bidichk # Checks for dangerous unicode character sequences. - - bodyclose # Checks whether HTTP response body is closed successfully. - - canonicalheader # Canonicalheader checks whether net/http.Header uses canonical header. + - containedctx # Containedctx is a linter that detects struct contained context.Context field. - contextcheck # Check whether the function uses a non-inherited context. + - copyloopvar # Copyloopvar is a linter detects places where loop variables are copied. + - depguard # Go linter that checks if package imports are in a list of acceptable packages. + - dupword # Checks for duplicate words in the source code. - durationcheck # Check for two durations multiplied together. + - embeddedstructfieldcheck # Embedded types should be at the top of the field list of a struct, and there must be an empty line separating embedded fields from regular fields. - errcheck # Errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases. - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error. - errorlint # Errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. + - exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. + - fatcontext # Detects nested contexts in loops and function literals. + - forcetypeassert # Find forced type assertions. - funcorder # Checks the order of functions, methods, and constructors. - gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. - gocognit # Computes and checks the cognitive complexity of functions. - goconst # Finds repeated strings that could be replaced by a constant. - gocritic # Provides diagnostics that check for bugs, performance and style issues. - goheader # Checks if file header matches to pattern. + - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. - gosec # Inspects source code for security problems. - govet # Vet examines Go source code and reports suspicious constructs. - - ineffassign # Detects when assignments to existing variables are not used. + - iface # Detect the incorrect use of interfaces, helping developers avoid interface pollution. + - inamedparam # Reports interfaces with unnamed method parameters. + - intrange # Intrange is a linter to find places where for loops could make use of an integer range. + - iotamixing # Checks if iotas are being used in const blocks with other non-iota declarations. - makezero # Finds slice declarations with non-zero initial length. + - mirror # Reports wrong mirror patterns of bytes/strings usage. - mnd # An analyzer to detect magic numbers. + - modernize # A suite of analyzers that suggest simplifications to Go code, using modern language and library features. - nakedret # Checks that functions with naked returns are not longer than a maximum size (can be zero). - nilnil # Checks that there is no simultaneous return of nil error and an invalid value. - - noctx # Finds sending http request without context.Context. - nolintlint # Reports ill-formed or insufficient nolint directives. - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. - perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. - prealloc # Finds slice declarations that could potentially be pre-allocated. + - reassign # Checks that package variables are not reassigned. - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. - staticcheck # It's a set of rules from staticcheck. + - testifylint # Checks usage of github.com/stretchr/testify. - testpackage # Linter that makes you use a separate _test package. + - thelper # Thelper detects tests helpers which do not start with the t.Helper() method. + - tparallel # Tparallel detects inappropriate usage of t.Parallel() method in your Go test codes. - unconvert # Remove unnecessary type conversions. - unused # Checks Go code for unused constants, variables, functions and types. - - usetesting # Reports uses of functions with replacement inside the testing package. - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. + - usetesting # Reports uses of functions with replacement inside the testing package. - wastedassign # Finds wasted assignment statements. + - whitespace # Checks for unnecessary newlines at the start and end of functions, if, for, etc. exclusions: rules: - text: 'Error return value of .((os\.)?std(out|err)\..*|.*print(f|ln)?). is not checked' linters: [ errcheck ] - path: (.+)_test\.go - linters: [ gocognit, mnd ] + linters: [ gocognit, goconst, mnd ] + - text: 'assigned to ctx' + linters: [ wastedassign ] + - text: 'ctx is never used' + linters: [ staticcheck ] + + paths: + - \\.git$ + - assets$ + - bench(mark)?s?$ + - bin$ + - build$ + - configs?$ + - deploy(ment)?s?$ + - docs$ + - githooks$ + - scripts$ + + generated: strict settings: + depguard: + rules: + main: + list-mode: lax + deny: + - pkg: 'math/rand$' + desc: 'use math/rand/v2' + - pkg: 'github.com/pkg/errors' + desc: 'Should be replaced by standard lib errors package' + + dupword: + comments-only: true + + embeddedstructfieldcheck: + forbid-mutex: true + + errcheck: + exclude-functions: + - encoding/json.Marshal + - encoding/json.MarshalIndent + gocognit: min-complexity: 10 @@ -92,6 +148,7 @@ linters: - dupArg # Detects suspicious duplicated arguments. - dupBranchBody # Detects duplicated branch bodies inside conditional statements. - dupCase # Detects duplicated case clauses inside switch or select statements. + - dupOption # Detects duplicated option function arguments in variadic function calls. - dupSubExpr # Detects suspicious duplicated sub-expressions. - dynamicFmtString # Detects suspicious formatting strings usage. - emptyDecl # Detects suspicious empty declarations blocks. @@ -184,10 +241,14 @@ linters: - rangeValCopy # Detects loops that copy big objects during each iteration. - sliceClear # Detects slice clear loops, suggests an idiom that is recognized by the Go compiler. - stringXbytes # Detects redundant conversions between string and []byte. + - zeroByteRepeat # Detects bytes.Repeat with 0 value. goheader: template-path: ../.github/goheader.tmpl + gomoddirectives: + replace-local: true + gosec: excludes: # _ instead of err checks @@ -196,6 +257,17 @@ linters: govet: enable-all: true + iface: + enable: + - identical + - unused + + inamedparam: + skip-single-param: true + + iotamixing: + report-individual: true + nakedret: max-func-lines: 10 @@ -208,32 +280,62 @@ linters: prealloc: range-loops: true + reassign: + patterns: + - '.*' + revive: severity: error rules: - - name: atomic # Check for commonly mistaken usages of the sync/atomic package. - - name: confusing-naming # Methods or fields of struct that have names different only by capitalization could be confusing. - - name: confusing-results # Function or methods that return multiple, no named, values of the same type could induce error. - - name: constant-logical-expr # The rule spots logical expressions that evaluate always to the same value. - - name: context-keys-type # Basic types should not be used as a key in context.WithValue. - - name: deep-exit # Packages exposing functions that can stop program execution by exiting are hard to reuse. This rule looks for program exits in functions other than main() or init(). - - name: early-return # In GO it is idiomatic to minimize nesting statements, a typical example is to avoid if-then-else constructions. - - name: empty-block # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. - - name: empty-lines # Sometimes gofmt is not enough to enforce a common formatting of a code-base; this rule warns when there are heading or trailing newlines in code blocks. - - name: error-return # By convention, for the sake of readability, the errors should be last in the list of returned values by a function. - - name: error-strings # By convention, for better readability, error messages should not be capitalized or end with punctuation or a newline. - - name: errorf # It is possible to get a simpler program by replacing errors.New(fmt.Sprintf()) with fmt.Errorf(). This rule spots that kind of simplification opportunities. - - name: identical-branches # An if-then-else conditional with identical implementations in both branches is an error. - - name: if-return # Checking if an error is nil to just after return the error or nil is redundant. - - name: increment-decrement # By convention, for better readability, incrementing an integer variable by 1 is recommended to be done using the ++ operator. This rule spots expressions like i += 1 and i -= 1 and proposes to change them into i++ and i--. - - name: range # This rule suggests a shorter way of writing ranges that do not use the second value. - - name: redefines-builtin-id # Constant names like false, true, nil, function names like append, make, and basic type names like bool, and byte are not reserved words of the language; therefore the can be redefined. Even if possible, redefining these built in names can lead to bugs very difficult to detect. - - name: redundant-build-tag # This rule warns about redundant build tag comments // +build when //go:build is present. gofmt in Go 1.17+ automatically adds the //go:build constraint, making the // +build comment unnecessary. - - name: string-of-int # Explicit type conversion string(i) where i has an integer type other than rune might behave not as expected by the developer (e.g. string(42) is not "42"). This rule spot that kind of suspicious conversions. - - name: use-errors-new # This rules identifies calls to fmt.Errorf that can be safely replaced by, the more efficient, errors.New. - - name: unnecessary-stmt # This rule suggests to remove redundant statements like a break at the end of a case block, for improving the code's readability. - - name: unreachable-code # This rule spots and proposes to remove unreachable code. - - name: waitgroup-by-value # Function parameters that are passed by value, are in fact a copy of the original argument. Passing a copy of a sync.WaitGroup is usually not what the developer wants to do. This rule warns when a sync.WaitGroup expected as a by-value parameter in a function or method. + - name: atomic # Check for commonly mistaken usages of the sync/atomic package. + - name: confusing-naming # Methods or fields of struct that have names different only by capitalization could be confusing. + - name: confusing-results # Function or methods that return multiple, no named, values of the same type could induce error. + - name: constant-logical-expr # The rule spots logical expressions that evaluate always to the same value. + - name: context-as-argument # By convention, context.Context should be the first parameter of a function. This rule spots function declarations that do not follow the convention. + - name: context-keys-type # Basic types should not be used as a key in context.WithValue. + - name: deep-exit # Packages exposing functions that can stop program execution by exiting are hard to reuse. This rule looks for program exits in functions other than main() or init(). + - name: defer # This rule warns on some common mistakes when using defer statement. + arguments: + - - 'call-chain' + - 'loop' + - 'method-call' + - 'recover' + - 'immediate-recover' + - 'return' + - name: duplicated-imports # It is possible to unintentionally import the same package twice. This rule looks for packages that are imported two or more times. + - name: early-return # In GO it is idiomatic to minimize nesting statements, a typical example is to avoid if-then-else constructions. + - name: empty-block # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. + - name: empty-lines # Sometimes gofmt is not enough to enforce a common formatting of a code-base; this rule warns when there are heading or trailing newlines in code blocks. + - name: error-return # By convention, for the sake of readability, the errors should be last in the list of returned values by a function. + - name: error-strings # By convention, for better readability, error messages should not be capitalized or end with punctuation or a newline. + - name: errorf # It is possible to get a simpler program by replacing errors.New(fmt.Sprintf()) with fmt.Errorf(). This rule spots that kind of simplification opportunities. + - name: forbidden-call-in-wg-go # Warns on forbidden calls inside calls to wg.Go. + - name: identical-branches # An if-then-else conditional with identical implementations in both branches is an error. + - name: identical-ifelseif-branches # An if ... else if chain with identical branches makes maintenance harder and might be a source of bugs. Duplicated branches should be consolidated in one. + - name: identical-ifelseif-conditions # An if ... else if chain with identical conditions can lead to unreachable code and is a potential source of bugs while making the code harder to read and maintain. + - name: identical-switch-branches # A switch with identical branches makes maintenance harder and might be a source of bugs. Duplicated branches should be consolidated in one case clause. + - name: identical-switch-conditions # A switch statement with cases with the same condition can lead to unreachable code and is a potential source of bugs while making the code harder to read and maintain. + - name: if-return # Checking if an error is nil to just after return the error or nil is redundant. + - name: increment-decrement # By convention, for better readability, incrementing an integer variable by 1 is recommended to be done using the ++ operator. This rule spots expressions like i += 1 and i -= 1 and proposes to change them into i++ and i--. + - name: inefficient-map-lookup # This rule identifies code that iteratively searches for a key in a map. + - name: optimize-operands-order # Conditional expressions can be written to take advantage of short circuit evaluation and speed up its average evaluation time by forcing the evaluation of less time-consuming terms before more costly ones. This rule spots logical expressions where the order of evaluation of terms seems non optimal. + - name: range # This rule suggests a shorter way of writing ranges that do not use the second value. + - name: redefines-builtin-id # Constant names like false, true, nil, function names like append, make, and basic type names like bool, and byte are not reserved words of the language; therefore the can be redefined. Even if possible, redefining these built in names can lead to bugs very difficult to detect. + - name: redundant-build-tag # This rule warns about redundant build tag comments // +build when //go:build is present. gofmt in Go 1.17+ automatically adds the //go:build constraint, making the // +build comment unnecessary. + - name: string-of-int # Explicit type conversion string(i) where i has an integer type other than rune might behave not as expected by the developer (e.g. string(42) is not "42"). This rule spot that kind of suspicious conversions. + - name: unchecked-type-assertion # This rule checks whether a type assertion result is checked (the ok value), preventing unexpected panics. + arguments: + - accept-ignored-assertion-result: true + - name: use-any # Since Go 1.18, interface{} has an alias: any. This rule proposes to replace instances of interface{} with any. + - name: use-errors-new # This rules identifies calls to fmt.Errorf that can be safely replaced by, the more efficient, errors.New. + - name: use-fmt-print # This rule proposes to replace calls to built-in print and println with their equivalents from fmt standard package. + - name: use-waitgroup-go # Since Go 1.25 the sync package proposes the WaitGroup.Go method. This method is a shorter and safer replacement for the idiom wg.Add ... go { ... wg.Done ... }. + - name: useless-break # This rule warns on useless break statements in case clauses of switch and select statements. + - name: useless-fallthrough # This rule warns on useless fallthrough statements in case clauses of switch statements. A fallthrough is considered useless if it's the single statement of a case clause block. + - name: unnecessary-if # Identifies `if-else` statements that can be replaced by simpler statements. + - name: unnecessary-stmt # This rule suggests to remove redundant statements like a break at the end of a case block, for improving the code's readability. + - name: unreachable-code # This rule spots and proposes to remove unreachable code. + - name: waitgroup-by-value # Function parameters that are passed by value, are in fact a copy of the original argument. Passing a copy of a sync.WaitGroup is usually not what the developer wants to do. This rule warns when a sync.WaitGroup expected as a by-value parameter in a function or method. issues: max-issues-per-linter: 0 From 8d8ac825f3ad2a98ca49b695e071dfc8ffe05cdd Mon Sep 17 00:00:00 2001 From: Alexander Menshchikov Date: Thu, 29 Oct 2026 16:02:12 +0300 Subject: [PATCH 3/9] Update deferred golangci-lint config --- deferred/.golangci.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/deferred/.golangci.yml b/deferred/.golangci.yml index 584be97..d6bf931 100644 --- a/deferred/.golangci.yml +++ b/deferred/.golangci.yml @@ -23,8 +23,6 @@ linters: - asasalint # Check for pass []any as any in variadic func(…any). - asciicheck # Checks that all code identifiers does not have non-ASCII symbols in the name. - bidichk # Checks for dangerous unicode character sequences. - - bodyclose # Checks whether HTTP response body is closed successfully. - - canonicalheader # Canonicalheader checks whether net/http.Header uses canonical header. - containedctx # Containedctx is a linter that detects struct contained context.Context field. - contextcheck # Check whether the function uses a non-inherited context. - copyloopvar # Copyloopvar is a linter detects places where loop variables are copied. @@ -33,7 +31,6 @@ linters: - durationcheck # Check for two durations multiplied together. - embeddedstructfieldcheck # Embedded types should be at the top of the field list of a struct, and there must be an empty line separating embedded fields from regular fields. - errcheck # Errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases. - - errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and reports occurrences where the check for the returned error can be omitted. - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error. - errorlint # Errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. - exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. @@ -56,10 +53,8 @@ linters: - mirror # Reports wrong mirror patterns of bytes/strings usage. - mnd # An analyzer to detect magic numbers. - modernize # A suite of analyzers that suggest simplifications to Go code, using modern language and library features. - - musttag # Enforce field tags in (un)marshaled structs. - nakedret # Checks that functions with naked returns are not longer than a maximum size (can be zero). - nilnil # Checks that there is no simultaneous return of nil error and an invalid value. - - noctx # Finds sending http request without context.Context. - nolintlint # Reports ill-formed or insufficient nolint directives. - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. - perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. @@ -125,10 +120,6 @@ linters: - encoding/json.Marshal - encoding/json.MarshalIndent - errchkjson: - check-error-free-encoding: true - report-no-exported: true - gocognit: min-complexity: 10 From b7aef22029fd143065d394c30ba7e72eb54a5326 Mon Sep 17 00:00:00 2001 From: Alexander Menshchikov Date: Thu, 29 Oct 2026 16:02:12 +0300 Subject: [PATCH 4/9] Update dispatcher golangci-lint config --- dispatcher/.golangci.yml | 41 +++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/dispatcher/.golangci.yml b/dispatcher/.golangci.yml index 2e1c5b8..7f28cfa 100644 --- a/dispatcher/.golangci.yml +++ b/dispatcher/.golangci.yml @@ -23,11 +23,10 @@ linters: - asasalint # Check for pass []any as any in variadic func(…any). - asciicheck # Checks that all code identifiers does not have non-ASCII symbols in the name. - bidichk # Checks for dangerous unicode character sequences. - - bodyclose # Checks whether HTTP response body is closed successfully. - - canonicalheader # Canonicalheader checks whether net/http.Header uses canonical header. - containedctx # Containedctx is a linter that detects struct contained context.Context field. - contextcheck # Check whether the function uses a non-inherited context. - copyloopvar # Copyloopvar is a linter detects places where loop variables are copied. + - depguard # Go linter that checks if package imports are in a list of acceptable packages. - dupword # Checks for duplicate words in the source code. - durationcheck # Check for two durations multiplied together. - embeddedstructfieldcheck # Embedded types should be at the top of the field list of a struct, and there must be an empty line separating embedded fields from regular fields. @@ -53,10 +52,9 @@ linters: - makezero # Finds slice declarations with non-zero initial length. - mirror # Reports wrong mirror patterns of bytes/strings usage. - mnd # An analyzer to detect magic numbers. - - musttag # Enforce field tags in (un)marshaled structs. + - modernize # A suite of analyzers that suggest simplifications to Go code, using modern language and library features. - nakedret # Checks that functions with naked returns are not longer than a maximum size (can be zero). - nilnil # Checks that there is no simultaneous return of nil error and an invalid value. - - noctx # Finds sending http request without context.Context. - nolintlint # Reports ill-formed or insufficient nolint directives. - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. - perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. @@ -67,6 +65,7 @@ linters: - testifylint # Checks usage of github.com/stretchr/testify. - testpackage # Linter that makes you use a separate _test package. - thelper # Thelper detects tests helpers which do not start with the t.Helper() method. + - tparallel # Tparallel detects inappropriate usage of t.Parallel() method in your Go test codes. - unconvert # Remove unnecessary type conversions. - unused # Checks Go code for unused constants, variables, functions and types. - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. @@ -80,8 +79,36 @@ linters: linters: [ errcheck ] - path: (.+)_test\.go linters: [ gocognit, goconst, mnd ] + - text: 'assigned to ctx' + linters: [ wastedassign ] + - text: 'ctx is never used' + linters: [ staticcheck ] + + paths: + - \\.git$ + - assets$ + - bench(mark)?s?$ + - bin$ + - build$ + - configs?$ + - deploy(ment)?s?$ + - docs$ + - githooks$ + - scripts$ + + generated: strict settings: + depguard: + rules: + main: + list-mode: lax + deny: + - pkg: 'math/rand$' + desc: 'use math/rand/v2' + - pkg: 'github.com/pkg/errors' + desc: 'Should be replaced by standard lib errors package' + dupword: comments-only: true @@ -216,12 +243,12 @@ linters: - stringXbytes # Detects redundant conversions between string and []byte. - zeroByteRepeat # Detects bytes.Repeat with 0 value. - gomoddirectives: - replace-local: true - goheader: template-path: ../.github/goheader.tmpl + gomoddirectives: + replace-local: true + gosec: excludes: # _ instead of err checks From 7892a0a9d60625df7fbf245579d39c54a65b87b8 Mon Sep 17 00:00:00 2001 From: Alexander Menshchikov Date: Thu, 29 Oct 2026 16:02:13 +0300 Subject: [PATCH 5/9] Update protomap golangci-lint config --- protomap/.golangci.yml | 15 ++++++--------- protomap/protomap_test.go | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/protomap/.golangci.yml b/protomap/.golangci.yml index 584be97..61e915f 100644 --- a/protomap/.golangci.yml +++ b/protomap/.golangci.yml @@ -23,8 +23,6 @@ linters: - asasalint # Check for pass []any as any in variadic func(…any). - asciicheck # Checks that all code identifiers does not have non-ASCII symbols in the name. - bidichk # Checks for dangerous unicode character sequences. - - bodyclose # Checks whether HTTP response body is closed successfully. - - canonicalheader # Canonicalheader checks whether net/http.Header uses canonical header. - containedctx # Containedctx is a linter that detects struct contained context.Context field. - contextcheck # Check whether the function uses a non-inherited context. - copyloopvar # Copyloopvar is a linter detects places where loop variables are copied. @@ -33,7 +31,6 @@ linters: - durationcheck # Check for two durations multiplied together. - embeddedstructfieldcheck # Embedded types should be at the top of the field list of a struct, and there must be an empty line separating embedded fields from regular fields. - errcheck # Errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases. - - errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and reports occurrences where the check for the returned error can be omitted. - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error. - errorlint # Errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. - exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. @@ -56,14 +53,13 @@ linters: - mirror # Reports wrong mirror patterns of bytes/strings usage. - mnd # An analyzer to detect magic numbers. - modernize # A suite of analyzers that suggest simplifications to Go code, using modern language and library features. - - musttag # Enforce field tags in (un)marshaled structs. - nakedret # Checks that functions with naked returns are not longer than a maximum size (can be zero). - nilnil # Checks that there is no simultaneous return of nil error and an invalid value. - - noctx # Finds sending http request without context.Context. - nolintlint # Reports ill-formed or insufficient nolint directives. - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. - perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. - prealloc # Finds slice declarations that could potentially be pre-allocated. + - protogetter # Reports direct reads from proto message fields when getters should be used. - reassign # Checks that package variables are not reassigned. - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. - staticcheck # It's a set of rules from staticcheck. @@ -125,10 +121,6 @@ linters: - encoding/json.Marshal - encoding/json.MarshalIndent - errchkjson: - check-error-free-encoding: true - report-no-exported: true - gocognit: min-complexity: 10 @@ -290,6 +282,11 @@ linters: prealloc: range-loops: true + protogetter: + skip-files: + - '*/vendor/*' + skip-any-generated: true + reassign: patterns: - '.*' diff --git a/protomap/protomap_test.go b/protomap/protomap_test.go index da08590..9bdfab3 100644 --- a/protomap/protomap_test.go +++ b/protomap/protomap_test.go @@ -194,6 +194,6 @@ func TestProtomap_Unmarshal(t *testing.T) { require.NoError(t, err) first.Value = "changed" - assert.Equal(t, "value", second.Value) + assert.Equal(t, "value", second.GetValue()) }) } From 98afbc1304a3390b05ad704c2ff4c7541f28285f Mon Sep 17 00:00:00 2001 From: Alexander Menshchikov Date: Thu, 29 Oct 2026 16:02:13 +0300 Subject: [PATCH 6/9] Update protowrap golangci-lint config --- protowrap/.golangci.yml | 168 +++++++++++++++++++++++++++++++++------- 1 file changed, 138 insertions(+), 30 deletions(-) diff --git a/protowrap/.golangci.yml b/protowrap/.golangci.yml index 6d6d7d1..61e915f 100644 --- a/protowrap/.golangci.yml +++ b/protowrap/.golangci.yml @@ -20,50 +20,107 @@ formatters: linters: default: none enable: + - asasalint # Check for pass []any as any in variadic func(…any). - asciicheck # Checks that all code identifiers does not have non-ASCII symbols in the name. - bidichk # Checks for dangerous unicode character sequences. - - bodyclose # Checks whether HTTP response body is closed successfully. - - canonicalheader # Canonicalheader checks whether net/http.Header uses canonical header. + - containedctx # Containedctx is a linter that detects struct contained context.Context field. - contextcheck # Check whether the function uses a non-inherited context. + - copyloopvar # Copyloopvar is a linter detects places where loop variables are copied. + - depguard # Go linter that checks if package imports are in a list of acceptable packages. + - dupword # Checks for duplicate words in the source code. - durationcheck # Check for two durations multiplied together. + - embeddedstructfieldcheck # Embedded types should be at the top of the field list of a struct, and there must be an empty line separating embedded fields from regular fields. - errcheck # Errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases. - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error. - errorlint # Errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. + - exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. + - fatcontext # Detects nested contexts in loops and function literals. + - forcetypeassert # Find forced type assertions. - funcorder # Checks the order of functions, methods, and constructors. - gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. - gocognit # Computes and checks the cognitive complexity of functions. - goconst # Finds repeated strings that could be replaced by a constant. - gocritic # Provides diagnostics that check for bugs, performance and style issues. - goheader # Checks if file header matches to pattern. + - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. - gosec # Inspects source code for security problems. - govet # Vet examines Go source code and reports suspicious constructs. - - ineffassign # Detects when assignments to existing variables are not used. + - iface # Detect the incorrect use of interfaces, helping developers avoid interface pollution. + - inamedparam # Reports interfaces with unnamed method parameters. + - intrange # Intrange is a linter to find places where for loops could make use of an integer range. + - iotamixing # Checks if iotas are being used in const blocks with other non-iota declarations. - makezero # Finds slice declarations with non-zero initial length. + - mirror # Reports wrong mirror patterns of bytes/strings usage. - mnd # An analyzer to detect magic numbers. + - modernize # A suite of analyzers that suggest simplifications to Go code, using modern language and library features. - nakedret # Checks that functions with naked returns are not longer than a maximum size (can be zero). - nilnil # Checks that there is no simultaneous return of nil error and an invalid value. - - noctx # Finds sending http request without context.Context. - nolintlint # Reports ill-formed or insufficient nolint directives. - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. - perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. - prealloc # Finds slice declarations that could potentially be pre-allocated. + - protogetter # Reports direct reads from proto message fields when getters should be used. + - reassign # Checks that package variables are not reassigned. - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. - staticcheck # It's a set of rules from staticcheck. + - testifylint # Checks usage of github.com/stretchr/testify. - testpackage # Linter that makes you use a separate _test package. + - thelper # Thelper detects tests helpers which do not start with the t.Helper() method. + - tparallel # Tparallel detects inappropriate usage of t.Parallel() method in your Go test codes. - unconvert # Remove unnecessary type conversions. - unused # Checks Go code for unused constants, variables, functions and types. - - usetesting # Reports uses of functions with replacement inside the testing package. - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. + - usetesting # Reports uses of functions with replacement inside the testing package. - wastedassign # Finds wasted assignment statements. + - whitespace # Checks for unnecessary newlines at the start and end of functions, if, for, etc. exclusions: rules: - text: 'Error return value of .((os\.)?std(out|err)\..*|.*print(f|ln)?). is not checked' linters: [ errcheck ] - path: (.+)_test\.go - linters: [ gocognit, mnd ] + linters: [ gocognit, goconst, mnd ] + - text: 'assigned to ctx' + linters: [ wastedassign ] + - text: 'ctx is never used' + linters: [ staticcheck ] + + paths: + - \\.git$ + - assets$ + - bench(mark)?s?$ + - bin$ + - build$ + - configs?$ + - deploy(ment)?s?$ + - docs$ + - githooks$ + - scripts$ + + generated: strict settings: + depguard: + rules: + main: + list-mode: lax + deny: + - pkg: 'math/rand$' + desc: 'use math/rand/v2' + - pkg: 'github.com/pkg/errors' + desc: 'Should be replaced by standard lib errors package' + + dupword: + comments-only: true + + embeddedstructfieldcheck: + forbid-mutex: true + + errcheck: + exclude-functions: + - encoding/json.Marshal + - encoding/json.MarshalIndent + gocognit: min-complexity: 10 @@ -92,6 +149,7 @@ linters: - dupArg # Detects suspicious duplicated arguments. - dupBranchBody # Detects duplicated branch bodies inside conditional statements. - dupCase # Detects duplicated case clauses inside switch or select statements. + - dupOption # Detects duplicated option function arguments in variadic function calls. - dupSubExpr # Detects suspicious duplicated sub-expressions. - dynamicFmtString # Detects suspicious formatting strings usage. - emptyDecl # Detects suspicious empty declarations blocks. @@ -184,10 +242,14 @@ linters: - rangeValCopy # Detects loops that copy big objects during each iteration. - sliceClear # Detects slice clear loops, suggests an idiom that is recognized by the Go compiler. - stringXbytes # Detects redundant conversions between string and []byte. + - zeroByteRepeat # Detects bytes.Repeat with 0 value. goheader: template-path: ../.github/goheader.tmpl + gomoddirectives: + replace-local: true + gosec: excludes: # _ instead of err checks @@ -196,6 +258,18 @@ linters: govet: enable-all: true + iface: + enable: + - identical + - opaque + - unused + + inamedparam: + skip-single-param: true + + iotamixing: + report-individual: true + nakedret: max-func-lines: 10 @@ -208,33 +282,67 @@ linters: prealloc: range-loops: true + protogetter: + skip-files: + - '*/vendor/*' + skip-any-generated: true + + reassign: + patterns: + - '.*' + revive: severity: error rules: - - name: atomic # Check for commonly mistaken usages of the sync/atomic package. - - name: confusing-naming # Methods or fields of struct that have names different only by capitalization could be confusing. - - name: confusing-results # Function or methods that return multiple, no named, values of the same type could induce error. - - name: constant-logical-expr # The rule spots logical expressions that evaluate always to the same value. - - name: context-keys-type # Basic types should not be used as a key in context.WithValue. - - name: deep-exit # Packages exposing functions that can stop program execution by exiting are hard to reuse. This rule looks for program exits in functions other than main() or init(). - - name: early-return # In GO it is idiomatic to minimize nesting statements, a typical example is to avoid if-then-else constructions. - - name: empty-block # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. - - name: empty-lines # Sometimes gofmt is not enough to enforce a common formatting of a code-base; this rule warns when there are heading or trailing newlines in code blocks. - - name: error-return # By convention, for the sake of readability, the errors should be last in the list of returned values by a function. - - name: error-strings # By convention, for better readability, error messages should not be capitalized or end with punctuation or a newline. - - name: errorf # It is possible to get a simpler program by replacing errors.New(fmt.Sprintf()) with fmt.Errorf(). This rule spots that kind of simplification opportunities. - - name: identical-branches # An if-then-else conditional with identical implementations in both branches is an error. - - name: if-return # Checking if an error is nil to just after return the error or nil is redundant. - - name: increment-decrement # By convention, for better readability, incrementing an integer variable by 1 is recommended to be done using the ++ operator. This rule spots expressions like i += 1 and i -= 1 and proposes to change them into i++ and i--. - - name: range # This rule suggests a shorter way of writing ranges that do not use the second value. - - name: redefines-builtin-id # Constant names like false, true, nil, function names like append, make, and basic type names like bool, and byte are not reserved words of the language; therefore the can be redefined. Even if possible, redefining these built in names can lead to bugs very difficult to detect. - - name: redundant-build-tag # This rule warns about redundant build tag comments // +build when //go:build is present. gofmt in Go 1.17+ automatically adds the //go:build constraint, making the // +build comment unnecessary. - - name: string-of-int # Explicit type conversion string(i) where i has an integer type other than rune might behave not as expected by the developer (e.g. string(42) is not "42"). This rule spot that kind of suspicious conversions. - - name: use-any # Since Go 1.18, interface{} has an alias: any. This rule proposes to replace instances of interface{} with any. - - name: use-errors-new # This rules identifies calls to fmt.Errorf that can be safely replaced by, the more efficient, errors.New. - - name: unnecessary-stmt # This rule suggests to remove redundant statements like a break at the end of a case block, for improving the code's readability. - - name: unreachable-code # This rule spots and proposes to remove unreachable code. - - name: waitgroup-by-value # Function parameters that are passed by value, are in fact a copy of the original argument. Passing a copy of a sync.WaitGroup is usually not what the developer wants to do. This rule warns when a sync.WaitGroup expected as a by-value parameter in a function or method. + - name: atomic # Check for commonly mistaken usages of the sync/atomic package. + - name: confusing-naming # Methods or fields of struct that have names different only by capitalization could be confusing. + - name: confusing-results # Function or methods that return multiple, no named, values of the same type could induce error. + - name: constant-logical-expr # The rule spots logical expressions that evaluate always to the same value. + - name: context-as-argument # By convention, context.Context should be the first parameter of a function. This rule spots function declarations that do not follow the convention. + - name: context-keys-type # Basic types should not be used as a key in context.WithValue. + - name: deep-exit # Packages exposing functions that can stop program execution by exiting are hard to reuse. This rule looks for program exits in functions other than main() or init(). + - name: defer # This rule warns on some common mistakes when using defer statement. + arguments: + - - 'call-chain' + - 'loop' + - 'method-call' + - 'recover' + - 'immediate-recover' + - 'return' + - name: duplicated-imports # It is possible to unintentionally import the same package twice. This rule looks for packages that are imported two or more times. + - name: early-return # In GO it is idiomatic to minimize nesting statements, a typical example is to avoid if-then-else constructions. + - name: empty-block # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. + - name: empty-lines # Sometimes gofmt is not enough to enforce a common formatting of a code-base; this rule warns when there are heading or trailing newlines in code blocks. + - name: error-return # By convention, for the sake of readability, the errors should be last in the list of returned values by a function. + - name: error-strings # By convention, for better readability, error messages should not be capitalized or end with punctuation or a newline. + - name: errorf # It is possible to get a simpler program by replacing errors.New(fmt.Sprintf()) with fmt.Errorf(). This rule spots that kind of simplification opportunities. + - name: forbidden-call-in-wg-go # Warns on forbidden calls inside calls to wg.Go. + - name: identical-branches # An if-then-else conditional with identical implementations in both branches is an error. + - name: identical-ifelseif-branches # An if ... else if chain with identical branches makes maintenance harder and might be a source of bugs. Duplicated branches should be consolidated in one. + - name: identical-ifelseif-conditions # An if ... else if chain with identical conditions can lead to unreachable code and is a potential source of bugs while making the code harder to read and maintain. + - name: identical-switch-branches # A switch with identical branches makes maintenance harder and might be a source of bugs. Duplicated branches should be consolidated in one case clause. + - name: identical-switch-conditions # A switch statement with cases with the same condition can lead to unreachable code and is a potential source of bugs while making the code harder to read and maintain. + - name: if-return # Checking if an error is nil to just after return the error or nil is redundant. + - name: increment-decrement # By convention, for better readability, incrementing an integer variable by 1 is recommended to be done using the ++ operator. This rule spots expressions like i += 1 and i -= 1 and proposes to change them into i++ and i--. + - name: inefficient-map-lookup # This rule identifies code that iteratively searches for a key in a map. + - name: optimize-operands-order # Conditional expressions can be written to take advantage of short circuit evaluation and speed up its average evaluation time by forcing the evaluation of less time-consuming terms before more costly ones. This rule spots logical expressions where the order of evaluation of terms seems non optimal. + - name: range # This rule suggests a shorter way of writing ranges that do not use the second value. + - name: redefines-builtin-id # Constant names like false, true, nil, function names like append, make, and basic type names like bool, and byte are not reserved words of the language; therefore the can be redefined. Even if possible, redefining these built in names can lead to bugs very difficult to detect. + - name: redundant-build-tag # This rule warns about redundant build tag comments // +build when //go:build is present. gofmt in Go 1.17+ automatically adds the //go:build constraint, making the // +build comment unnecessary. + - name: string-of-int # Explicit type conversion string(i) where i has an integer type other than rune might behave not as expected by the developer (e.g. string(42) is not "42"). This rule spot that kind of suspicious conversions. + - name: unchecked-type-assertion # This rule checks whether a type assertion result is checked (the ok value), preventing unexpected panics. + arguments: + - accept-ignored-assertion-result: true + - name: use-any # Since Go 1.18, interface{} has an alias: any. This rule proposes to replace instances of interface{} with any. + - name: use-errors-new # This rules identifies calls to fmt.Errorf that can be safely replaced by, the more efficient, errors.New. + - name: use-fmt-print # This rule proposes to replace calls to built-in print and println with their equivalents from fmt standard package. + - name: use-waitgroup-go # Since Go 1.25 the sync package proposes the WaitGroup.Go method. This method is a shorter and safer replacement for the idiom wg.Add ... go { ... wg.Done ... }. + - name: useless-break # This rule warns on useless break statements in case clauses of switch and select statements. + - name: useless-fallthrough # This rule warns on useless fallthrough statements in case clauses of switch statements. A fallthrough is considered useless if it's the single statement of a case clause block. + - name: unnecessary-if # Identifies `if-else` statements that can be replaced by simpler statements. + - name: unnecessary-stmt # This rule suggests to remove redundant statements like a break at the end of a case block, for improving the code's readability. + - name: unreachable-code # This rule spots and proposes to remove unreachable code. + - name: waitgroup-by-value # Function parameters that are passed by value, are in fact a copy of the original argument. Passing a copy of a sync.WaitGroup is usually not what the developer wants to do. This rule warns when a sync.WaitGroup expected as a by-value parameter in a function or method. issues: max-issues-per-linter: 0 From 2f6f2a2dd82b3f0866e7314115913aa0585dbc91 Mon Sep 17 00:00:00 2001 From: Alexander Menshchikov Date: Thu, 29 Oct 2026 16:02:13 +0300 Subject: [PATCH 7/9] Update strcase golangci-lint config --- strcase/.golangci.yml | 159 ++++++++++++++++++++++++++++++++++-------- strcase/strcase.go | 2 + 2 files changed, 132 insertions(+), 29 deletions(-) diff --git a/strcase/.golangci.yml b/strcase/.golangci.yml index 0aa0e79..8d63edf 100644 --- a/strcase/.golangci.yml +++ b/strcase/.golangci.yml @@ -20,42 +20,58 @@ formatters: linters: default: none enable: + - asasalint # Check for pass []any as any in variadic func(…any). - asciicheck # Checks that all code identifiers does not have non-ASCII symbols in the name. - bidichk # Checks for dangerous unicode character sequences. - - bodyclose # Checks whether HTTP response body is closed successfully. - - canonicalheader # Canonicalheader checks whether net/http.Header uses canonical header. + - containedctx # Containedctx is a linter that detects struct contained context.Context field. - contextcheck # Check whether the function uses a non-inherited context. - copyloopvar # Copyloopvar is a linter detects places where loop variables are copied. + - depguard # Go linter that checks if package imports are in a list of acceptable packages. + - dupword # Checks for duplicate words in the source code. - durationcheck # Check for two durations multiplied together. + - embeddedstructfieldcheck # Embedded types should be at the top of the field list of a struct, and there must be an empty line separating embedded fields from regular fields. - errcheck # Errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases. - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error. - errorlint # Errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. + - exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. + - fatcontext # Detects nested contexts in loops and function literals. + - forcetypeassert # Find forced type assertions. - funcorder # Checks the order of functions, methods, and constructors. - gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. - gocognit # Computes and checks the cognitive complexity of functions. - goconst # Finds repeated strings that could be replaced by a constant. - gocritic # Provides diagnostics that check for bugs, performance and style issues. - goheader # Checks if file header matches to pattern. + - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. - gosec # Inspects source code for security problems. - govet # Vet examines Go source code and reports suspicious constructs. - - ineffassign # Detects when assignments to existing variables are not used. + - iface # Detect the incorrect use of interfaces, helping developers avoid interface pollution. + - inamedparam # Reports interfaces with unnamed method parameters. + - intrange # Intrange is a linter to find places where for loops could make use of an integer range. + - iotamixing # Checks if iotas are being used in const blocks with other non-iota declarations. - makezero # Finds slice declarations with non-zero initial length. + - mirror # Reports wrong mirror patterns of bytes/strings usage. - mnd # An analyzer to detect magic numbers. + - modernize # A suite of analyzers that suggest simplifications to Go code, using modern language and library features. - nakedret # Checks that functions with naked returns are not longer than a maximum size (can be zero). - nilnil # Checks that there is no simultaneous return of nil error and an invalid value. - - noctx # Finds sending http request without context.Context. - nolintlint # Reports ill-formed or insufficient nolint directives. - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. - perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. - prealloc # Finds slice declarations that could potentially be pre-allocated. + - reassign # Checks that package variables are not reassigned. - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. - staticcheck # It's a set of rules from staticcheck. + - testifylint # Checks usage of github.com/stretchr/testify. - testpackage # Linter that makes you use a separate _test package. + - thelper # Thelper detects tests helpers which do not start with the t.Helper() method. + - tparallel # Tparallel detects inappropriate usage of t.Parallel() method in your Go test codes. - unconvert # Remove unnecessary type conversions. - unused # Checks Go code for unused constants, variables, functions and types. - - usetesting # Reports uses of functions with replacement inside the testing package. - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. + - usetesting # Reports uses of functions with replacement inside the testing package. - wastedassign # Finds wasted assignment statements. + - whitespace # Checks for unnecessary newlines at the start and end of functions, if, for, etc. exclusions: rules: @@ -63,8 +79,47 @@ linters: linters: [ errcheck ] - path: (.+)_test\.go linters: [ gocognit, goconst, mnd ] + - text: 'assigned to ctx' + linters: [ wastedassign ] + - text: 'ctx is never used' + linters: [ staticcheck ] + + paths: + - \\.git$ + - assets$ + - bench(mark)?s?$ + - bin$ + - build$ + - configs?$ + - deploy(ment)?s?$ + - docs$ + - githooks$ + - scripts$ + + generated: strict settings: + depguard: + rules: + main: + list-mode: lax + deny: + - pkg: 'math/rand$' + desc: 'use math/rand/v2' + - pkg: 'github.com/pkg/errors' + desc: 'Should be replaced by standard lib errors package' + + dupword: + comments-only: true + + embeddedstructfieldcheck: + forbid-mutex: true + + errcheck: + exclude-functions: + - encoding/json.Marshal + - encoding/json.MarshalIndent + gocognit: min-complexity: 15 @@ -93,6 +148,7 @@ linters: - dupArg # Detects suspicious duplicated arguments. - dupBranchBody # Detects duplicated branch bodies inside conditional statements. - dupCase # Detects duplicated case clauses inside switch or select statements. + - dupOption # Detects duplicated option function arguments in variadic function calls. - dupSubExpr # Detects suspicious duplicated sub-expressions. - dynamicFmtString # Detects suspicious formatting strings usage. - emptyDecl # Detects suspicious empty declarations blocks. @@ -185,10 +241,14 @@ linters: - rangeValCopy # Detects loops that copy big objects during each iteration. - sliceClear # Detects slice clear loops, suggests an idiom that is recognized by the Go compiler. - stringXbytes # Detects redundant conversions between string and []byte. + - zeroByteRepeat # Detects bytes.Repeat with 0 value. goheader: template-path: ../.github/goheader.tmpl + gomoddirectives: + replace-local: true + gosec: excludes: # _ instead of err checks @@ -197,6 +257,18 @@ linters: govet: enable-all: true + iface: + enable: + - identical + - opaque + - unused + + inamedparam: + skip-single-param: true + + iotamixing: + report-individual: true + nakedret: max-func-lines: 10 @@ -209,33 +281,62 @@ linters: prealloc: range-loops: true + reassign: + patterns: + - '.*' + revive: severity: error rules: - - name: atomic # Check for commonly mistaken usages of the sync/atomic package. - - name: confusing-naming # Methods or fields of struct that have names different only by capitalization could be confusing. - - name: confusing-results # Function or methods that return multiple, no named, values of the same type could induce error. - - name: constant-logical-expr # The rule spots logical expressions that evaluate always to the same value. - - name: context-keys-type # Basic types should not be used as a key in context.WithValue. - - name: deep-exit # Packages exposing functions that can stop program execution by exiting are hard to reuse. This rule looks for program exits in functions other than main() or init(). - - name: early-return # In GO it is idiomatic to minimize nesting statements, a typical example is to avoid if-then-else constructions. - - name: empty-block # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. - - name: empty-lines # Sometimes gofmt is not enough to enforce a common formatting of a code-base; this rule warns when there are heading or trailing newlines in code blocks. - - name: error-return # By convention, for the sake of readability, the errors should be last in the list of returned values by a function. - - name: error-strings # By convention, for better readability, error messages should not be capitalized or end with punctuation or a newline. - - name: errorf # It is possible to get a simpler program by replacing errors.New(fmt.Sprintf()) with fmt.Errorf(). This rule spots that kind of simplification opportunities. - - name: identical-branches # An if-then-else conditional with identical implementations in both branches is an error. - - name: if-return # Checking if an error is nil to just after return the error or nil is redundant. - - name: increment-decrement # By convention, for better readability, incrementing an integer variable by 1 is recommended to be done using the ++ operator. This rule spots expressions like i += 1 and i -= 1 and proposes to change them into i++ and i--. - - name: range # This rule suggests a shorter way of writing ranges that do not use the second value. - - name: redefines-builtin-id # Constant names like false, true, nil, function names like append, make, and basic type names like bool, and byte are not reserved words of the language; therefore the can be redefined. Even if possible, redefining these built in names can lead to bugs very difficult to detect. - - name: redundant-build-tag # This rule warns about redundant build tag comments // +build when //go:build is present. gofmt in Go 1.17+ automatically adds the //go:build constraint, making the // +build comment unnecessary. - - name: string-of-int # Explicit type conversion string(i) where i has an integer type other than rune might behave not as expected by the developer (e.g. string(42) is not "42"). This rule spot that kind of suspicious conversions. - - name: use-any # Since Go 1.18, interface{} has an alias: any. This rule proposes to replace instances of interface{} with any. - - name: use-errors-new # This rules identifies calls to fmt.Errorf that can be safely replaced by, the more efficient, errors.New. - - name: unnecessary-stmt # This rule suggests to remove redundant statements like a break at the end of a case block, for improving the code's readability. - - name: unreachable-code # This rule spots and proposes to remove unreachable code. - - name: waitgroup-by-value # Function parameters that are passed by value, are in fact a copy of the original argument. Passing a copy of a sync.WaitGroup is usually not what the developer wants to do. This rule warns when a sync.WaitGroup expected as a by-value parameter in a function or method. + - name: atomic # Check for commonly mistaken usages of the sync/atomic package. + - name: confusing-naming # Methods or fields of struct that have names different only by capitalization could be confusing. + - name: confusing-results # Function or methods that return multiple, no named, values of the same type could induce error. + - name: constant-logical-expr # The rule spots logical expressions that evaluate always to the same value. + - name: context-as-argument # By convention, context.Context should be the first parameter of a function. This rule spots function declarations that do not follow the convention. + - name: context-keys-type # Basic types should not be used as a key in context.WithValue. + - name: deep-exit # Packages exposing functions that can stop program execution by exiting are hard to reuse. This rule looks for program exits in functions other than main() or init(). + - name: defer # This rule warns on some common mistakes when using defer statement. + arguments: + - - 'call-chain' + - 'loop' + - 'method-call' + - 'recover' + - 'immediate-recover' + - 'return' + - name: duplicated-imports # It is possible to unintentionally import the same package twice. This rule looks for packages that are imported two or more times. + - name: early-return # In GO it is idiomatic to minimize nesting statements, a typical example is to avoid if-then-else constructions. + - name: empty-block # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. + - name: empty-lines # Sometimes gofmt is not enough to enforce a common formatting of a code-base; this rule warns when there are heading or trailing newlines in code blocks. + - name: error-return # By convention, for the sake of readability, the errors should be last in the list of returned values by a function. + - name: error-strings # By convention, for better readability, error messages should not be capitalized or end with punctuation or a newline. + - name: errorf # It is possible to get a simpler program by replacing errors.New(fmt.Sprintf()) with fmt.Errorf(). This rule spots that kind of simplification opportunities. + - name: forbidden-call-in-wg-go # Warns on forbidden calls inside calls to wg.Go. + - name: identical-branches # An if-then-else conditional with identical implementations in both branches is an error. + - name: identical-ifelseif-branches # An if ... else if chain with identical branches makes maintenance harder and might be a source of bugs. Duplicated branches should be consolidated in one. + - name: identical-ifelseif-conditions # An if ... else if chain with identical conditions can lead to unreachable code and is a potential source of bugs while making the code harder to read and maintain. + - name: identical-switch-branches # A switch with identical branches makes maintenance harder and might be a source of bugs. Duplicated branches should be consolidated in one case clause. + - name: identical-switch-conditions # A switch statement with cases with the same condition can lead to unreachable code and is a potential source of bugs while making the code harder to read and maintain. + - name: if-return # Checking if an error is nil to just after return the error or nil is redundant. + - name: increment-decrement # By convention, for better readability, incrementing an integer variable by 1 is recommended to be done using the ++ operator. This rule spots expressions like i += 1 and i -= 1 and proposes to change them into i++ and i--. + - name: inefficient-map-lookup # This rule identifies code that iteratively searches for a key in a map. + - name: optimize-operands-order # Conditional expressions can be written to take advantage of short circuit evaluation and speed up its average evaluation time by forcing the evaluation of less time-consuming terms before more costly ones. This rule spots logical expressions where the order of evaluation of terms seems non optimal. + - name: range # This rule suggests a shorter way of writing ranges that do not use the second value. + - name: redefines-builtin-id # Constant names like false, true, nil, function names like append, make, and basic type names like bool, and byte are not reserved words of the language; therefore the can be redefined. Even if possible, redefining these built in names can lead to bugs very difficult to detect. + - name: redundant-build-tag # This rule warns about redundant build tag comments // +build when //go:build is present. gofmt in Go 1.17+ automatically adds the //go:build constraint, making the // +build comment unnecessary. + - name: string-of-int # Explicit type conversion string(i) where i has an integer type other than rune might behave not as expected by the developer (e.g. string(42) is not "42"). This rule spot that kind of suspicious conversions. + - name: unchecked-type-assertion # This rule checks whether a type assertion result is checked (the ok value), preventing unexpected panics. + arguments: + - accept-ignored-assertion-result: true + - name: use-any # Since Go 1.18, interface{} has an alias: any. This rule proposes to replace instances of interface{} with any. + - name: use-errors-new # This rules identifies calls to fmt.Errorf that can be safely replaced by, the more efficient, errors.New. + - name: use-fmt-print # This rule proposes to replace calls to built-in print and println with their equivalents from fmt standard package. + - name: use-waitgroup-go # Since Go 1.25 the sync package proposes the WaitGroup.Go method. This method is a shorter and safer replacement for the idiom wg.Add ... go { ... wg.Done ... }. + - name: useless-break # This rule warns on useless break statements in case clauses of switch and select statements. + - name: useless-fallthrough # This rule warns on useless fallthrough statements in case clauses of switch statements. A fallthrough is considered useless if it's the single statement of a case clause block. + - name: unnecessary-if # Identifies `if-else` statements that can be replaced by simpler statements. + - name: unnecessary-stmt # This rule suggests to remove redundant statements like a break at the end of a case block, for improving the code's readability. + - name: unreachable-code # This rule spots and proposes to remove unreachable code. + - name: waitgroup-by-value # Function parameters that are passed by value, are in fact a copy of the original argument. Passing a copy of a sync.WaitGroup is usually not what the developer wants to do. This rule warns when a sync.WaitGroup expected as a by-value parameter in a function or method. issues: max-issues-per-linter: 0 diff --git a/strcase/strcase.go b/strcase/strcase.go index 477e674..ed77c01 100644 --- a/strcase/strcase.go +++ b/strcase/strcase.go @@ -15,7 +15,9 @@ const ( CamelCase SnakeCase KebabCase +) +const ( // noSep is a special internal separator value for specific cases (e.g. flatcase) noSep = rune(0) // maxWordLength limits iterator over a string when looking for any separator From e6ed757884b148b2440e26568ec01c9790678d9a Mon Sep 17 00:00:00 2001 From: Alexander Menshchikov Date: Thu, 29 Oct 2026 16:02:13 +0300 Subject: [PATCH 8/9] Update sync golangci-lint config --- sync/.golangci.yml | 161 ++++++++++++++++++++++++++++++++++++--------- sync/once_test.go | 3 +- 2 files changed, 132 insertions(+), 32 deletions(-) diff --git a/sync/.golangci.yml b/sync/.golangci.yml index 64c8d28..d6bf931 100644 --- a/sync/.golangci.yml +++ b/sync/.golangci.yml @@ -20,51 +20,106 @@ formatters: linters: default: none enable: + - asasalint # Check for pass []any as any in variadic func(…any). - asciicheck # Checks that all code identifiers does not have non-ASCII symbols in the name. - bidichk # Checks for dangerous unicode character sequences. - - bodyclose # Checks whether HTTP response body is closed successfully. - - canonicalheader # Canonicalheader checks whether net/http.Header uses canonical header. + - containedctx # Containedctx is a linter that detects struct contained context.Context field. - contextcheck # Check whether the function uses a non-inherited context. - copyloopvar # Copyloopvar is a linter detects places where loop variables are copied. + - depguard # Go linter that checks if package imports are in a list of acceptable packages. + - dupword # Checks for duplicate words in the source code. - durationcheck # Check for two durations multiplied together. + - embeddedstructfieldcheck # Embedded types should be at the top of the field list of a struct, and there must be an empty line separating embedded fields from regular fields. - errcheck # Errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases. - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error. - errorlint # Errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. + - exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. + - fatcontext # Detects nested contexts in loops and function literals. + - forcetypeassert # Find forced type assertions. - funcorder # Checks the order of functions, methods, and constructors. - gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. - gocognit # Computes and checks the cognitive complexity of functions. - goconst # Finds repeated strings that could be replaced by a constant. - gocritic # Provides diagnostics that check for bugs, performance and style issues. - goheader # Checks if file header matches to pattern. + - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. - gosec # Inspects source code for security problems. - govet # Vet examines Go source code and reports suspicious constructs. - - ineffassign # Detects when assignments to existing variables are not used. + - iface # Detect the incorrect use of interfaces, helping developers avoid interface pollution. + - inamedparam # Reports interfaces with unnamed method parameters. + - intrange # Intrange is a linter to find places where for loops could make use of an integer range. + - iotamixing # Checks if iotas are being used in const blocks with other non-iota declarations. - makezero # Finds slice declarations with non-zero initial length. + - mirror # Reports wrong mirror patterns of bytes/strings usage. - mnd # An analyzer to detect magic numbers. + - modernize # A suite of analyzers that suggest simplifications to Go code, using modern language and library features. - nakedret # Checks that functions with naked returns are not longer than a maximum size (can be zero). - nilnil # Checks that there is no simultaneous return of nil error and an invalid value. - - noctx # Finds sending http request without context.Context. - nolintlint # Reports ill-formed or insufficient nolint directives. - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. - perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. - prealloc # Finds slice declarations that could potentially be pre-allocated. + - reassign # Checks that package variables are not reassigned. - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. - staticcheck # It's a set of rules from staticcheck. + - testifylint # Checks usage of github.com/stretchr/testify. - testpackage # Linter that makes you use a separate _test package. + - thelper # Thelper detects tests helpers which do not start with the t.Helper() method. + - tparallel # Tparallel detects inappropriate usage of t.Parallel() method in your Go test codes. - unconvert # Remove unnecessary type conversions. - unused # Checks Go code for unused constants, variables, functions and types. - - usetesting # Reports uses of functions with replacement inside the testing package. - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. + - usetesting # Reports uses of functions with replacement inside the testing package. - wastedassign # Finds wasted assignment statements. + - whitespace # Checks for unnecessary newlines at the start and end of functions, if, for, etc. exclusions: rules: - text: 'Error return value of .((os\.)?std(out|err)\..*|.*print(f|ln)?). is not checked' linters: [ errcheck ] - path: (.+)_test\.go - linters: [ gocognit, mnd ] + linters: [ gocognit, goconst, mnd ] + - text: 'assigned to ctx' + linters: [ wastedassign ] + - text: 'ctx is never used' + linters: [ staticcheck ] + + paths: + - \\.git$ + - assets$ + - bench(mark)?s?$ + - bin$ + - build$ + - configs?$ + - deploy(ment)?s?$ + - docs$ + - githooks$ + - scripts$ + + generated: strict settings: + depguard: + rules: + main: + list-mode: lax + deny: + - pkg: 'math/rand$' + desc: 'use math/rand/v2' + - pkg: 'github.com/pkg/errors' + desc: 'Should be replaced by standard lib errors package' + + dupword: + comments-only: true + + embeddedstructfieldcheck: + forbid-mutex: true + + errcheck: + exclude-functions: + - encoding/json.Marshal + - encoding/json.MarshalIndent + gocognit: min-complexity: 10 @@ -93,6 +148,7 @@ linters: - dupArg # Detects suspicious duplicated arguments. - dupBranchBody # Detects duplicated branch bodies inside conditional statements. - dupCase # Detects duplicated case clauses inside switch or select statements. + - dupOption # Detects duplicated option function arguments in variadic function calls. - dupSubExpr # Detects suspicious duplicated sub-expressions. - dynamicFmtString # Detects suspicious formatting strings usage. - emptyDecl # Detects suspicious empty declarations blocks. @@ -185,10 +241,14 @@ linters: - rangeValCopy # Detects loops that copy big objects during each iteration. - sliceClear # Detects slice clear loops, suggests an idiom that is recognized by the Go compiler. - stringXbytes # Detects redundant conversions between string and []byte. + - zeroByteRepeat # Detects bytes.Repeat with 0 value. goheader: template-path: ../.github/goheader.tmpl + gomoddirectives: + replace-local: true + gosec: excludes: # _ instead of err checks @@ -197,6 +257,18 @@ linters: govet: enable-all: true + iface: + enable: + - identical + - opaque + - unused + + inamedparam: + skip-single-param: true + + iotamixing: + report-individual: true + nakedret: max-func-lines: 10 @@ -209,33 +281,62 @@ linters: prealloc: range-loops: true + reassign: + patterns: + - '.*' + revive: severity: error rules: - - name: atomic # Check for commonly mistaken usages of the sync/atomic package. - - name: confusing-naming # Methods or fields of struct that have names different only by capitalization could be confusing. - - name: confusing-results # Function or methods that return multiple, no named, values of the same type could induce error. - - name: constant-logical-expr # The rule spots logical expressions that evaluate always to the same value. - - name: context-keys-type # Basic types should not be used as a key in context.WithValue. - - name: deep-exit # Packages exposing functions that can stop program execution by exiting are hard to reuse. This rule looks for program exits in functions other than main() or init(). - - name: early-return # In GO it is idiomatic to minimize nesting statements, a typical example is to avoid if-then-else constructions. - - name: empty-block # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. - - name: empty-lines # Sometimes gofmt is not enough to enforce a common formatting of a code-base; this rule warns when there are heading or trailing newlines in code blocks. - - name: error-return # By convention, for the sake of readability, the errors should be last in the list of returned values by a function. - - name: error-strings # By convention, for better readability, error messages should not be capitalized or end with punctuation or a newline. - - name: errorf # It is possible to get a simpler program by replacing errors.New(fmt.Sprintf()) with fmt.Errorf(). This rule spots that kind of simplification opportunities. - - name: identical-branches # An if-then-else conditional with identical implementations in both branches is an error. - - name: if-return # Checking if an error is nil to just after return the error or nil is redundant. - - name: increment-decrement # By convention, for better readability, incrementing an integer variable by 1 is recommended to be done using the ++ operator. This rule spots expressions like i += 1 and i -= 1 and proposes to change them into i++ and i--. - - name: range # This rule suggests a shorter way of writing ranges that do not use the second value. - - name: redefines-builtin-id # Constant names like false, true, nil, function names like append, make, and basic type names like bool, and byte are not reserved words of the language; therefore the can be redefined. Even if possible, redefining these built in names can lead to bugs very difficult to detect. - - name: redundant-build-tag # This rule warns about redundant build tag comments // +build when //go:build is present. gofmt in Go 1.17+ automatically adds the //go:build constraint, making the // +build comment unnecessary. - - name: string-of-int # Explicit type conversion string(i) where i has an integer type other than rune might behave not as expected by the developer (e.g. string(42) is not "42"). This rule spot that kind of suspicious conversions. - - name: use-any # Since Go 1.18, interface{} has an alias: any. This rule proposes to replace instances of interface{} with any. - - name: use-errors-new # This rules identifies calls to fmt.Errorf that can be safely replaced by, the more efficient, errors.New. - - name: unnecessary-stmt # This rule suggests to remove redundant statements like a break at the end of a case block, for improving the code's readability. - - name: unreachable-code # This rule spots and proposes to remove unreachable code. - - name: waitgroup-by-value # Function parameters that are passed by value, are in fact a copy of the original argument. Passing a copy of a sync.WaitGroup is usually not what the developer wants to do. This rule warns when a sync.WaitGroup expected as a by-value parameter in a function or method. + - name: atomic # Check for commonly mistaken usages of the sync/atomic package. + - name: confusing-naming # Methods or fields of struct that have names different only by capitalization could be confusing. + - name: confusing-results # Function or methods that return multiple, no named, values of the same type could induce error. + - name: constant-logical-expr # The rule spots logical expressions that evaluate always to the same value. + - name: context-as-argument # By convention, context.Context should be the first parameter of a function. This rule spots function declarations that do not follow the convention. + - name: context-keys-type # Basic types should not be used as a key in context.WithValue. + - name: deep-exit # Packages exposing functions that can stop program execution by exiting are hard to reuse. This rule looks for program exits in functions other than main() or init(). + - name: defer # This rule warns on some common mistakes when using defer statement. + arguments: + - - 'call-chain' + - 'loop' + - 'method-call' + - 'recover' + - 'immediate-recover' + - 'return' + - name: duplicated-imports # It is possible to unintentionally import the same package twice. This rule looks for packages that are imported two or more times. + - name: early-return # In GO it is idiomatic to minimize nesting statements, a typical example is to avoid if-then-else constructions. + - name: empty-block # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. + - name: empty-lines # Sometimes gofmt is not enough to enforce a common formatting of a code-base; this rule warns when there are heading or trailing newlines in code blocks. + - name: error-return # By convention, for the sake of readability, the errors should be last in the list of returned values by a function. + - name: error-strings # By convention, for better readability, error messages should not be capitalized or end with punctuation or a newline. + - name: errorf # It is possible to get a simpler program by replacing errors.New(fmt.Sprintf()) with fmt.Errorf(). This rule spots that kind of simplification opportunities. + - name: forbidden-call-in-wg-go # Warns on forbidden calls inside calls to wg.Go. + - name: identical-branches # An if-then-else conditional with identical implementations in both branches is an error. + - name: identical-ifelseif-branches # An if ... else if chain with identical branches makes maintenance harder and might be a source of bugs. Duplicated branches should be consolidated in one. + - name: identical-ifelseif-conditions # An if ... else if chain with identical conditions can lead to unreachable code and is a potential source of bugs while making the code harder to read and maintain. + - name: identical-switch-branches # A switch with identical branches makes maintenance harder and might be a source of bugs. Duplicated branches should be consolidated in one case clause. + - name: identical-switch-conditions # A switch statement with cases with the same condition can lead to unreachable code and is a potential source of bugs while making the code harder to read and maintain. + - name: if-return # Checking if an error is nil to just after return the error or nil is redundant. + - name: increment-decrement # By convention, for better readability, incrementing an integer variable by 1 is recommended to be done using the ++ operator. This rule spots expressions like i += 1 and i -= 1 and proposes to change them into i++ and i--. + - name: inefficient-map-lookup # This rule identifies code that iteratively searches for a key in a map. + - name: optimize-operands-order # Conditional expressions can be written to take advantage of short circuit evaluation and speed up its average evaluation time by forcing the evaluation of less time-consuming terms before more costly ones. This rule spots logical expressions where the order of evaluation of terms seems non optimal. + - name: range # This rule suggests a shorter way of writing ranges that do not use the second value. + - name: redefines-builtin-id # Constant names like false, true, nil, function names like append, make, and basic type names like bool, and byte are not reserved words of the language; therefore the can be redefined. Even if possible, redefining these built in names can lead to bugs very difficult to detect. + - name: redundant-build-tag # This rule warns about redundant build tag comments // +build when //go:build is present. gofmt in Go 1.17+ automatically adds the //go:build constraint, making the // +build comment unnecessary. + - name: string-of-int # Explicit type conversion string(i) where i has an integer type other than rune might behave not as expected by the developer (e.g. string(42) is not "42"). This rule spot that kind of suspicious conversions. + - name: unchecked-type-assertion # This rule checks whether a type assertion result is checked (the ok value), preventing unexpected panics. + arguments: + - accept-ignored-assertion-result: true + - name: use-any # Since Go 1.18, interface{} has an alias: any. This rule proposes to replace instances of interface{} with any. + - name: use-errors-new # This rules identifies calls to fmt.Errorf that can be safely replaced by, the more efficient, errors.New. + - name: use-fmt-print # This rule proposes to replace calls to built-in print and println with their equivalents from fmt standard package. + - name: use-waitgroup-go # Since Go 1.25 the sync package proposes the WaitGroup.Go method. This method is a shorter and safer replacement for the idiom wg.Add ... go { ... wg.Done ... }. + - name: useless-break # This rule warns on useless break statements in case clauses of switch and select statements. + - name: useless-fallthrough # This rule warns on useless fallthrough statements in case clauses of switch statements. A fallthrough is considered useless if it's the single statement of a case clause block. + - name: unnecessary-if # Identifies `if-else` statements that can be replaced by simpler statements. + - name: unnecessary-stmt # This rule suggests to remove redundant statements like a break at the end of a case block, for improving the code's readability. + - name: unreachable-code # This rule spots and proposes to remove unreachable code. + - name: waitgroup-by-value # Function parameters that are passed by value, are in fact a copy of the original argument. Passing a copy of a sync.WaitGroup is usually not what the developer wants to do. This rule warns when a sync.WaitGroup expected as a by-value parameter in a function or method. issues: max-issues-per-linter: 0 diff --git a/sync/once_test.go b/sync/once_test.go index 8043281..ff572b4 100644 --- a/sync/once_test.go +++ b/sync/once_test.go @@ -3,7 +3,6 @@ package sync_test import ( - "errors" "fmt" "sync" "sync/atomic" @@ -64,7 +63,7 @@ func TestSuccessfulOnce_Do(t *testing.T) { assert.Len(t, errs, int(attemptCounter-1)) for err := range errs { attempt := attemptError{} - require.True(t, errors.As(err, &attempt)) + require.ErrorAs(t, err, &attempt) assert.LessOrEqual(t, attempt.Cnt, successAt-1) } } From 98d49b7ac19e9382da646e22d974b4e24ba799ce Mon Sep 17 00:00:00 2001 From: Alexander Menshchikov Date: Thu, 29 Oct 2026 16:02:13 +0300 Subject: [PATCH 9/9] Update time golangci-lint config --- time/.golangci.yml | 165 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 137 insertions(+), 28 deletions(-) diff --git a/time/.golangci.yml b/time/.golangci.yml index e006069..2837ccc 100644 --- a/time/.golangci.yml +++ b/time/.golangci.yml @@ -20,41 +20,60 @@ formatters: linters: default: none enable: + - asasalint # Check for pass []any as any in variadic func(…any). - asciicheck # Checks that all code identifiers does not have non-ASCII symbols in the name. - bidichk # Checks for dangerous unicode character sequences. - - bodyclose # Checks whether HTTP response body is closed successfully. - - canonicalheader # Canonicalheader checks whether net/http.Header uses canonical header. + - containedctx # Containedctx is a linter that detects struct contained context.Context field. - contextcheck # Check whether the function uses a non-inherited context. + - copyloopvar # Copyloopvar is a linter detects places where loop variables are copied. + - depguard # Go linter that checks if package imports are in a list of acceptable packages. + - dupword # Checks for duplicate words in the source code. - durationcheck # Check for two durations multiplied together. + - embeddedstructfieldcheck # Embedded types should be at the top of the field list of a struct, and there must be an empty line separating embedded fields from regular fields. - errcheck # Errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases. + - errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and reports occurrences where the check for the returned error can be omitted. - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error. - errorlint # Errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. + - exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. + - fatcontext # Detects nested contexts in loops and function literals. + - forcetypeassert # Find forced type assertions. - funcorder # Checks the order of functions, methods, and constructors. - gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. - gocognit # Computes and checks the cognitive complexity of functions. - goconst # Finds repeated strings that could be replaced by a constant. - gocritic # Provides diagnostics that check for bugs, performance and style issues. - goheader # Checks if file header matches to pattern. + - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. - gosec # Inspects source code for security problems. - govet # Vet examines Go source code and reports suspicious constructs. - - ineffassign # Detects when assignments to existing variables are not used. + - iface # Detect the incorrect use of interfaces, helping developers avoid interface pollution. + - inamedparam # Reports interfaces with unnamed method parameters. + - intrange # Intrange is a linter to find places where for loops could make use of an integer range. + - iotamixing # Checks if iotas are being used in const blocks with other non-iota declarations. - makezero # Finds slice declarations with non-zero initial length. + - mirror # Reports wrong mirror patterns of bytes/strings usage. - mnd # An analyzer to detect magic numbers. + - modernize # A suite of analyzers that suggest simplifications to Go code, using modern language and library features. + - musttag # Enforce field tags in (un)marshaled structs. - nakedret # Checks that functions with naked returns are not longer than a maximum size (can be zero). - nilnil # Checks that there is no simultaneous return of nil error and an invalid value. - - noctx # Finds sending http request without context.Context. - nolintlint # Reports ill-formed or insufficient nolint directives. - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. - perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. - prealloc # Finds slice declarations that could potentially be pre-allocated. + - reassign # Checks that package variables are not reassigned. - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. - staticcheck # It's a set of rules from staticcheck. + - testifylint # Checks usage of github.com/stretchr/testify. - testpackage # Linter that makes you use a separate _test package. + - thelper # Thelper detects tests helpers which do not start with the t.Helper() method. + - tparallel # Tparallel detects inappropriate usage of t.Parallel() method in your Go test codes. - unconvert # Remove unnecessary type conversions. - unused # Checks Go code for unused constants, variables, functions and types. - - usetesting # Reports uses of functions with replacement inside the testing package. - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. + - usetesting # Reports uses of functions with replacement inside the testing package. - wastedassign # Finds wasted assignment statements. + - whitespace # Checks for unnecessary newlines at the start and end of functions, if, for, etc. exclusions: rules: @@ -62,8 +81,51 @@ linters: linters: [ errcheck ] - path: (.+)_test\.go linters: [ gocognit, goconst, mnd ] + - text: 'assigned to ctx' + linters: [ wastedassign ] + - text: 'ctx is never used' + linters: [ staticcheck ] + + paths: + - \\.git$ + - assets$ + - bench(mark)?s?$ + - bin$ + - build$ + - configs?$ + - deploy(ment)?s?$ + - docs$ + - githooks$ + - scripts$ + + generated: strict settings: + depguard: + rules: + main: + list-mode: lax + deny: + - pkg: 'math/rand$' + desc: 'use math/rand/v2' + - pkg: 'github.com/pkg/errors' + desc: 'Should be replaced by standard lib errors package' + + dupword: + comments-only: true + + embeddedstructfieldcheck: + forbid-mutex: true + + errcheck: + exclude-functions: + - encoding/json.Marshal + - encoding/json.MarshalIndent + + errchkjson: + check-error-free-encoding: true + report-no-exported: true + gocognit: min-complexity: 10 @@ -92,6 +154,7 @@ linters: - dupArg # Detects suspicious duplicated arguments. - dupBranchBody # Detects duplicated branch bodies inside conditional statements. - dupCase # Detects duplicated case clauses inside switch or select statements. + - dupOption # Detects duplicated option function arguments in variadic function calls. - dupSubExpr # Detects suspicious duplicated sub-expressions. - dynamicFmtString # Detects suspicious formatting strings usage. - emptyDecl # Detects suspicious empty declarations blocks. @@ -184,10 +247,14 @@ linters: - rangeValCopy # Detects loops that copy big objects during each iteration. - sliceClear # Detects slice clear loops, suggests an idiom that is recognized by the Go compiler. - stringXbytes # Detects redundant conversions between string and []byte. + - zeroByteRepeat # Detects bytes.Repeat with 0 value. goheader: template-path: ../.github/goheader.tmpl + gomoddirectives: + replace-local: true + gosec: excludes: # _ instead of err checks @@ -196,6 +263,18 @@ linters: govet: enable-all: true + iface: + enable: + - identical + - opaque + - unused + + inamedparam: + skip-single-param: true + + iotamixing: + report-individual: true + nakedret: max-func-lines: 10 @@ -208,32 +287,62 @@ linters: prealloc: range-loops: true + reassign: + patterns: + - '.*' + revive: severity: error rules: - - name: atomic # Check for commonly mistaken usages of the sync/atomic package. - - name: confusing-naming # Methods or fields of struct that have names different only by capitalization could be confusing. - - name: confusing-results # Function or methods that return multiple, no named, values of the same type could induce error. - - name: constant-logical-expr # The rule spots logical expressions that evaluate always to the same value. - - name: context-keys-type # Basic types should not be used as a key in context.WithValue. - - name: deep-exit # Packages exposing functions that can stop program execution by exiting are hard to reuse. This rule looks for program exits in functions other than main() or init(). - - name: early-return # In GO it is idiomatic to minimize nesting statements, a typical example is to avoid if-then-else constructions. - - name: empty-block # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. - - name: empty-lines # Sometimes gofmt is not enough to enforce a common formatting of a code-base; this rule warns when there are heading or trailing newlines in code blocks. - - name: error-return # By convention, for the sake of readability, the errors should be last in the list of returned values by a function. - - name: error-strings # By convention, for better readability, error messages should not be capitalized or end with punctuation or a newline. - - name: errorf # It is possible to get a simpler program by replacing errors.New(fmt.Sprintf()) with fmt.Errorf(). This rule spots that kind of simplification opportunities. - - name: identical-branches # An if-then-else conditional with identical implementations in both branches is an error. - - name: if-return # Checking if an error is nil to just after return the error or nil is redundant. - - name: increment-decrement # By convention, for better readability, incrementing an integer variable by 1 is recommended to be done using the ++ operator. This rule spots expressions like i += 1 and i -= 1 and proposes to change them into i++ and i--. - - name: range # This rule suggests a shorter way of writing ranges that do not use the second value. - - name: redefines-builtin-id # Constant names like false, true, nil, function names like append, make, and basic type names like bool, and byte are not reserved words of the language; therefore the can be redefined. Even if possible, redefining these built in names can lead to bugs very difficult to detect. - - name: redundant-build-tag # This rule warns about redundant build tag comments // +build when //go:build is present. gofmt in Go 1.17+ automatically adds the //go:build constraint, making the // +build comment unnecessary. - - name: string-of-int # Explicit type conversion string(i) where i has an integer type other than rune might behave not as expected by the developer (e.g. string(42) is not "42"). This rule spot that kind of suspicious conversions. - - name: use-errors-new # This rules identifies calls to fmt.Errorf that can be safely replaced by, the more efficient, errors.New. - - name: unnecessary-stmt # This rule suggests to remove redundant statements like a break at the end of a case block, for improving the code's readability. - - name: unreachable-code # This rule spots and proposes to remove unreachable code. - - name: waitgroup-by-value # Function parameters that are passed by value, are in fact a copy of the original argument. Passing a copy of a sync.WaitGroup is usually not what the developer wants to do. This rule warns when a sync.WaitGroup expected as a by-value parameter in a function or method. + - name: atomic # Check for commonly mistaken usages of the sync/atomic package. + - name: confusing-naming # Methods or fields of struct that have names different only by capitalization could be confusing. + - name: confusing-results # Function or methods that return multiple, no named, values of the same type could induce error. + - name: constant-logical-expr # The rule spots logical expressions that evaluate always to the same value. + - name: context-as-argument # By convention, context.Context should be the first parameter of a function. This rule spots function declarations that do not follow the convention. + - name: context-keys-type # Basic types should not be used as a key in context.WithValue. + - name: deep-exit # Packages exposing functions that can stop program execution by exiting are hard to reuse. This rule looks for program exits in functions other than main() or init(). + - name: defer # This rule warns on some common mistakes when using defer statement. + arguments: + - - 'call-chain' + - 'loop' + - 'method-call' + - 'recover' + - 'immediate-recover' + - 'return' + - name: duplicated-imports # It is possible to unintentionally import the same package twice. This rule looks for packages that are imported two or more times. + - name: early-return # In GO it is idiomatic to minimize nesting statements, a typical example is to avoid if-then-else constructions. + - name: empty-block # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. + - name: empty-lines # Sometimes gofmt is not enough to enforce a common formatting of a code-base; this rule warns when there are heading or trailing newlines in code blocks. + - name: error-return # By convention, for the sake of readability, the errors should be last in the list of returned values by a function. + - name: error-strings # By convention, for better readability, error messages should not be capitalized or end with punctuation or a newline. + - name: errorf # It is possible to get a simpler program by replacing errors.New(fmt.Sprintf()) with fmt.Errorf(). This rule spots that kind of simplification opportunities. + - name: forbidden-call-in-wg-go # Warns on forbidden calls inside calls to wg.Go. + - name: identical-branches # An if-then-else conditional with identical implementations in both branches is an error. + - name: identical-ifelseif-branches # An if ... else if chain with identical branches makes maintenance harder and might be a source of bugs. Duplicated branches should be consolidated in one. + - name: identical-ifelseif-conditions # An if ... else if chain with identical conditions can lead to unreachable code and is a potential source of bugs while making the code harder to read and maintain. + - name: identical-switch-branches # A switch with identical branches makes maintenance harder and might be a source of bugs. Duplicated branches should be consolidated in one case clause. + - name: identical-switch-conditions # A switch statement with cases with the same condition can lead to unreachable code and is a potential source of bugs while making the code harder to read and maintain. + - name: if-return # Checking if an error is nil to just after return the error or nil is redundant. + - name: increment-decrement # By convention, for better readability, incrementing an integer variable by 1 is recommended to be done using the ++ operator. This rule spots expressions like i += 1 and i -= 1 and proposes to change them into i++ and i--. + - name: inefficient-map-lookup # This rule identifies code that iteratively searches for a key in a map. + - name: optimize-operands-order # Conditional expressions can be written to take advantage of short circuit evaluation and speed up its average evaluation time by forcing the evaluation of less time-consuming terms before more costly ones. This rule spots logical expressions where the order of evaluation of terms seems non optimal. + - name: range # This rule suggests a shorter way of writing ranges that do not use the second value. + - name: redefines-builtin-id # Constant names like false, true, nil, function names like append, make, and basic type names like bool, and byte are not reserved words of the language; therefore the can be redefined. Even if possible, redefining these built in names can lead to bugs very difficult to detect. + - name: redundant-build-tag # This rule warns about redundant build tag comments // +build when //go:build is present. gofmt in Go 1.17+ automatically adds the //go:build constraint, making the // +build comment unnecessary. + - name: string-of-int # Explicit type conversion string(i) where i has an integer type other than rune might behave not as expected by the developer (e.g. string(42) is not "42"). This rule spot that kind of suspicious conversions. + - name: unchecked-type-assertion # This rule checks whether a type assertion result is checked (the ok value), preventing unexpected panics. + arguments: + - accept-ignored-assertion-result: true + - name: use-any # Since Go 1.18, interface{} has an alias: any. This rule proposes to replace instances of interface{} with any. + - name: use-errors-new # This rules identifies calls to fmt.Errorf that can be safely replaced by, the more efficient, errors.New. + - name: use-fmt-print # This rule proposes to replace calls to built-in print and println with their equivalents from fmt standard package. + - name: use-waitgroup-go # Since Go 1.25 the sync package proposes the WaitGroup.Go method. This method is a shorter and safer replacement for the idiom wg.Add ... go { ... wg.Done ... }. + - name: useless-break # This rule warns on useless break statements in case clauses of switch and select statements. + - name: useless-fallthrough # This rule warns on useless fallthrough statements in case clauses of switch statements. A fallthrough is considered useless if it's the single statement of a case clause block. + - name: unnecessary-if # Identifies `if-else` statements that can be replaced by simpler statements. + - name: unnecessary-stmt # This rule suggests to remove redundant statements like a break at the end of a case block, for improving the code's readability. + - name: unreachable-code # This rule spots and proposes to remove unreachable code. + - name: waitgroup-by-value # Function parameters that are passed by value, are in fact a copy of the original argument. Passing a copy of a sync.WaitGroup is usually not what the developer wants to do. This rule warns when a sync.WaitGroup expected as a by-value parameter in a function or method. issues: max-issues-per-linter: 0