Skip to content

Commit f16cc1c

Browse files
Upgrade golangci v2 (#449)
* upgrade golangci to v2 * fix linter errors * fix finter
1 parent 782625f commit f16cc1c

File tree

16 files changed

+134
-130
lines changed

16 files changed

+134
-130
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Checkout code
1212
uses: actions/checkout@v4
1313
- name: Run linters
14-
uses: golangci/golangci-lint-action@v6
14+
uses: golangci/golangci-lint-action@v8
1515
with:
1616
version: latest
1717
args: --timeout=3m

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Checkout code
3131
uses: actions/checkout@v4
3232
- name: Run linters
33-
uses: golangci/golangci-lint-action@v6
33+
uses: golangci/golangci-lint-action@v8
3434
with:
3535
version: latest
3636
args: --timeout=3m

.golangci.yml

Lines changed: 107 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,111 @@
1-
linters-settings:
2-
exhaustive:
3-
default-signifies-exhaustive: true
4-
5-
gocritic:
6-
# The list of supported checkers can be find in https://go-critic.github.io/overview.
7-
settings:
8-
underef:
9-
# Whether to skip (*x).method() calls where x is a pointer receiver.
10-
skipRecvDeref: false
11-
12-
govet:
13-
enable-all: true
14-
disable:
15-
- fieldalignment # too strict
16-
- shadow # complains too much about shadowing errors. All research points to this being fine.
17-
18-
nakedret:
19-
max-func-lines: 0
20-
21-
nolintlint:
22-
allow-no-explanation: [ forbidigo, tracecheck, gomnd, gochecknoinits, makezero ]
23-
require-explanation: true
24-
require-specific: true
25-
26-
revive:
27-
ignore-generated-header: true
28-
severity: error
29-
rules:
30-
- name: atomic
31-
- name: line-length-limit
32-
arguments: [ 200 ]
33-
# These are functions that we use without checking the errors often. Most of these can't return an error even
34-
# though they implement an interface that can.
35-
- name: unhandled-error
36-
arguments:
37-
- fmt.Printf
38-
- fmt.Println
39-
- fmt.Fprint
40-
- fmt.Fprintf
41-
- fmt.Fprintln
42-
- os.Stderr.Sync
43-
- sb.WriteString
44-
- buf.WriteString
45-
- hasher.Write
46-
- os.Setenv
47-
- os.RemoveAll
48-
- name: var-naming
49-
arguments: [["ID", "URL", "HTTP", "API"], []]
50-
51-
tenv:
52-
all: true
53-
54-
1+
version: "2"
552
linters:
56-
disable-all: true
3+
default: none
574
enable:
58-
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
59-
- gosimple # Linter for Go source code that specializes in simplifying a code
60-
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
61-
- ineffassign # Detects when assignments to existing variables are not used
62-
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
63-
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
64-
- unused # Checks Go code for unused constants, variables, functions and types
65-
- asasalint # Check for pass []any as any in variadic func(...any)
66-
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
67-
- bidichk # Checks for dangerous unicode character sequences
68-
- bodyclose # checks whether HTTP response body is closed successfully
69-
- durationcheck # check for two durations multiplied together
70-
- 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.
71-
# https://github.com/1uf3/execinquery is archived so golangci-lint warns/errors about it
72-
# - execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds
73-
- exhaustive # check exhaustiveness of enum switch statements
74-
- forbidigo # Forbids identifiers
75-
- gochecknoinits # Checks that no init functions are present in Go code
76-
- goconst # Finds repeated strings that could be replaced by a constant
77-
- gocritic # Provides diagnostics that check for bugs, performance and style issues.
78-
- godot # Check if comments end in a period
79-
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt.
80-
# Need this disabled for now, we need to have a replace
81-
# - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
82-
- goprintffuncname # Checks that printf-like functions are named with f at the end
83-
- gosec # Inspects source code for security problems
84-
- nakedret # Finds naked returns in functions greater than a specified function length
85-
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
86-
- noctx # noctx finds sending http request without context.Context
87-
- nolintlint # Reports ill-formed or insufficient nolint directives
88-
- nonamedreturns # Reports all named returns
89-
- nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL.
90-
- predeclared # find code that shadows one of Go's predeclared identifiers
91-
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
92-
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
93-
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
94-
- unconvert # Remove unnecessary type conversions
95-
- usestdlibvars # detect the possibility to use variables/constants from the Go standard library
96-
- whitespace # Tool for detection of leading and trailing whitespace
97-
5+
- asasalint
6+
- asciicheck
7+
- bidichk
8+
- bodyclose
9+
- durationcheck
10+
- errcheck
11+
- errorlint
12+
- exhaustive
13+
- forbidigo
14+
- gochecknoinits
15+
- goconst
16+
- gocritic
17+
- godot
18+
- goprintffuncname
19+
- gosec
20+
- govet
21+
- ineffassign
22+
- nakedret
23+
- nilerr
24+
- noctx
25+
- nolintlint
26+
- nonamedreturns
27+
- nosprintfhostport
28+
- predeclared
29+
- revive
30+
- staticcheck
31+
- tparallel
32+
- unconvert
33+
- unused
34+
- usestdlibvars
35+
- whitespace
36+
settings:
37+
exhaustive:
38+
default-signifies-exhaustive: true
39+
gocritic:
40+
settings:
41+
underef:
42+
skipRecvDeref: false
43+
govet:
44+
disable:
45+
- fieldalignment
46+
- shadow
47+
enable-all: true
48+
nakedret:
49+
max-func-lines: 0
50+
nolintlint:
51+
require-explanation: true
52+
require-specific: true
53+
allow-no-explanation:
54+
- forbidigo
55+
- tracecheck
56+
- gomnd
57+
- gochecknoinits
58+
- makezero
59+
revive:
60+
severity: error
61+
rules:
62+
- name: atomic
63+
- name: line-length-limit
64+
arguments:
65+
- 200
66+
- name: unhandled-error
67+
arguments:
68+
- fmt.Printf
69+
- fmt.Println
70+
- fmt.Fprint
71+
- fmt.Fprintf
72+
- fmt.Fprintln
73+
- os.Stderr.Sync
74+
- sb.WriteString
75+
- buf.WriteString
76+
- hasher.Write
77+
- os.Setenv
78+
- os.RemoveAll
79+
- name: var-naming
80+
arguments:
81+
- - ID
82+
- URL
83+
- HTTP
84+
- API
85+
- []
86+
exclusions:
87+
generated: lax
88+
presets:
89+
- comments
90+
- common-false-positives
91+
- legacy
92+
- std-error-handling
93+
rules:
94+
- linters:
95+
- godot
96+
source: (TODO)
97+
paths:
98+
- third_party$
99+
- builtin$
100+
- examples$
98101
issues:
99102
max-same-issues: 50
100-
101-
exclude-rules:
102-
# Don't require TODO comments to end in a period
103-
- source: "(TODO)"
104-
linters: [ godot ]
103+
formatters:
104+
enable:
105+
- goimports
106+
exclusions:
107+
generated: lax
108+
paths:
109+
- third_party$
110+
- builtin$
111+
- examples$

pkg/actions/actions.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func NewOutstandingAction(id, name string) *OutstandingAction {
4141
}
4242

4343
func (oa *OutstandingAction) SetStatus(ctx context.Context, status v2.BatonActionStatus) {
44-
oa.Mutex.Lock()
45-
defer oa.Mutex.Unlock()
44+
oa.Lock()
45+
defer oa.Unlock()
4646
l := ctxzap.Extract(ctx).With(
4747
zap.String("action_id", oa.Id),
4848
zap.String("action_name", oa.Name),
@@ -59,8 +59,8 @@ func (oa *OutstandingAction) SetStatus(ctx context.Context, status v2.BatonActio
5959
}
6060

6161
func (oa *OutstandingAction) setError(_ context.Context, err error) {
62-
oa.Mutex.Lock()
63-
defer oa.Mutex.Unlock()
62+
oa.Lock()
63+
defer oa.Unlock()
6464
if oa.Rv == nil {
6565
oa.Rv = &structpb.Struct{}
6666
}

pkg/actions/actions_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func testActionHandler(ctx context.Context, args *structpb.Struct) (*structpb.St
4141
return nil, nil, fmt.Errorf("missing dn")
4242
}
4343

44-
var userStruct structpb.Struct = structpb.Struct{
44+
var userStruct = structpb.Struct{
4545
Fields: map[string]*structpb.Value{
4646
"success": {
4747
Kind: &structpb.Value_BoolValue{BoolValue: true},
@@ -66,7 +66,7 @@ func testAsyncActionHandler(ctx context.Context, args *structpb.Struct) (*struct
6666
}
6767
}
6868

69-
var userStruct structpb.Struct = structpb.Struct{
69+
var userStruct = structpb.Struct{
7070
Fields: map[string]*structpb.Value{
7171
"success": {
7272
Kind: &structpb.Value_BoolValue{BoolValue: true},
@@ -109,7 +109,7 @@ func testAsyncCancelActionHandler(ctx context.Context, args *structpb.Struct) (*
109109
}
110110
}
111111

112-
var userStruct structpb.Struct = structpb.Struct{
112+
var userStruct = structpb.Struct{
113113
Fields: map[string]*structpb.Value{
114114
"success": {
115115
Kind: &structpb.Value_BoolValue{BoolValue: true},

pkg/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func DefineConfiguration[T field.Configurable](
5252
uniqueFields := make(map[string]field.SchemaField)
5353
for _, f := range confschema.Fields {
5454
if s, ok := uniqueFields[f.FieldName]; ok {
55-
if !(f.WasReExported || s.WasReExported) {
55+
if !f.WasReExported && !s.WasReExported {
5656
return nil, nil, fmt.Errorf("multiple fields with the same name: %s.If you want to use a default field in the SDK, use ExportAs on the connector schema field", f.FieldName)
5757
}
5858
}
@@ -140,7 +140,7 @@ func verifyStructFields[T field.Configurable](schema field.Configuration) error
140140
configType = configType.Elem()
141141
}
142142
if configType.Kind() != reflect.Struct {
143-
return fmt.Errorf("T must be a struct type, got %v", configType.Kind())
143+
return fmt.Errorf("T must be a struct type, got %v", configType.Kind()) //nolint:staticcheck // we want to capital letter here
144144
}
145145
for _, field := range schema.Fields {
146146
fieldFound := false

pkg/connectorrunner/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func (c *connectorRunner) run(ctx context.Context) error {
228228
}
229229

230230
if stopForLoop {
231-
return fmt.Errorf("Unable to communicate with gRPC server")
231+
return fmt.Errorf("unable to communicate with gRPC server")
232232
}
233233

234234
return nil

pkg/crypto/providers/registry.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/conductorone/baton-sdk/pkg/crypto/providers/jwk"
1010
)
1111

12-
var EncryptionProviderNotRegisteredError = fmt.Errorf("crypto/providers: encryption provider not registered")
12+
var ErrEncryptionProviderNotRegistered = fmt.Errorf("crypto/providers: encryption provider not registered")
1313

1414
type EncryptionProvider interface {
1515
Encrypt(ctx context.Context, conf *v2.EncryptionConfig, plainText *v2.PlaintextData) (*v2.EncryptedData, error)
@@ -29,15 +29,15 @@ func normalizeProviderName(name string) string {
2929
func GetEncryptionProvider(name string) (EncryptionProvider, error) {
3030
provider, ok := providerRegistry[normalizeProviderName(name)]
3131
if !ok {
32-
return nil, fmt.Errorf("%w (%s)", EncryptionProviderNotRegisteredError, name)
32+
return nil, fmt.Errorf("%w (%s)", ErrEncryptionProviderNotRegistered, name)
3333
}
3434
return provider, nil
3535
}
3636

3737
// GetEncryptionProviderForConfig returns the encryption provider for the given config.
3838
// If the config specifies a provider, we will fetch it directly by name and return an error if it's not found.
3939
// If the config contains a non-nil well-known configuration (like JWKPublicKeyConfig), we will return the provider for that by name.
40-
// If we can't find a provider, we return an EncryptionProviderNotRegisteredError.
40+
// If we can't find a provider, we return an ErrEncryptionProviderNotRegistered.
4141
func GetEncryptionProviderForConfig(ctx context.Context, conf *v2.EncryptionConfig) (EncryptionProvider, error) {
4242
providerName := normalizeProviderName(conf.GetProvider())
4343

@@ -51,7 +51,7 @@ func GetEncryptionProviderForConfig(ctx context.Context, conf *v2.EncryptionConf
5151

5252
// If we don't have a provider by now, bail.
5353
if providerName == "" {
54-
return nil, EncryptionProviderNotRegisteredError
54+
return nil, ErrEncryptionProviderNotRegistered
5555
}
5656

5757
return GetEncryptionProvider(providerName)

pkg/field/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func isValidDomain(hostname string) bool {
115115

116116
// Labels can only contain letters, digits, or hyphens
117117
for i := range label {
118-
if !(isAlphaNumeric(label[i]) || label[i] == '-') {
118+
if !isAlphaNumeric(label[i]) && label[i] != '-' {
119119
return false
120120
}
121121
}

pkg/metrics/otel_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/assert"
10-
_ "github.com/stretchr/testify/assert"
1110
"github.com/stretchr/testify/suite"
1211
"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
1312
sdkmetric "go.opentelemetry.io/otel/sdk/metric"

0 commit comments

Comments
 (0)