influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.43k stars 5.54k forks source link

gocritic->sloppyLen - Detects usage of `len` when result is obvious or doesn’t make sense. Should we enable it? #15498

Closed zak-pawel closed 2 months ago

zak-pawel commented 2 months ago

Description

This issue starts a discussion about enabling:

Example

Before:

len(arr) <= 0

After:

len(arr) == 0

Expected output

Decision about enabling or not enabling this checker.

Findings

For this checker, the following findings were found in the current codebase:

plugins/inputs/aerospike/aerospike.go:221:5                 gocritic  sloppyLen: len(a.Namespaces) <= 0 can be len(a.Namespaces) == 0
plugins/inputs/aerospike/aerospike.go:265:5                 gocritic  sloppyLen: len(a.Sets) <= 0 can be len(a.Sets) == 0
plugins/inputs/dovecot/dovecot.go:49:5                      gocritic  sloppyLen: len(d.Filters) <= 0 can be len(d.Filters) == 0
plugins/inputs/file/file.go:86:6                            gocritic  sloppyLen: len(files) <= 0 can be len(files) == 0
plugins/inputs/opcua_listener/opcua_listener_test.go:224:9  gocritic  sloppyLen: len(newRemaining) <= 0 can be len(newRemaining) == 0
plugins/inputs/opcua_listener/opcua_listener_test.go:364:9  gocritic  sloppyLen: len(newRemaining) <= 0 can be len(newRemaining) == 0
plugins/inputs/x509_cert/x509_cert.go:514:6                 gocritic  sloppyLen: len(files) <= 0 can be len(files) == 0

Additional configuration

For this checker, no additional configuration can be provided.

powersj commented 2 months ago

+1