Skip to content

Commit

Permalink
[chore]: enable nolintlint (#37351)
Browse files Browse the repository at this point in the history
#### Description

[nolintlint](https://golangci-lint.run/usage/linters/#nolintlint):
Reports ill-formed or insufficient nolint directives.

Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 authored Jan 24, 2025
1 parent 6a7f685 commit a05740a
Show file tree
Hide file tree
Showing 62 changed files with 75 additions and 121 deletions.
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ linters-settings:
explicit-exhaustive-switch: true
ignore-enum-members: "pmetric.MetricTypeEmpty"

nolintlint:
require-specific: true

predeclared:
ignore: copy

Expand Down Expand Up @@ -201,6 +204,7 @@ linters:
- gosec
- govet
- misspell
- nolintlint
- predeclared
- reassign
- revive
Expand All @@ -227,3 +231,7 @@ issues:
- text: "G115:"
linters:
- gosec
- path: "pagefile.go" # This exclusion is required for Windows only
text: "cachedBytes"
linters:
- unused
2 changes: 0 additions & 2 deletions cmd/telemetrygen/internal/logs/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ func (w worker) simulateLogs(res *resource.Resource, exporterFunc func() (sdklog

if w.spanID != "" {
// we checked this for errors in the Validate function
// nolint: errcheck
b, _ := hex.DecodeString(w.spanID)
sid = trace.SpanID(b)
}
if w.traceID != "" {
// we checked this for errors in the Validate function
// nolint: errcheck
b, _ := hex.DecodeString(w.traceID)
tid = trace.TraceID(b)
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/telemetrygen/internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,12 @@ func exemplarsFromConfig(c *Config) []metricdata.Exemplar[int64] {

if c.TraceID != "" {
// we validated this already during the Validate() function for config
// nolint: errcheck
traceID, _ := hex.DecodeString(c.TraceID)
exemplar.TraceID = traceID
}

if c.SpanID != "" {
// we validated this already during the Validate() function for config
// nolint: errcheck
spanID, _ := hex.DecodeString(c.SpanID)
exemplar.SpanID = spanID
}
Expand Down
2 changes: 0 additions & 2 deletions connector/datadogconnector/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ func TestExamples(t *testing.T) {
t.Setenv("DD_API_KEY", "aaaaaaaaa")
factories := newTestComponents(t)
const configFile = "./examples/config.yaml"
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33594
// nolint:staticcheck
_, err := otelcoltest.LoadConfigAndValidate(configFile, factories)
require.NoError(t, err, "All yaml config must validate. Please ensure that all necessary component factories are added in newTestComponents()")
}
Expand Down
2 changes: 0 additions & 2 deletions connector/servicegraphconnector/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ func TestLoadConfig(t *testing.T) {
require.NoError(t, err)

factories.Connectors[metadata.Type] = NewFactory()
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33594
// nolint:staticcheck
cfg, err := otelcoltest.LoadConfigAndValidate(filepath.Join("testdata", "service-graph-connector-config.yaml"), factories)

// Verify
Expand Down
2 changes: 1 addition & 1 deletion connector/servicegraphconnector/internal/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s *Store) Expire() {
defer s.mtx.Unlock()

// Iterates until no more items can be evicted
for s.tryEvictHead() { // nolint
for s.tryEvictHead() {
}
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/awskinesisexporter/internal/batch/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"errors"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/kinesis/types" //nolint:staticcheck // Some encoding types uses legacy prototype version
"github.com/aws/aws-sdk-go-v2/service/kinesis/types"
"go.opentelemetry.io/collector/consumer/consumererror"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awskinesisexporter/internal/compress"
Expand Down
10 changes: 0 additions & 10 deletions exporter/awss3exporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ func TestLoadConfig(t *testing.T) {

factory := NewFactory()
factories.Exporters[metadata.Type] = factory
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33594
// nolint:staticcheck
cfg, err := otelcoltest.LoadConfigAndValidate(filepath.Join("testdata", "default.yaml"), factories)

require.NoError(t, err)
Expand Down Expand Up @@ -57,8 +55,6 @@ func TestConfig(t *testing.T) {

factory := NewFactory()
factories.Exporters[factory.Type()] = factory
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33594
// nolint:staticcheck
cfg, err := otelcoltest.LoadConfigAndValidate(
filepath.Join("testdata", "config.yaml"), factories)

Expand Down Expand Up @@ -93,8 +89,6 @@ func TestConfigForS3CompatibleSystems(t *testing.T) {

factory := NewFactory()
factories.Exporters[factory.Type()] = factory
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33594
// nolint:staticcheck
cfg, err := otelcoltest.LoadConfigAndValidate(
filepath.Join("testdata", "config-s3-compatible-systems.yaml"), factories)

Expand Down Expand Up @@ -209,8 +203,6 @@ func TestMarshallerName(t *testing.T) {

factory := NewFactory()
factories.Exporters[factory.Type()] = factory
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33594
// nolint:staticcheck
cfg, err := otelcoltest.LoadConfigAndValidate(
filepath.Join("testdata", "marshaler.yaml"), factories)

Expand Down Expand Up @@ -253,8 +245,6 @@ func TestCompressionName(t *testing.T) {

factory := NewFactory()
factories.Exporters[factory.Type()] = factory
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33594
// nolint:staticcheck
cfg, err := otelcoltest.LoadConfigAndValidate(
filepath.Join("testdata", "compression.yaml"), factories)

Expand Down
2 changes: 1 addition & 1 deletion exporter/awss3exporter/internal/upload/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (sw *s3manager) Upload(ctx context.Context, data []byte) error {
}

func (sw *s3manager) contentBuffer(raw []byte) (*bytes.Buffer, error) {
//nolint: gocritic // Leaving this as a switch statement to make it easier to add more later compressions
//nolint:gocritic // Leaving this as a switch statement to make it easier to add more later compressions
switch sw.builder.Compression {
case configcompression.TypeGzip:
content := bytes.NewBuffer(nil)
Expand Down
1 change: 0 additions & 1 deletion exporter/clickhouseexporter/exporter_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ func mustPushMetricsData(t *testing.T, exporter *metricsExporter, md pmetric.Met
require.NoError(t, err)
}

// nolint:unparam // not need to check this func
func newTestMetricsExporter(t *testing.T, dsn string, fns ...func(*Config)) *metricsExporter {
exporter, err := newMetricsExporter(zaptest.NewLogger(t), withTestExporterConfig(fns...)(dsn))
require.NoError(t, err)
Expand Down
4 changes: 0 additions & 4 deletions exporter/datadogexporter/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ func TestExamples(t *testing.T) {
t.Run(filepath.Base(f.Name()), func(t *testing.T) {
t.Setenv("DD_API_KEY", "aaaaaaaaa")
name := filepath.Join(folder, f.Name())
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33594
// nolint:staticcheck
_, err := otelcoltest.LoadConfigAndValidate(name, factories)
require.NoError(t, err, "All yaml config must validate. Please ensure that all necessary component factories are added in newTestComponents()")
})
Expand Down Expand Up @@ -85,8 +83,6 @@ func TestExamples(t *testing.T) {
require.Len(t, data, n)
require.NoError(t, f.Close())
defer os.RemoveAll(f.Name())
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33594
// nolint:staticcheck
_, err = otelcoltest.LoadConfigAndValidate(f.Name(), factories)
require.NoError(t, err, "All yaml config must validate. Please ensure that all necessary component factories are added in newTestComponents()")
})
Expand Down
2 changes: 0 additions & 2 deletions exporter/datadogexporter/integrationtest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ func getIntegrationTestComponents(t *testing.T) otelcol.Factories {
}

func getIntegrationTestCollector(t *testing.T, cfgFile string, factories otelcol.Factories) *otelcol.Collector {
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33594
// nolint:staticcheck
_, err := otelcoltest.LoadConfigAndValidate(cfgFile, factories)
require.NoError(t, err, "All yaml config must be valid.")

Expand Down
2 changes: 1 addition & 1 deletion exporter/datadogexporter/internal/metrics/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *Consumer) runningMetrics(timestamp uint64, buildInfo component.BuildInf
}

for _, lang := range metadata.Languages {
tags := append(buildTags, "language:"+lang) // nolint
tags := append(buildTags, "language:"+lang) //nolint:gocritic
runningMetric := DefaultMetrics("runtime_metrics", "", timestamp, tags)
series = append(series, runningMetric...)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ func safeUint64ToInt64(v uint64) int64 {
if v > math.MaxInt64 {
return math.MaxInt64
}
return int64(v) // nolint:goset // overflow checked
return int64(v) //nolint:goset // overflow checked
}
4 changes: 2 additions & 2 deletions exporter/elasticsearchexporter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ func valueHash(h hash.Hash, v pcommon.Value) {
h.Write(buf)
case pcommon.ValueTypeInt:
buf := make([]byte, 8)
binary.LittleEndian.PutUint64(buf, uint64(v.Int())) // nolint:gosec // Overflow assumed. We prefer having high integers over zero.
binary.LittleEndian.PutUint64(buf, uint64(v.Int()))
h.Write(buf)
case pcommon.ValueTypeBytes:
h.Write(v.Bytes().AsRaw())
Expand All @@ -796,5 +796,5 @@ func safeUint64ToInt64(v uint64) int64 {
if v > math.MaxInt64 {
return math.MaxInt64
}
return int64(v) // nolint:goset // overflow checked
return int64(v) //nolint:goset // overflow checked
}
2 changes: 1 addition & 1 deletion exporter/elasticsearchexporter/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ func TestEncodeLogBodyMapMode(t *testing.T) {
resourceLogs := logs.ResourceLogs().AppendEmpty()
scopeLogs := resourceLogs.ScopeLogs().AppendEmpty()
logRecords := scopeLogs.LogRecords()
observedTimestamp := pcommon.Timestamp(time.Now().UnixNano()) // nolint:gosec // UnixNano is positive and thus safe to convert to signed integer.
observedTimestamp := pcommon.Timestamp(time.Now().UnixNano())

logRecord := logRecords.AppendEmpty()
logRecord.SetObservedTimestamp(observedTimestamp)
Expand Down
4 changes: 2 additions & 2 deletions exporter/elasticsearchexporter/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func itemRequestsSortFunc(a, b itemRequest) int {
return comp
}

func assertRecordedItems(t *testing.T, expected []itemRequest, recorder *bulkRecorder, assertOrder bool) { // nolint:unparam
func assertRecordedItems(t *testing.T, expected []itemRequest, recorder *bulkRecorder, assertOrder bool) { //nolint:unparam
recorder.WaitItems(len(expected))
assertItemRequests(t, expected, recorder.Items(), assertOrder)
}

func assertItemRequests(t *testing.T, expected, actual []itemRequest, assertOrder bool) { // nolint:unparam
func assertItemRequests(t *testing.T, expected, actual []itemRequest, assertOrder bool) {
expectedItems := expected
actualItems := actual
if !assertOrder {
Expand Down
2 changes: 0 additions & 2 deletions exporter/googlemanagedprometheusexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ func TestLoadConfig(t *testing.T) {

factory := NewFactory()
factories.Exporters[metadata.Type] = factory
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33594
// nolint:staticcheck
cfg, err := otelcoltest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories)

require.NoError(t, err)
Expand Down
2 changes: 0 additions & 2 deletions exporter/loadbalancingexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ func TestBuildExporterConfig(t *testing.T) {
require.NoError(t, err)

factories.Exporters[metadata.Type] = NewFactory()
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33594
// nolint:staticcheck
cfg, err := otelcoltest.LoadConfigAndValidate(filepath.Join("testdata", "test-build-exporter-config.yaml"), factories)
require.NoError(t, err)
require.NotNil(t, cfg)
Expand Down
2 changes: 1 addition & 1 deletion exporter/opensearchexporter/internal/objmodel/objmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// Ingest Node is used. But either way, we try to present only well formed
// document to OpenSearch.

// nolint:errcheck
//nolint:errcheck
package objmodel // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opensearchexporter/internal/objmodel"

import (
Expand Down
3 changes: 1 addition & 2 deletions exporter/prometheusexporter/end_to_end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ func TestEndToEndSummarySupport(t *testing.T) {
require.Empty(t, prometheusExporterScrape, "Left-over unmatched Prometheus scrape content: %q\n", prometheusExporterScrape)
}

// the following triggers G101: Potential hardcoded credentials
// nolint:gosec
//nolint:gosec // the following triggers G101: Potential hardcoded credentials
const dropWizardResponse = `
# HELP jvm_memory_pool_bytes_used Used bytes of a given JVM memory pool.
# TYPE jvm_memory_pool_bytes_used gauge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
deletePathRegexp = regexp.MustCompile(`/v2/apm/correlate/([^/]+)/([^/]+)/([^/]+)/([^/]+)`) // /dimName/dimValue/{service,environment}/value
)

func waitForCors(corCh <-chan *request, count, waitSeconds int) []*request { // nolint: unparam
func waitForCors(corCh <-chan *request, count, waitSeconds int) []*request { //nolint:unparam
cors := make([]*request, 0, count)
timeout := time.After(time.Duration(waitSeconds) * time.Second)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (a *ActiveServiceTracker) processEnvironment(res pcommon.Resource, now time
if err == nil {
a.hostEnvironmentCache.UpdateOrCreate(&CacheKey{value: environment}, now)
}
// nolint:errorlint
//nolint:errorlint
if maxEntry, ok := err.(*correlations.ErrMaxEntries); ok && maxEntry.MaxEntries > 0 {
a.hostEnvironmentCache.SetMaxSize(maxEntry.MaxEntries, now)
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func (a *ActiveServiceTracker) processService(res pcommon.Resource, now time.Tim
if err == nil {
a.hostServiceCache.UpdateOrCreate(&CacheKey{value: service}, now)
}
// nolint:errorlint
//nolint:errorlint
if maxEntry, ok := err.(*correlations.ErrMaxEntries); ok && maxEntry.MaxEntries > 0 {
a.hostServiceCache.SetMaxSize(maxEntry.MaxEntries, now)
}
Expand Down
2 changes: 1 addition & 1 deletion extension/jaegerremotesampling/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func logDeprecation(logger *zap.Logger) {
})
}

// nolint
//nolint:unused
var protoGate = featuregate.GlobalRegistry().MustRegister(
"extension.jaegerremotesampling.replaceThriftWithProto",
featuregate.StageStable,
Expand Down
2 changes: 1 addition & 1 deletion internal/aws/metrics/metric_calculator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func TestSweep(t *testing.T) {
assert.LessOrEqual(t, time.Since(sweepTime), mwe.ttl)
}
require.NoError(t, mwe.Shutdown())
for range sweepEvent { // nolint
for range sweepEvent { //nolint:revive
}
assert.True(t, closed.Load(), "Sweeper did not terminate.")
}
4 changes: 2 additions & 2 deletions internal/otelarrow/test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func makeTestTraces(i int) ptrace.Traces {

func bulkyGenFunc() MkGen {
return func() GenFunc {
entropy := datagen.NewTestEntropy(int64(rand.Uint64())) //nolint:gosec // only used for testing
entropy := datagen.NewTestEntropy(int64(rand.Uint64()))

tracesGen := datagen.NewTracesGenerator(
entropy,
Expand Down Expand Up @@ -627,7 +627,7 @@ func nearLimitGenFunc() MkGen {
const hardLimit = 1 << 20 // 1 MiB

return func() GenFunc {
entropy := datagen.NewTestEntropy(int64(rand.Uint64())) //nolint:gosec // only used for testing
entropy := datagen.NewTestEntropy(int64(rand.Uint64()))

tracesGen := datagen.NewTracesGenerator(
entropy,
Expand Down
6 changes: 3 additions & 3 deletions pkg/experimentalmetricmetadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package experimentalmetricmetadata // import "github.com/open-telemetry/opentele
// MetadataExporter provides an interface to implement
// ConsumeMetadata in Exporters that support metadata.
// Type, functionality, and interface not guaranteed to be stable or permanent.
type MetadataExporter interface { //nolint
type MetadataExporter interface {
// ConsumeMetadata will be invoked every time there's an
// update to a resource that results in one or more MetadataUpdate.
ConsumeMetadata(metadata []*MetadataUpdate) error
Expand Down Expand Up @@ -34,7 +34,7 @@ type ResourceID string
// Apart from Kubernetes labels, the other metadata collected by this
// receiver are also handled in the same manner.
// Type, functionality, and fields not guaranteed to be stable or permanent.
type MetadataDelta struct { //nolint
type MetadataDelta struct {
// MetadataToAdd contains key-value pairs that are newly added to
// the resource description in the current revision.
MetadataToAdd map[string]string
Expand All @@ -49,7 +49,7 @@ type MetadataDelta struct { //nolint
// MetadataUpdate provides a delta view of metadata on a resource between
// two revisions of a resource.
// Type, functionality, and fields not guaranteed to be stable or permanent.
type MetadataUpdate struct { //nolint
type MetadataUpdate struct {
// ResourceIDKey is the label key of UID label for the resource.
ResourceIDKey string
// ResourceID is the Kubernetes UID of the resource. In case of
Expand Down
Loading

0 comments on commit a05740a

Please sign in to comment.