Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] add wastedassign linter #26522

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ linters:
- unconvert
- unparam
- unused
- wastedassign

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func histDataPointToSummary(dp pmetric.HistogramDataPoint) (float64, float64, fl
}

func estimateSingleBucketHistogram(dp pmetric.HistogramDataPoint) (float64, float64, float64) {
min, max, sum := 0.0, 0.0, 0.0
var min, max, sum float64

if dp.HasSum() {
sum = dp.Sum()
Expand Down
2 changes: 1 addition & 1 deletion exporter/prometheusremotewriteexporter/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (prwe *prweWAL) continuallyPopWALThenExport(ctx context.Context, signalStar
}
reqL = append(reqL, req)

shouldExport := false
var shouldExport bool
select {
case <-timer.C:
shouldExport = true
Expand Down
4 changes: 2 additions & 2 deletions exporter/sumologicexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (se *sumologicexporter) start(_ context.Context, host component.Host) (err
// so they can be handled by OTC retry mechanism
func (se *sumologicexporter) pushLogsData(ctx context.Context, ld plog.Logs) error {
var (
currentMetadata = newFields(pcommon.NewMap())
currentMetadata fields
previousMetadata = newFields(pcommon.NewMap())
errs error
droppedRecords []plog.LogRecord
Expand Down Expand Up @@ -233,7 +233,7 @@ func (se *sumologicexporter) pushLogsData(ctx context.Context, ld plog.Logs) err
// so they can be handle by the OTC retry mechanism
func (se *sumologicexporter) pushMetricsData(ctx context.Context, md pmetric.Metrics) error {
var (
currentMetadata = newFields(pcommon.NewMap())
currentMetadata fields
previousMetadata = newFields(pcommon.NewMap())
errs error
droppedRecords []metricPair
Expand Down
3 changes: 2 additions & 1 deletion pkg/ottl/contexts/internal/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func SetValue(value pcommon.Value, val interface{}) error {
}

func getIndexableValue(value pcommon.Value, keys []ottl.Key) (any, error) {
val, ok := value, false
val := value
var ok bool
for i := 0; i < len(keys); i++ {
switch val.Type() {
case pcommon.ValueTypeMap:
Expand Down
8 changes: 4 additions & 4 deletions receiver/mongodbatlasreceiver/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (s *logsReceiver) collectClusterLogs(clusters []mongodbatlas.Cluster, proje

func filterClusters(clusters []mongodbatlas.Cluster, projectCfg ProjectConfig) ([]mongodbatlas.Cluster, error) {
include, exclude := projectCfg.IncludeClusters, projectCfg.ExcludeClusters
whitelist := false
var allowed bool
var clusterNameSet map[string]struct{}
// check to include or exclude clusters
switch {
Expand All @@ -178,11 +178,11 @@ func filterClusters(clusters []mongodbatlas.Cluster, projectCfg ProjectConfig) (
return clusters, nil
// include is initialized
case len(include) > 0 && len(exclude) == 0:
whitelist = true
allowed = true
clusterNameSet = projectCfg.includesByClusterName
// exclude is initialized
case len(exclude) > 0 && len(include) == 0:
whitelist = false
allowed = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't needed is it?

clusterNameSet = projectCfg.excludesByClusterName
// both are initialized
default:
Expand All @@ -191,7 +191,7 @@ func filterClusters(clusters []mongodbatlas.Cluster, projectCfg ProjectConfig) (

var filtered []mongodbatlas.Cluster
for _, cluster := range clusters {
if _, ok := clusterNameSet[cluster.Name]; (!ok && !whitelist) || (ok && whitelist) {
if _, ok := clusterNameSet[cluster.Name]; (!ok && !allowed) || (ok && allowed) {
filtered = append(filtered, cluster)
}
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/prometheusreceiver/internal/metricfamily.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (mf *metricFamily) appendMetric(metrics pmetric.MetricSlice, trimSuffixes b
metric.SetDescription(mf.metadata.Help)
metric.SetUnit(prometheus.UnitWordToUCUM(mf.metadata.Unit))

pointCount := 0
var pointCount int

switch mf.mtype {
case pmetric.MetricTypeHistogram:
Expand Down
2 changes: 1 addition & 1 deletion receiver/prometheusreceiver/internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func timestampFromMs(timeAtMs int64) pcommon.Timestamp {
}

func getBoundary(metricType pmetric.MetricType, labels labels.Labels) (float64, error) {
val := ""
var val string
switch metricType {
case pmetric.MetricTypeHistogram:
val = labels.Get(model.BucketLabel)
Expand Down