8000 Migrate to golangci-lint v2 by ccoVeille · Pull Request #1708 · gofr-dev/gofr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Migrate to golangci-lint v2 #1708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ jobs:
# Install the linting tool
- name: Install golangci-lint
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1

- name: Get dependencies
run: |
Expand All @@ -340,7 +340,7 @@ jobs:
# Run linter on the root module
- name: Lint Root Module
run: |
golangci-lint run --out-format=colored-line-number --timeout=5m
golangci-lint run --output.text.print-issued-lines --output.text.colors=true --show-stats=false --timeout=5m

# Run linter on each submodule
- name: Lint Submodules
Expand All @@ -352,7 +352,7 @@ jobs:
# Change directory to the submodule and run golangci-lint
cd $module
go mod tidy
golangci-lint run --timeout 9m0s || total_errors=$((total_errors + 1))
golangci-lint run --output.text.print-issued-lines --output.text.colors=true --show-stats=false --timeout 9m0s || total_errors=$((total_errors + 1))
cd - # Return to the root directory
done
echo "Total submodule lint errors: $total_errors"
Expand Down
253 changes: 129 additions & 124 deletions .golangci.yml
6D4E
Original file line number Diff line number Diff line change
@@ -1,105 +1,6 @@
---
linters-settings:
dupl:
threshold: 100
exhaustive:
default-signifies-exhaustive: false
funlen:
lines: 100
statements: 50
gci:
sections:
- standard
- default
- localmodule
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 10
goimports:
local-prefixes: github.com/golangci/golangci-lint
mnd:
checks:
- argument
- case
- condition
- return
govet:
enable:
- shadow
settings:
printf:
funcs:
- (gofr.dev/pkg/gofr/Logger).Logf
- (gofr.dev/pkg/gofr/Logger).Errorf
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: true # require an explanation for nolint directives
require-specific: true # require nolint directives to be specific about which linter is being skipped
usestdlibvars:
time-layout: true # Suggest the use of constants available in time package
revive:
rules:
# default revive rules, they have to be present otherwise they are disabled
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
arguments:
# enables checking public methods of private types
- "checkPrivateReceivers"
# make error messages clearer
- "sayRepetitiveInsteadOfStutters"
- name: increment-decrement
- name: indent-error-flow
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
- name: var-naming
# additional revive rules
- name: bare-return
- name: bool-literal-in-expr
- name: comment-spacings
- name: early-return
- name: defer
- name: deep-exit
- name: unused-receiver
- name: use-any

version: "2"
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
default: none
enable:
- asciicheck
- bodyclose
Expand All @@ -112,18 +13,15 @@ linters:
- errorlint
- exhaustive
- funlen
- gci
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- gofmt
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
Expand All @@ -138,33 +36,140 @@ linters:
- revive
- rowserrcheck
- staticcheck
- stylecheck
- testifylint
- thelper
- unconvert
- unparam
- unused
- usestdlibvars
- usetesting
- whitespace
- wsl
- usetesting



# don't enable:
# - godox # Disabling because we need TODO lines at this stage of project.
# - testpackage # We also need to do unit test for unexported functions. And adding _internal in all files is cumbersome.
# don't enable:
# - godox # Disabling because we need TODO lines at this stage of project.
# - testpackage # We also need to do unit test for unexported functions. And adding _internal in all files is cumbersome.

issues:
include:
- EXC0014

