Skip to content

Commit

Permalink
[chore] fix lint errors (#34724)
Browse files Browse the repository at this point in the history
Fix linter failures found in
#34664,
namely: no need to check whether a slice is nil if you already check its
length.
  • Loading branch information
songy23 authored Aug 16, 2024
1 parent eaa0888 commit 8fb6b92
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func makeHandler(t *testing.T, corCh chan<- *request, forcedRespCode *atomic.Val
switch r.Method {
case http.MethodGet:
match := getPathRegexp.FindStringSubmatch(r.URL.Path)
if match == nil || len(match) < 3 {
if len(match) < 3 {
rw.WriteHeader(404)
return
}
Expand All @@ -78,7 +78,7 @@ func makeHandler(t *testing.T, corCh chan<- *request, forcedRespCode *atomic.Val
return
case http.MethodPut:
match := putPathRegexp.FindStringSubmatch(r.URL.Path)
if match == nil || len(match) < 4 {
if len(match) < 4 {
rw.WriteHeader(404)
return
}
Expand All @@ -100,7 +100,7 @@ func makeHandler(t *testing.T, corCh chan<- *request, forcedRespCode *atomic.Val

case http.MethodDelete:
match := deletePathRegexp.FindStringSubmatch(r.URL.Path)
if match == nil || len(match) < 5 {
if len(match) < 5 {
rw.WriteHeader(404)
return
}
Expand Down
2 changes: 1 addition & 1 deletion extension/headerssetterextension/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (

// Validate checks if the extension configuration is valid
func (cfg *Config) Validate() error {
if cfg.HeadersConfig == nil || len(cfg.HeadersConfig) == 0 {
if len(cfg.HeadersConfig) == 0 {
return errMissingHeadersConfig
}
for _, header := range cfg.HeadersConfig {
Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/adapter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func convertInto(ent *entry.Entry, dest plog.LogRecord) {
copy(buffer[0:8], ent.SpanID)
dest.SetSpanID(buffer)
}
if ent.TraceFlags != nil && len(ent.TraceFlags) > 0 {
if len(ent.TraceFlags) > 0 {
// The 8 least significant bits are the trace flags as defined in W3C Trace
// Context specification. Don't override the 24 reserved bits.
flags := uint32(ent.TraceFlags[0])
Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/operator/transformer/retain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c Config) Build(set component.TelemetrySettings) (operator.Operator, error
if err != nil {
return nil, err
}
if c.Fields == nil || len(c.Fields) == 0 {
if len(c.Fields) == 0 {
return nil, fmt.Errorf("retain: 'fields' is empty")
}

Expand Down
2 changes: 1 addition & 1 deletion receiver/httpcheckreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (h *httpcheckScraper) start(ctx context.Context, host component.Host) (err

// scrape connects to the endpoint and produces metrics based on the response
func (h *httpcheckScraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
if h.clients == nil || len(h.clients) == 0 {
if len(h.clients) == 0 {
return pmetric.NewMetrics(), errClientNotInit
}

Expand Down
2 changes: 1 addition & 1 deletion receiver/mongodbatlasreceiver/log_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func decode4_2(logger *zap.Logger, r io.Reader) ([]model.LogEntry, error) {
}

submatches := mongo4_2LogRegex.FindStringSubmatch(scanner.Text())
if submatches == nil || len(submatches) != 6 {
if len(submatches) != 6 {
// Match failed for line; We will skip this line and continue processing others.
logger.Error("Entry did not match regex", zap.String("entry", scanner.Text()))
continue
Expand Down

0 comments on commit 8fb6b92

Please sign in to comment.