Skip to content

Commit

Permalink
chore(lint): Update golangci-lint config (#1174)
Browse files Browse the repository at this point in the history
* buimop

* bet

* weird

* x

* x

* bet
  • Loading branch information
itsdevbear authored May 24, 2024
1 parent 73ab6bf commit 0bd5c01
Show file tree
Hide file tree
Showing 38 changed files with 155 additions and 105 deletions.
100 changes: 60 additions & 40 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This code is licensed under the terms of the MIT license https://opensource.org/license/mit
# Copyright (c) 2021 Marat Reymers

## Golden config for golangci-lint v1.57.2
## Golden config for golangci-lint v1.58.2
#
# This is the best config for golangci-lint based on my experience and opinion.
# It is very strict, but not extremely strict.
Expand All @@ -12,6 +12,7 @@ run:
# Default: 1m
timeout: 3m


# This file contains only configs which differ from defaults.
# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
linters-settings:
Expand Down Expand Up @@ -40,7 +41,7 @@ linters-settings:
# even if all enum members are not listed.
# Default: false
default-signifies-exhaustive: true

exhaustruct:
# List of regular expressions to exclude struct packages and their names from checks.
# Regular expressions must match complete canonical struct package/name/structname.
Expand Down Expand Up @@ -102,26 +103,6 @@ linters-settings:
# Default: true
skipRecvDeref: false

mnd:
# List of function patterns to exclude from analysis.
# Values always ignored: `time.Date`,
# `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
# `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`.
# Default: []
ignored-functions:
- flag.Arg
- flag.Duration.*
- flag.Float.*
- flag.Int.*
- flag.Uint.*
- os.Chmod
- os.Mkdir.*
- os.OpenFile
- os.WriteFile
- prometheus.ExponentialBuckets.*
- prometheus.LinearBuckets
- ssz.*

gomodguard:
blocked:
# List of blocked modules.
Expand Down Expand Up @@ -156,6 +137,11 @@ linters-settings:
# Default: false
strict: true

inamedparam:
# Skips check for interface methods with only a single parameter.
# Default: false
skip-single-param: true

lll:
# Max line length, lines longer will be reported.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option.
Expand All @@ -165,10 +151,25 @@ linters-settings:
# Default: 1
tab-width: 1

inamedparam:
# Skips check for interface methods with only a single parameter.
# Default: false
skip-single-param: true
mnd:
# List of function patterns to exclude from analysis.
# Values always ignored: `time.Date`,
# `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
# `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`.
# Default: []
ignored-functions:
- args.Error
- flag.Arg
- flag.Duration.*
- flag.Float.*
- flag.Int.*
- flag.Uint.*
- os.Chmod
- os.Mkdir.*
- os.OpenFile
- os.WriteFile
- prometheus.ExponentialBuckets.*
- prometheus.LinearBuckets

nakedret:
# Make an issue if func has more lines of code than this setting, and it has naked returns.
Expand All @@ -178,15 +179,13 @@ linters-settings:
nolintlint:
# Exclude following linters from requiring an explanation.
# Default: []
allow-no-explanation: [funlen, gocognit, lll]
allow-no-explanation: [ funlen, gocognit, lll ]
# Enable to require an explanation of nonzero length after each nolint directive.
# Default: false
require-explanation: true
# Enable to require nolint directives to mention the specific linter being suppressed.
# Default: false
require-specific: true
# Enable to ensure that nolint directives are all used. Default is true.
allow-unused: true

perfsprint:
# Optimizes into strings concatenation.
Expand All @@ -199,29 +198,47 @@ linters-settings:
packages:
- github.com/jmoiron/sqlx

sloglint:
# Enforce not using global loggers.
# Values:
# - "": disabled
# - "all": report all global loggers
# - "default": report only the default slog logger
# Default: ""
no-global: "all"
# Enforce using methods that accept a context.
# Values:
# - "": disabled
# - "all": report all contextless calls
# - "scope": report only if a context exists in the scope of the outermost function
# Default: ""
context: "scope"

tenv:
# The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
# Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
# Default: false
all: true


linters:
disable-all: true
enable:
# # enabled by default
## enabled by default
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
- gosimple # specializes in simplifying a code
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ineffassign # detects when assignments to existing variables are not used
# TODO: Requires fixing due to bug in lib, not included in latest release.
# bug in library that needs to be resolved.
# - staticcheck # is a go vet on steroids, applying a ton of static analysis checks
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
- unused # checks for unused constants, variables, functions and types
# ## disabled by default
## disabled by default
- asasalint # checks for pass []any as any in variadic func(...any)
- asciicheck # checks that your code does not contain non-ASCII identifiers
- bidichk # checks for dangerous unicode character sequences
- bodyclose # checks whether HTTP response body is closed successfully
- canonicalheader # checks whether net/http.Header uses canonical header
- copyloopvar # detects places where loop variables are copied
- cyclop # checks function and package cyclomatic complexity
- dupl # tool for code clone detection
Expand All @@ -230,19 +247,19 @@ linters:
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
- exhaustive # checks exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
- fatcontext # detects nested contexts in loops
- forbidigo # forbids identifiers
- funlen # tool for detection of long functions
- gocheckcompilerdirectives # validates go compiler directive comments (//go:)
- gochecknoglobals # checks that no global variables exist
- gochecknoinits # checks that no init functions are present in Go code
- gochecksumtype # checks exhaustiveness on Go "sum types"
- gocognit # computes and checks the cognitive complexity of functions
# - goconst # finds repeated strings that could be replaced by a constant
- goconst # finds repeated strings that could be replaced by a constant
- gocritic # provides diagnostics that check for bugs, performance and style issues
- gocyclo # computes and checks the cyclomatic complexity of functions
- godot # checks if comments end in a period
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
- mnd # detects magic numbers
# - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
- gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
- goprintffuncname # checks that printf-like functions are named with f at the end
Expand All @@ -252,6 +269,7 @@ linters:
- loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
- makezero # finds slice declarations with non-zero initial length
- mirror # reports wrong mirror patterns of bytes/strings usage
- mnd # detects magic numbers
- musttag # enforces field tags in (un)marshaled structs
- nakedret # finds naked returns in functions greater than a specified function length
- nestif # reports deeply nested if statements
Expand Down Expand Up @@ -304,10 +322,11 @@ linters:
- contextcheck # [too many false positives] checks the function whether use a non-inherited context
#- depguard # [replaced by gomodguard] checks if package imports are in a list of acceptable packages
- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
- dupword # [useless without config] checks for duplicate words in the source code
#- dupword # [useless without config] checks for duplicate words in the source code
#- err113 # [too strict] checks the errors handling expressions
#- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/errchkjson] checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted
#- execinquery # [deprecated] checks query string in Query function which reads your Go src files and warning it finds
#- forcetypeassert # [replaced by errcheck] finds forced type assertions
#- goerr113 # [too strict] checks the errors handling expressions
#- gofmt # [replaced by goimports] checks whether code was gofmt-ed
#- gofumpt # [replaced by goimports, gofumports is not available yet] checks whether code was gofumpt-ed
- gosmopolitan # reports certain i18n/l10n anti-patterns in your Go codebase
Expand All @@ -318,9 +337,10 @@ linters:
#- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity
#- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test
- tagliatelle # checks the struct tags
#- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers
- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers
#- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines


issues:
# Maximum count of issues with the same text.
# Set to 0 to disable.
Expand All @@ -329,9 +349,9 @@ issues:

exclude-rules:
- source: "(noinspection|TODO)"
linters: [godot]
linters: [ godot ]
- source: "//noinspection"
linters: [gocritic]
linters: [ gocritic ]
- path: "_test\\.go"
linters:
- bodyclose
Expand All @@ -340,4 +360,4 @@ issues:
- goconst
- gosec
- noctx
- wrapcheck
- wrapcheck
1 change: 1 addition & 0 deletions beacond/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func run() error {
// main is the entry point.
func main() {
if err := run(); err != nil {
//nolint:sloglint // todo fix.
slog.Error("startup failure", "error", err)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion mod/beacon/blockchain/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *Service[
// ProcessStateTransition receives an incoming beacon block, it first validates
// and then processes the block.
//
//nolint:funlen // todo cleanup.

func (s *Service[
AvailabilityStoreT,
ReadOnlyBeaconStateT,
Expand Down
2 changes: 1 addition & 1 deletion mod/consensus-types/pkg/state/deneb/deneb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
//nolint:errcheck // do not check for err returns

package deneb_test

import (
Expand Down
2 changes: 1 addition & 1 deletion mod/consensus-types/pkg/types/payload_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
)

//
//nolint:lll // long variable names.

var _ engineprimitives.ExecutionPayloadHeader = (*ExecutionPayloadHeaderDeneb)(
nil,
)
Expand Down
10 changes: 6 additions & 4 deletions mod/da/pkg/kzg/ckzg/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ func setupVerifier() (*ckzg.Verifier, error) {

func setupTestData(t *testing.T, fileName string) (
*eip4844.Blob, eip4844.KZGProof, eip4844.KZGCommitment) {
t.Helper()

filePath := filepath.Join(baseDir, fileName)
data, err := afero.ReadFile(afero.NewOsFs(), filePath)
require.NoError(t, err)

type Test struct {
Input struct {
Blob string `json:"blob"`
Expand All @@ -98,13 +101,12 @@ func setupTestData(t *testing.T, fileName string) (
require.NoError(t, errBlob)

var commitment eip4844.KZGCommitment

errCommitment := commitment.UnmarshalJSON([]byte(
`"` + test.Input.Commitment + `"`))
errCommitment := commitment.UnmarshalJSON(
[]byte(`"` + test.Input.Commitment + `"`),
)
require.NoError(t, errCommitment)

var proof eip4844.KZGProof

errProof := proof.UnmarshalJSON([]byte(`"` + test.Input.Proof + `"`))
require.NoError(t, errProof)

Expand Down
5 changes: 4 additions & 1 deletion mod/da/pkg/kzg/gokzg/gokzg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ func setupVerifier() (*gokzg.Verifier, error) {
}

func setupTestData(t *testing.T, fileName string) (
*eip4844.Blob, eip4844.KZGProof, eip4844.KZGCommitment) {
*eip4844.Blob, eip4844.KZGProof, eip4844.KZGCommitment,
) {
t.Helper()

filePath := filepath.Join(baseDir, fileName)
data, err := afero.ReadFile(afero.NewOsFs(), filePath)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion mod/da/pkg/types/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
// BlobSidecar as per the Ethereum 2.0 specification:
// https://github.com/ethereum/consensus-specs/blob/dev/specs/deneb/p2p-interface.md?ref=bankless.ghost.io#blobsidecar
//
//nolint:lll
//nolint:lll // link.
//go:generate go run github.com/ferranbt/fastssz/sszgen -path ./sidecar.go -objs BlobSidecar -include ../../../primitives/pkg/bytes,../../../consensus-types/pkg/types,../../../primitives/pkg/math,../../../primitives/mod.go,../../../primitives/pkg/eip4844,$GETH_PKG_INCLUDE/common,$GETH_PKG_INCLUDE/common/hexutil -output sidecar.ssz.go
type BlobSidecar struct {
// Index represents the index of the blob in the block.
Expand Down
2 changes: 1 addition & 1 deletion mod/execution/pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (s *EngineClient[ExecutionPayloadDenebT]) Name() string {
// ================================ IPC ================================

//
//nolint:lll // long line length due to struct tags.

func (s *EngineClient[ExecutionPayloadDenebT]) startIPCServer(
ctx context.Context,
) {
Expand Down
13 changes: 7 additions & 6 deletions mod/node-builder/pkg/commands/jwt/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,16 @@ func Test_NewGenerateJWTCommand(t *testing.T) {
})
}

func checkAuthFileIntegrity(t testing.TB, fPath string) {
func checkAuthFileIntegrity(tb testing.TB, fPath string) {
tb.Helper()
fs := afero.NewOsFs()
fileInfo, err := fs.Stat(fPath)
require.NoError(t, err)
require.NotNil(t, fileInfo)
require.NoError(tb, err)
require.NotNil(tb, fileInfo)

enc, err := afero.ReadFile(fs, fPath)
require.NoError(t, err)
require.NoError(tb, err)
decoded, err := hexutil.Decode(string(enc))
require.NoError(t, err)
require.Len(t, decoded, 32)
require.NoError(tb, err)
require.Len(tb, decoded, 32)
}
7 changes: 4 additions & 3 deletions mod/node-builder/pkg/commands/utils/tos/tos.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ import (
"github.com/spf13/cobra"
)

//nolint:lll
const (
// acceptTosFilename is the name of the file that stores the accepted terms
// of use.
acceptTosFilename = "tosaccepted"
// acceptTosPromptTextFormat is the format for the prompt text for accepting
// the terms of use.
//nolint:lll

acceptTosPromptTextFormat = `
%s Terms of Use
Expand All @@ -58,12 +59,12 @@ TERMS AND CONDITIONS: %s
Type "accept" to accept these terms and conditions [accept/decline]:`
// acceptTosPromptErrTextFormat is the error prompt text for accepting the
// terms of use.
//nolint:lll

AcceptTosPromptErrTextFormat = `could not scan text input, if you are trying to run in
non-interactive environment, you can use the --accept-terms-of-use flag after reading the
terms and conditions here:
%s`
//nolint:lll

DeclinedErrorString = "you have to accept Terms and Conditions in order to continue"
)

Expand Down
1 change: 1 addition & 0 deletions mod/node-builder/pkg/commands/utils/tos/tos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func TestDeclineWithNonInteractiveCLI(t *testing.T) {
// }

func makeTempDir(t *testing.T) string {
t.Helper()
homeDir, err := os.MkdirTemp("", "beacond-test-*")
if err != nil {
t.Errorf("Expected no error, got %v", err)
Expand Down
Loading

0 comments on commit 0bd5c01

Please sign in to comment.