# exclude-use-default: false
# exclude-use-default: false # By default, golangci-lint does not enforce comments on exported types. We want it.
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd
- dupl
- goconst
settings:
dupl:
threshold: 100
exhaustive:
default-signifies-exhaustive: false
funlen:
lines: 100
statements: 50
goconst:
min-len: 2
min-occurrences: 2
gocritic:
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
gocyclo:
min-complexity: 10
govet:
enable:
- shadow
settings:
printf:
funcs:
- (gofr.dev/pkg/gofr/Logger).Logf
- (gofr.dev/pkg/gofr/Logger).Errorf
lll:
line-length: 140
misspell:
locale: US
mnd:
checks:
- argument
- case
- condition
- return
nolintlint:
require-explanation: true # require an explanation for nolint directives
require-specific: true # require nolint directives to be specific about which linter is being skipped
allow-unused: false # report any unused nolint directives
revive:
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
arguments:
# enables checking public methods of private types
- checkPrivateReceivers
# make error messages clearer
- sayRepetitiveInsteadOfStutters
- name: increment-decrement
- name: indent-error-flow
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
- name: var-naming
- name: bare-return
- name: bool-literal-in-expr
- name: comment-spacings
- name: early-return
- name: defer
- name: deep-exit
- name: unused-receiver
- name: use-any
staticcheck:
checks:
- all
- -QF1001 # TODO remove this line and fix reported errors
- -QF1003 # TODO remove this line and fix reported errors
- -QF1008 # TODO remove this line and fix reported errors
- -ST1000 # TODO remove this line and fix reported errors
usestdlibvars:
time-layout: true
exclusions:
presets:
- common-false-positives # TODO fix errors reported by this and remove this line
- legacy # TODO fix errors reported by this and remove this line
- std-error-handling # TODO remove this line, configure errcheck, and fix reported errors
rules:
- linters:
- dupl
- goconst
- mnd
path: _test\.go
- linters:
- revive
text: "exported (.+) should have comment" # TODO fix errors reported by this and remove this line
paths:
- examples # TODO remove this line and fix reported errors
formatters:
enable:
- gci
- gofmt
settings:
gci:
sections:
- standard
- default
- localmodule
goimports:
local-prefixes:
- github.com/golangci/golangci-lint
3 changes: 2 additions & 1 deletion examples/grpc/grpc-streaming-server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
"testing"
"time"

"gofr.dev/examples/grpc/grpc-streaming-server/server"
"google.golang.org/grpc"

"gofr.dev/examples/grpc/grpc-streaming-server/server"
)

func TestMain(m *testing.M) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ package server

import (
"fmt"
"gofr.dev/pkg/gofr"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"io"
"strings"
"time"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"gofr.dev/pkg/gofr"
)

// Register the gRPC service in your app using the following code in your main.go:
Expand Down
1 change: 1 addition & 0 deletions examples/grpc/grpc-unary-server/server/hello_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package server

import (
"fmt"

"gofr.dev/pkg/gofr"
)

Expand Down
1 change: 1 addition & 0 deletions examples/using-add-filestore/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

"gofr.dev/pkg/gofr"
"gofr.dev/pkg/gofr/cmd"
"gofr.dev/pkg/gofr/container"
Expand Down
1 change: 1 addition & 0 deletions examples/using-cron-jobs/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/stretchr/testify/assert"

"gofr.dev/pkg/gofr/testutil"
)

Expand Down
6 changes: 3 additions & 3 deletions pkg/gofr/cmd/terminal/spinner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestSpinner(t *testing.T) {

// Check if output contains spinner frames
outputStr := b.String()
assert.NotZero(t, outputStr)
assert.NotEmpty(t, outputStr)

// Testing Globe Spinner
b = &bytes.Buffer{}
Expand All @@ -50,7 +50,7 @@ func TestSpinner(t *testing.T) {

// Check if output contains spinner frames
outputStr = b.String()
assert.NotZero(t, outputStr)
assert.NotEmpty(t, outputStr)

// Testing Pulse Spinner
b = &bytes.Buffer{}
Expand All @@ -69,7 +69,7 @@ func TestSpinner(t *testing.T) {
// Check if output contains spinner frames
outputStr = b.String()
fmt.Println(outputStr)
assert.NotZero(t, outputStr)
assert.NotEmpty(t, outputStr)
}

func TestSpinner_contextDone(t *testing.T) {
Expand Down
Loading
Loading
0