Skip to content

Commit d0e86d0

Browse files
authored
ci: upgrade golangci-lint to v2 (#746)
Signed-off-by: Roman Dmytrenko <[email protected]>
1 parent faed7f1 commit d0e86d0

File tree

24 files changed

+153
-92
lines changed

24 files changed

+153
-92
lines changed

.golangci.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
1+
---
2+
version: "2"
3+
4+
formatters:
5+
enable: []
6+
# - gofumpt
7+
# - gci
8+
9+
linters:
10+
default: none
11+
enable:
12+
- copyloopvar
13+
- dupword
14+
- errcheck
15+
- govet
16+
- ineffassign
17+
- intrange
18+
- misspell
19+
- staticcheck
20+
# - unused
21+
settings:
22+
staticcheck:
23+
checks:
24+
- "all"
25+
- "-ST1000" # package comment
26+
- "-ST1003" # incorrect identifier
27+
- "-ST1005" # incorrectly formatted error
28+
- "-QF1008" # omit embedded field from selector expression
29+
- "-SA1019" # using deprecated
30+
exclusions:
31+
paths:
32+
- tests/flagd
33+
34+
issues:
35+
max-issues-per-linter: 0
36+
max-same-issues: 0
37+
138
run:
239
timeout: 3m
40+
build-tags:
41+
- testtools
42+
modules-download-mode: readonly
43+
44+
output:
45+
sort-order:
46+
- file

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | s
22
MODULE_TYPE ?= providers
33
FLAGD_TESTBED = flagd-testbed
44
FLAGD_SYNC = sync-testbed
5+
GOLANGCI_LINT_VERSION := v2.4.0
6+
GOBIN := $(shell go env GOBIN)
57

68
workspace-init:
79
go work init
@@ -18,8 +20,8 @@ e2e:
1820
go clean -testcache && go list -f '{{.Dir}}/...' -m | xargs -I{} go test -timeout=1m -tags=e2e {}
1921

2022
lint:
21-
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.8
22-
$(foreach module, $(ALL_GO_MOD_DIRS), ${GOPATH}/bin/golangci-lint run $(module)/...;)
23+
go install -v github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
24+
$(foreach module, $(ALL_GO_MOD_DIRS), ${GOBIN}/golangci-lint run $(module)/...;)
2325

2426
new-provider:
2527
mkdir ./providers/$(MODULE_NAME)

providers/flagd/pkg/configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ func WithCustomSyncProvider(customSyncProvider sync.ISync) ProviderOption {
379379
return WithCustomSyncProviderAndUri(customSyncProvider, defaultCustomSyncProviderUri)
380380
}
381381

382-
// WithCustomSyncProvider provides a custom implementation of the sync.ISync interface used by the inProcess Service
382+
// WithCustomSyncProviderAndUri provides a custom implementation of the sync.ISync interface used by the inProcess Service
383383
// This is only useful with inProcess resolver type
384384
func WithCustomSyncProviderAndUri(customSyncProvider sync.ISync, customSyncProviderUri string) ProviderOption {
385385
return func(p *ProviderConfiguration) {

providers/flagd/pkg/provider.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ func NewProvider(opts ...ProviderOption) (*Provider, error) {
4646
provider.providerConfiguration.log)
4747

4848
var service IService
49-
if provider.providerConfiguration.Resolver == rpc {
49+
switch provider.providerConfiguration.Resolver {
50+
case rpc:
5051
service = rpcService.NewService(
5152
rpcService.Configuration{
5253
Host: provider.providerConfiguration.Host,
@@ -59,7 +60,7 @@ func NewProvider(opts ...ProviderOption) (*Provider, error) {
5960
cacheService,
6061
provider.providerConfiguration.log,
6162
provider.providerConfiguration.EventStreamConnectionMaxAttempts)
62-
} else if provider.providerConfiguration.Resolver == inProcess {
63+
case inProcess:
6364
service = process.NewInProcessService(process.Configuration{
6465
Host: provider.providerConfiguration.Host,
6566
Port: provider.providerConfiguration.Port,
@@ -73,7 +74,7 @@ func NewProvider(opts ...ProviderOption) (*Provider, error) {
7374
CustomSyncProviderUri: provider.providerConfiguration.CustomSyncProviderUri,
7475
GrpcDialOptionsOverride: provider.providerConfiguration.GrpcDialOptionsOverride,
7576
})
76-
} else {
77+
default:
7778
service = process.NewInProcessService(process.Configuration{
7879
OfflineFlagSource: provider.providerConfiguration.OfflineFlagSourcePath,
7980
})

providers/flagd/pkg/service/in_process/do_nothing_custom_sync_provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/open-feature/flagd/core/pkg/sync"
77
)
88

9-
// Fake implementation of sync.ISync. Does not conform to the contract because it does not send any events to the DataSync.
9+
// DoNothingCustomSyncProvider is fake implementation of sync.ISync. Does not conform to the contract because it does not send any events to the DataSync.
1010
// Only used for unit tests.
1111
type DoNothingCustomSyncProvider struct {
1212
}
@@ -27,7 +27,7 @@ func (fps DoNothingCustomSyncProvider) ReSync(ctx context.Context, dataSync chan
2727
return nil
2828
}
2929

30-
// Returns an implementation of sync.ISync interface that does nothing at all.
30+
// NewDoNothingCustomSyncProvider returns an implementation of sync.ISync interface that does nothing at all.
3131
// The returned implementation does not conform to the sync.DataSync contract.
3232
// This is useful only for unit tests.
3333
func NewDoNothingCustomSyncProvider() DoNothingCustomSyncProvider {

providers/flagd/pkg/service/rpc/service.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
flagdService "github.com/open-feature/flagd/core/pkg/service"
2121
"github.com/open-feature/go-sdk-contrib/providers/flagd/internal/cache"
2222
"github.com/open-feature/go-sdk-contrib/providers/flagd/internal/logger"
23-
"github.com/open-feature/go-sdk/openfeature"
2423
of "github.com/open-feature/go-sdk/openfeature"
2524
"golang.org/x/net/context"
2625
"google.golang.org/protobuf/types/known/structpb"
@@ -115,7 +114,7 @@ func (s *Service) ResolveBoolean(ctx context.Context, key string, defaultValue b
115114
if s.cache.IsEnabled() {
116115
fromCache, ok := s.cache.GetCache().Get(key)
117116
if ok {
118-
fromCacheResDetail, ok := fromCache.(openfeature.BoolResolutionDetail)
117+
fromCacheResDetail, ok := fromCache.(of.BoolResolutionDetail)
119118
if ok {
120119
fromCacheResDetail.Reason = ReasonCached
121120
return fromCacheResDetail
@@ -174,7 +173,7 @@ func (s *Service) ResolveString(ctx context.Context, key string, defaultValue st
174173
if s.cache.IsEnabled() {
175174
fromCache, ok := s.cache.GetCache().Get(key)
176175
if ok {
177-
fromCacheResDetail, ok := fromCache.(openfeature.StringResolutionDetail)
176+
fromCacheResDetail, ok := fromCache.(of.StringResolutionDetail)
178177
if ok {
179178
fromCacheResDetail.Reason = ReasonCached
180179
return fromCacheResDetail
@@ -233,7 +232,7 @@ func (s *Service) ResolveFloat(ctx context.Context, key string, defaultValue flo
233232
if s.cache.IsEnabled() {
234233
fromCache, ok := s.cache.GetCache().Get(key)
235234
if ok {
236-
fromCacheResDetail, ok := fromCache.(openfeature.FloatResolutionDetail)
235+
fromCacheResDetail, ok := fromCache.(of.FloatResolutionDetail)
237236
if ok {
238237
fromCacheResDetail.Reason = ReasonCached
239238
return fromCacheResDetail
@@ -292,7 +291,7 @@ func (s *Service) ResolveInt(ctx context.Context, key string, defaultValue int64
292291
if s.cache.IsEnabled() {
293292
fromCache, ok := s.cache.GetCache().Get(key)
294293
if ok {
295-
fromCacheResDetail, ok := fromCache.(openfeature.IntResolutionDetail)
294+
fromCacheResDetail, ok := fromCache.(of.IntResolutionDetail)
296295
if ok {
297296
fromCacheResDetail.Reason = ReasonCached
298297
return fromCacheResDetail
@@ -350,7 +349,7 @@ func (s *Service) ResolveObject(ctx context.Context, key string, defaultValue in
350349
if s.cache.IsEnabled() {
351350
fromCache, ok := s.cache.GetCache().Get(key)
352351
if ok {
353-
fromCacheResDetail, ok := fromCache.(openfeature.InterfaceResolutionDetail)
352+
fromCacheResDetail, ok := fromCache.(of.InterfaceResolutionDetail)
354353
if ok {
355354
fromCacheResDetail.Reason = ReasonCached
356355
return fromCacheResDetail
@@ -414,7 +413,7 @@ func resolve[req resolutionRequestConstraints, resp resolutionResponseConstraint
414413
evalCtxF, err := structpb.NewStruct(evalCtx)
415414
if err != nil {
416415
logger.Error(err, "struct from evaluation context")
417-
return nil, openfeature.NewParseErrorResolutionError(err.Error())
416+
return nil, of.NewParseErrorResolutionError(err.Error())
418417
}
419418

420419
res, err := resolver(ctx, connect.NewRequest(&req{
@@ -428,20 +427,20 @@ func resolve[req resolutionRequestConstraints, resp resolutionResponseConstraint
428427
return res.Msg, nil
429428
}
430429

431-
func handleError(err error) openfeature.ResolutionError {
430+
func handleError(err error) of.ResolutionError {
432431
connectErr := &connect.Error{}
433432
errors.As(err, &connectErr)
434433
switch connectErr.Code() {
435434
case connect.CodeUnavailable:
436-
return openfeature.NewProviderNotReadyResolutionError(ConnectionError)
435+
return of.NewProviderNotReadyResolutionError(ConnectionError)
437436
case connect.CodeNotFound:
438-
return openfeature.NewFlagNotFoundResolutionError(err.Error())
437+
return of.NewFlagNotFoundResolutionError(err.Error())
439438
case connect.CodeInvalidArgument:
440-
return openfeature.NewTypeMismatchResolutionError(err.Error())
439+
return of.NewTypeMismatchResolutionError(err.Error())
441440
case connect.CodeDataLoss:
442-
return openfeature.NewParseErrorResolutionError(err.Error())
441+
return of.NewParseErrorResolutionError(err.Error())
443442
}
444-
return openfeature.NewGeneralResolutionError(err.Error())
443+
return of.NewGeneralResolutionError(err.Error())
445444
}
446445

447446
func (s *Service) EventChannel() <-chan of.Event {

providers/flagd/pkg/service/rpc/service_evaluation_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func TestBooleanEvaluation(t *testing.T) {
173173
}
174174

175175
for _, test := range tests {
176-
service := Service{
176+
service := &Service{
177177
cache: test.getCache(),
178178
logger: log,
179179
client: test.getMockClient(),
@@ -309,7 +309,7 @@ func TestStringEvaluation(t *testing.T) {
309309
}
310310

311311
for _, test := range tests {
312-
service := Service{
312+
service := &Service{
313313
cache: test.getCache(),
314314
logger: log,
315315
client: test.getMockClient(),
@@ -445,7 +445,7 @@ func TestFloatEvaluation(t *testing.T) {
445445
}
446446

447447
for _, test := range tests {
448-
service := Service{
448+
service := &Service{
449449
cache: test.getCache(),
450450
logger: log,
451451
client: test.getMockClient(),
@@ -581,7 +581,7 @@ func TestIntEvaluation(t *testing.T) {
581581
}
582582

583583
for _, test := range tests {
584-
service := Service{
584+
service := &Service{
585585
cache: test.getCache(),
586586
logger: log,
587587
client: test.getMockClient(),
@@ -730,7 +730,7 @@ func TestObjectEvaluation(t *testing.T) {
730730
}
731731

732732
for _, test := range tests {
733-
service := Service{
733+
service := &Service{
734734
cache: test.getCache(),
735735
logger: log,
736736
client: test.getMockClient(),
@@ -742,7 +742,7 @@ func TestObjectEvaluation(t *testing.T) {
742742
}
743743

744744
// validate is a generic validator
745-
func validate[T responseType](t *testing.T, test testStruct[T], resolutionDetail T, error of.ResolutionError, service Service) {
745+
func validate[T responseType](t *testing.T, test testStruct[T], resolutionDetail T, error of.ResolutionError, service *Service) {
746746
if diff := cmp.Diff(
747747
test.expectResponse, resolutionDetail,
748748
cmpopts.IgnoreFields(of.ProviderResolutionDetail{}, "ResolutionError"),

providers/flagsmith/pkg/provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func NewProvider(client *flagsmithClient.Client, opts ...ProviderOption) *Provid
2828

2929
}
3030

31-
// flagsmith provider does not have any hooks, returns empty slice
31+
// Hooks returns empty slice as flagsmith provider does not have any
3232
func (p *Provider) Hooks() []of.Hook {
3333
return []of.Hook{}
3434
}
@@ -144,7 +144,7 @@ func (p *Provider) BooleanEvaluation(ctx context.Context, flag string, defaultVa
144144

145145
if p.usingBooleanConfigValue {
146146
// Value will be true if the flag is enabled, false otherwise
147-
value := !(resolutionDetails.Reason == of.DisabledReason)
147+
value := resolutionDetails.Reason != of.DisabledReason
148148
return of.BoolResolutionDetail{
149149
Value: value,
150150
ProviderResolutionDetail: of.ProviderResolutionDetail{

providers/go-feature-flag/pkg/provider_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (m *mockClient) roundTripFunc(req *http.Request) *http.Response {
7979

8080
m.callCount++
8181
mockPath := "../testutils/mock_responses/%s.json"
82-
flagName := strings.Replace(req.URL.Path, "/ofrep/v1/evaluate/flags/", "", -1)
82+
flagName := strings.ReplaceAll(req.URL.Path, "/ofrep/v1/evaluate/flags/", "")
8383

8484
if flagName == "unauthorized" {
8585
return &http.Response{

providers/harness/pkg/provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ func (p *Provider) Status() of.State {
4343
}
4444

4545
func (p *Provider) Shutdown() {
46-
p.harnessClient.Close()
46+
_ = p.harnessClient.Close()
4747
p.status = of.NotReadyState
4848
}
4949

50-
// provider does not have any hooks, returns empty slice
50+
// Hooks returns empty slices as provider does not have any
5151
func (p *Provider) Hooks() []of.Hook {
5252
return []of.Hook{}
5353
}

0 commit comments

Comments
 (0)