Skip to content
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

chore: upgrade golangci-lint version to v1.60.3 and fix lint #3414

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.54.2
version: v1.60.3
working-directory: ${{ matrix.workdir }}
skip-pkg-cache: true
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ linters:
- gofumpt
- goconst
- goimports
- gomnd
- mnd
- gocyclo
- ineffassign
- lll
Expand Down Expand Up @@ -54,9 +54,9 @@ linters-settings:
multi-func: true
lll:
line-length: 160
gomnd:
mnd:
# don't include the "operation", "argument" and "assign"
checks:
checks:
- case
- condition
- return
Expand Down
6 changes: 3 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"syscall"
"time"

"github.com/google/uuid"
"golang.org/x/sync/errgroup"

"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/registry"
"github.com/go-kratos/kratos/v2/transport"

"github.com/google/uuid"
"golang.org/x/sync/errgroup"
)

// AppInfo is application context value.
Expand Down
2 changes: 1 addition & 1 deletion cmd/kratos/internal/proto/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func walk(dir string, args []string) error {
if dir == "" {
dir = "."
}
return filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
return filepath.Walk(dir, func(path string, _ os.FileInfo, _ error) error {
if ext := filepath.Ext(path); ext != ".proto" || strings.HasPrefix(path, "third_party") {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kratos/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func findCMD(base string) (map[string]string, error) {
var root bool
next := func(dir string) (map[string]string, error) {
cmdPath := make(map[string]string)
err := filepath.Walk(dir, func(walkPath string, info os.FileInfo, err error) error {
err := filepath.Walk(dir, func(walkPath string, info os.FileInfo, _ error) error {
// multi level directory is not allowed under the cmdPath directory, so it is judged that the path ends with cmdPath.
if strings.HasSuffix(walkPath, "cmd") {
paths, err := os.ReadDir(walkPath)
Expand Down
3 changes: 1 addition & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ func TestConfig(t *testing.T) {
t.Fatal("databaseDriver is not equal to val")
}

err = cf.Watch("endpoints", func(key string, value Value) {
})
err = cf.Watch("endpoints", func(string, Value) {})
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion config/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (e *env) load(envs []string) []*config.KeyValue {
var kv []*config.KeyValue
for _, env := range envs {
var k, v string
subs := strings.SplitN(env, "=", 2) //nolint:gomnd
subs := strings.SplitN(env, "=", 2) //nolint:mnd
k = subs[0]
if len(subs) > 1 {
v = subs[1]
Expand Down
4 changes: 2 additions & 2 deletions config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func resolver(input map[string]interface{}, mapper func(name string) string, toT

func mapper(input map[string]interface{}) func(name string) string {
mapper := func(name string) string {
args := strings.SplitN(strings.TrimSpace(name), ":", 2) //nolint:gomnd
args := strings.SplitN(strings.TrimSpace(name), ":", 2) //nolint:mnd
if v, has := readValue(input, args[0]); has {
s, _ := v.String()
return s
Expand Down Expand Up @@ -183,7 +183,7 @@ func expand(s string, mapping func(string) string, toType bool) interface{} {
re := r.FindAllStringSubmatch(s, -1)
var ct interface{}
for _, i := range re {
if len(i) == 2 { //nolint:gomnd
if len(i) == 2 { //nolint:mnd
m := mapping(i[1])
if toType {
ct = convertToType(m)
Expand Down
2 changes: 1 addition & 1 deletion config/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func TestExpand(t *testing.T) {

func TestWithMergeFunc(t *testing.T) {
c := &options{}
a := func(dst, src interface{}) error {
a := func(any, any) error {
return nil
}
WithMergeFunc(a)(c)
Expand Down
4 changes: 2 additions & 2 deletions contrib/config/nacos/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ func TestConfig_Watch(t *testing.T) {
source: source,
},
wantErr: false,
processFunc: func(t *testing.T, w config.Watcher) {
processFunc: func(t *testing.T, _ config.Watcher) {
_, pErr := client.PublishConfig(vo.ConfigParam{DataId: "test.yaml", Group: "test", Content: "test: test"})
if pErr != nil {
t.Error(pErr)
}
},
deferFunc: func(t *testing.T, w config.Watcher) {
deferFunc: func(t *testing.T, _ config.Watcher) {
_, dErr := client.DeleteConfig(vo.ConfigParam{DataId: "test.yaml", Group: "test"})
if dErr != nil {
t.Error(dErr)
Expand Down
4 changes: 2 additions & 2 deletions contrib/opensergo/opensergo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func TestOpenSergo(t *testing.T) {
args: args{
opts: []Option{},
},
preFunc: func(t *testing.T) {
preFunc: func(_ *testing.T) {
err := os.Setenv("OPENSERGO_ENDPOINT", "127.0.0.1:9090")
if err != nil {
panic(err)
Expand All @@ -322,7 +322,7 @@ func TestOpenSergo(t *testing.T) {
args: args{
opts: []Option{},
},
preFunc: func(t *testing.T) {
preFunc: func(_ *testing.T) {
err := os.Setenv("OPENSERGO_BOOTSTRAP", `{"endpoint": "127.0.0.1:9090"}`)
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion contrib/polaris/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func buildPolarisInstance(namespace string, nodes []selector.Node) *pb.ServiceIn
Service: &v1.Service{Name: wrapperspb.String(nodes[0].ServiceName()), Namespace: wrapperspb.String("default")},
Instances: ins,
}
return pb.NewServiceInstancesInProto(d, func(s string) local.InstanceLocalValue {
return pb.NewServiceInstancesInProto(d, func(string) local.InstanceLocalValue {
return local.NewInstanceLocalValue()
}, &pb.SvcPluginValues{Routers: nil, Loadbalancer: nil}, nil)
}
6 changes: 2 additions & 4 deletions contrib/registry/consul/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ func TestRegistry_Watch(t *testing.T) {
},
want: []*registry.ServiceInstance{instance1},
wantErr: false,
preFunc: func(t *testing.T) {
},
preFunc: func(*testing.T) {},
},
{
name: "ctx has been canceled",
Expand All @@ -344,8 +343,7 @@ func TestRegistry_Watch(t *testing.T) {
},
want: nil,
wantErr: true,
preFunc: func(t *testing.T) {
},
preFunc: func(*testing.T) {},
},
{
name: "register with healthCheck",
Expand Down
4 changes: 2 additions & 2 deletions contrib/registry/etcd/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (r *Registry) heartBeat(ctx context.Context, leaseID clientv3.LeaseID, key
if err != nil {
curLeaseID = 0
}
rand.Seed(time.Now().Unix())
randSource := rand.New(rand.NewSource(time.Now().Unix()))

for {
if curLeaseID == 0 {
Expand Down Expand Up @@ -200,7 +200,7 @@ func (r *Registry) heartBeat(ctx context.Context, leaseID clientv3.LeaseID, key
break
}
retreat = append(retreat, 1<<retryCnt)
time.Sleep(time.Duration(retreat[rand.Intn(len(retreat))]) * time.Second)
time.Sleep(time.Duration(retreat[randSource.Intn(len(retreat))]) * time.Second)
}
if _, ok := <-kac; !ok {
// retry failed
Expand Down
8 changes: 4 additions & 4 deletions contrib/registry/eureka/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ func (e *Client) pickServer(currentTimes int) string {
}

func (e *Client) shuffle() {
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(e.urls), func(i, j int) {
e.urls[i], e.urls[j] = e.urls[j], e.urls[i]
})
rand.New(rand.NewSource(time.Now().UnixNano())).
Shuffle(len(e.urls), func(i, j int) {
e.urls[i], e.urls[j] = e.urls[j], e.urls[i]
})
}

func (e *Client) buildAPI(currentTimes int, params ...string) string {
Expand Down
6 changes: 3 additions & 3 deletions contrib/registry/kubernetes/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ func (s *Registry) Watch(ctx context.Context, name string) (registry.Watcher, er
}
},
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
AddFunc: func(interface{}) {
s.sendLatestInstances(ctx, name, announcement)
},
UpdateFunc: func(oldObj, newObj interface{}) {
UpdateFunc: func(interface{}, interface{}) {
s.sendLatestInstances(ctx, name, announcement)
},
DeleteFunc: func(obj interface{}) {
DeleteFunc: func(interface{}) {
s.sendLatestInstances(ctx, name, announcement)
},
},
Expand Down
1 change: 0 additions & 1 deletion contrib/registry/kubernetes/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func TestRegistry(t *testing.T) {
Endpoints: []string{"http://127.0.0.1:80"},
}
_, err = clientSet.AppsV1().Deployments(namespace).Create(context.Background(), &deployment, metav1.CreateOptions{})

if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/registry/nacos/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func TestRegistry_Watch(t *testing.T) {
},
wantErr: true,
want: nil,
processFunc: func(t *testing.T) {
processFunc: func(*testing.T) {
cancel()
},
},
Expand Down
2 changes: 1 addition & 1 deletion contrib/registry/nacos/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func newWatcher(ctx context.Context, cli naming_client.INamingClient, serviceNam
ServiceName: serviceName,
Clusters: clusters,
GroupName: groupName,
SubscribeCallback: func(services []model.SubscribeService, err error) {
SubscribeCallback: func([]model.SubscribeService, error) {
select {
case w.watchChan <- struct{}{}:
default:
Expand Down
8 changes: 4 additions & 4 deletions contrib/registry/zookeeper/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestRegistry_GetService(t *testing.T) {
},
{
name: "conn close",
preFunc: func(t *testing.T) {
preFunc: func(*testing.T) {
conn.Close()
},
fields: fields{
Expand Down Expand Up @@ -339,7 +339,7 @@ func TestRegistry_Watch(t *testing.T) {
t.Error(err)
}
},
processFunc: func(t *testing.T, w registry.Watcher) {
processFunc: func(t *testing.T, _ registry.Watcher) {
err = r.Register(context.Background(), svrHello)
if err != nil {
t.Error(err)
Expand All @@ -357,7 +357,7 @@ func TestRegistry_Watch(t *testing.T) {
},
wantErr: true,
want: nil,
processFunc: func(t *testing.T, w registry.Watcher) {
processFunc: func(*testing.T, registry.Watcher) {
cancel()
},
},
Expand All @@ -372,7 +372,7 @@ func TestRegistry_Watch(t *testing.T) {
},
wantErr: true,
want: nil,
processFunc: func(t *testing.T, w registry.Watcher) {
processFunc: func(*testing.T, registry.Watcher) {
closeConn.Close()
},
},
Expand Down
5 changes: 2 additions & 3 deletions encoding/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package encoding

import (
"encoding/xml"
"fmt"
"runtime/debug"
"testing"
)
Expand Down Expand Up @@ -40,7 +39,7 @@ func TestRegisterCodec(t *testing.T) {
f := func() { RegisterCodec(nil) }
funcDidPanic, panicValue, _ := didPanic(f)
if !funcDidPanic {
t.Fatalf(fmt.Sprintf("func should panic\n\tPanic value:\t%#v", panicValue))
t.Fatalf("func should panic\n\tPanic value:\t%#v", panicValue)
}
if panicValue != "cannot register a nil Codec" {
t.Fatalf("panic error got %s want cannot register a nil Codec", panicValue)
Expand All @@ -50,7 +49,7 @@ func TestRegisterCodec(t *testing.T) {
}
funcDidPanic, panicValue, _ = didPanic(f)
if !funcDidPanic {
t.Fatalf(fmt.Sprintf("func should panic\n\tPanic value:\t%#v", panicValue))
t.Fatalf("func should panic\n\tPanic value:\t%#v", panicValue)
}
if panicValue != "cannot register Codec with empty string result for Name()" {
t.Fatalf("panic error got %s want cannot register Codec with empty string result for Name()", panicValue)
Expand Down
Loading
Loading