Skip to content

Commit 91deeae

Browse files
authored
[chore]: enable emptyStringTest issues from gocritic (#4834)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
1 parent 6e74327 commit 91deeae

File tree

37 files changed

+57
-58
lines changed

37 files changed

+57
-58
lines changed

.golangci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ linters:
2929
- commentedOutCode
3030
- deferInLoop
3131
- emptyFallthrough
32-
- emptyStringTest
3332
- exitAfterDefer
3433
- hugeParam
3534
- importShadow

apis/v1alpha1/opampbridge_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (*OpAMPBridgeWebhook) validate(r *OpAMPBridge) (admission.Warnings, error)
9494
warnings := admission.Warnings{}
9595

9696
// validate OpAMP server endpoint
97-
if len(strings.TrimSpace(r.Spec.Endpoint)) == 0 {
97+
if strings.TrimSpace(r.Spec.Endpoint) == "" {
9898
return warnings, errors.New("the OpAMP server endpoint is not specified")
9999
}
100100

apis/v1alpha1/targetallocator_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (w TargetAllocatorWebhook) validate(ctx context.Context, ta *TargetAllocato
115115
// if the prometheusCR is enabled, it needs a suite of permissions to function
116116
if ta.Spec.PrometheusCR.Enabled {
117117
saname := ta.Spec.ServiceAccount
118-
if len(ta.Spec.ServiceAccount) == 0 {
118+
if ta.Spec.ServiceAccount == "" {
119119
saname = naming.TargetAllocatorServiceAccount(ta.Name)
120120
}
121121
warnings, err := v1beta1.CheckTargetAllocatorPrometheusCRPolicyRules(ctx, w.reviewer, ta.GetNamespace(), saname)

apis/v1beta1/collector_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func (c CollectorWebhook) validateTargetAllocatorConfig(ctx context.Context, r *
359359
// if the prometheusCR is enabled, it needs a suite of permissions to function
360360
if r.Spec.TargetAllocator.PrometheusCR.Enabled {
361361
saname := r.Spec.TargetAllocator.ServiceAccount
362-
if len(r.Spec.TargetAllocator.ServiceAccount) == 0 {
362+
if r.Spec.TargetAllocator.ServiceAccount == "" {
363363
saname = naming.TargetAllocatorServiceAccount(r.Name)
364364
}
365365
warnings, err := CheckTargetAllocatorPrometheusCRPolicyRules(

cmd/operator-opamp-bridge/internal/agent/agent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (agent *Agent) generateCollectorPoolHealth() (map[string]*protobufs.Compone
159159

160160
// getCollectorSelector destructures the collectors scale selector if present, it uses the labelmap from the operator.
161161
func (*Agent) getCollectorSelector(col v1beta1.OpenTelemetryCollector) map[string]string {
162-
if len(col.Status.Scale.Selector) > 0 {
162+
if col.Status.Scale.Selector != "" {
163163
selMap := map[string]string{}
164164
for kvPair := range strings.SplitSeq(col.Status.Scale.Selector, ",") {
165165
kv := strings.Split(kvPair, "=")
@@ -401,7 +401,7 @@ func (agent *Agent) applyRemoteConfig(config *protobufs.AgentRemoteConfig) (*pro
401401
var errs []error
402402
// Apply changes from the received config map
403403
for key, file := range config.Config.GetConfigMap() {
404-
if len(key) == 0 || len(file.Body) == 0 {
404+
if key == "" || len(file.Body) == 0 {
405405
continue
406406
}
407407
colKey, err := kubeResourceFromKey(key)

cmd/operator-opamp-bridge/internal/operator/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func TestClient_Apply(t *testing.T) {
124124
c := NewClient(bridgeName, clientLogger, fakeClient, nil)
125125
var colConfig []byte
126126
var err error
127-
if len(tt.args.file) > 0 {
127+
if tt.args.file != "" {
128128
colConfig, err = loadConfig(tt.args.file)
129129
require.NoError(t, err, "Should be no error on loading test configuration")
130130
} else {

cmd/operator-opamp-bridge/internal/proxy/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (s *OpAMPProxy) onDisconnect(conn types.Connection) {
105105
defer s.mux.Unlock()
106106

107107
for instanceId := range s.connections[conn] {
108-
if hostName := s.agentsById[instanceId].GetHostname(); len(hostName) > 0 {
108+
if hostName := s.agentsById[instanceId].GetHostname(); hostName != "" {
109109
delete(s.agentsByHostName, hostName)
110110
}
111111
delete(s.agentsById, instanceId)
@@ -141,7 +141,7 @@ func (s *OpAMPProxy) onMessage(_ context.Context, conn types.Connection, msg *pr
141141
agentUpdated = true
142142
}
143143
agentUpdated = s.agentsById[instanceId].UpdateStatus(msg, response) || agentUpdated
144-
if hostName := s.agentsById[instanceId].GetHostname(); len(hostName) > 0 {
144+
if hostName := s.agentsById[instanceId].GetHostname(); hostName != "" {
145145
s.agentsByHostName[hostName] = instanceId
146146
}
147147
s.mux.Unlock()

cmd/otel-allocator/internal/server/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func TestServer_TargetsHandler(t *testing.T) {
165165
body := result.Body
166166
bodyBytes, err := io.ReadAll(body)
167167
assert.NoError(t, err)
168-
if len(tt.want.errString) != 0 {
168+
if tt.want.errString != "" {
169169
assert.EqualError(t, err, tt.want.errString)
170170
return
171171
}

internal/components/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (b Builder[ComponentConfigType]) WithDefaultsApplier(defaultsApplier Defaul
145145
func (b Builder[ComponentConfigType]) Build() (*GenericParser[ComponentConfigType], error) {
146146
o := NewEmptySettings[ComponentConfigType]()
147147
o.Apply(b...)
148-
if len(o.name) == 0 {
148+
if o.name == "" {
149149
return nil, errors.New("invalid settings struct, no name specified")
150150
}
151151
return &GenericParser[ComponentConfigType]{

internal/components/extensions/healthcheckv1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func healthCheckV1Probe(logger logr.Logger, config healthcheckV1Config) (*corev1
5151
// but since the function runs only when manifests are deployed,
5252
// we must keep these runtime defaults for backward compatibility.
5353
path := config.Path
54-
if len(path) == 0 {
54+
if path == "" {
5555
path = defaultHealthcheckV1Path
5656
}
5757
return &corev1.Probe{

0 commit comments

Comments
 (0)