From a0755797f52f70764b031642d4731594ff1cdab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=BBak?= Date: Thu, 5 Sep 2024 18:19:17 +0200 Subject: [PATCH] chore(linters): Enable `time-equal` rule for revive (#15838) --- .golangci.yml | 1 + agent/agent.go | 2 +- internal/internal.go | 2 +- plugins/inputs/intel_baseband/log_connector.go | 2 +- plugins/inputs/vsphere/vsan.go | 2 +- plugins/inputs/zipkin/codec/jsonV1/jsonV1_test.go | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 05fada7c3..7aa915d86 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -277,6 +277,7 @@ linters-settings: - name: string-of-int - name: struct-tag - name: superfluous-else + - name: time-equal - name: time-naming - name: unconditional-recursion - name: unexported-naming diff --git a/agent/agent.go b/agent/agent.go index 5d3f7dcf0..5d7cc033f 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -750,7 +750,7 @@ func updateWindow(start time.Time, roundInterval bool, period time.Duration) (ti var until time.Time if roundInterval { until = internal.AlignTime(start, period) - if until == start { + if until.Equal(start) { until = internal.AlignTime(start.Add(time.Nanosecond), period) } } else { diff --git a/internal/internal.go b/internal/internal.go index ac966413d..6f3ded575 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -174,7 +174,7 @@ func AlignDuration(tm time.Time, interval time.Duration) time.Duration { // If the current time is aligned the current time is returned. func AlignTime(tm time.Time, interval time.Duration) time.Time { truncated := tm.Truncate(interval) - if truncated == tm { + if truncated.Equal(tm) { return tm } return truncated.Add(interval) diff --git a/plugins/inputs/intel_baseband/log_connector.go b/plugins/inputs/intel_baseband/log_connector.go index f9379198b..023f81483 100644 --- a/plugins/inputs/intel_baseband/log_connector.go +++ b/plugins/inputs/intel_baseband/log_connector.go @@ -88,7 +88,7 @@ func (lc *logConnector) checkLogFreshness() error { // - modification time has been changed // - file is not empty // - file doesn't contain clear_log command (it may appear for few milliseconds, just before file is cleared) - if lc.lastModTime != currModTime && fileInfo.Size() != 0 && !lc.isClearLogContainedInFile() { + if !lc.lastModTime.Equal(currModTime) && fileInfo.Size() != 0 && !lc.isClearLogContainedInFile() { //refreshing succeed lc.lastModTime = currModTime return nil diff --git a/plugins/inputs/vsphere/vsan.go b/plugins/inputs/vsphere/vsan.go index 47c312e57..2c969910f 100644 --- a/plugins/inputs/vsphere/vsan.go +++ b/plugins/inputs/vsphere/vsan.go @@ -292,7 +292,7 @@ func (e *Endpoint) queryPerformance(ctx context.Context, vsanClient *soap.Client } if len(timeStamps) > 0 { lastSample := timeStamps[len(timeStamps)-1] - if lastSample != (time.Time{}) && lastSample.After(latest) { + if !lastSample.IsZero() && lastSample.After(latest) { latest = lastSample } } diff --git a/plugins/inputs/zipkin/codec/jsonV1/jsonV1_test.go b/plugins/inputs/zipkin/codec/jsonV1/jsonV1_test.go index 033e79a99..36ceba33a 100644 --- a/plugins/inputs/zipkin/codec/jsonV1/jsonV1_test.go +++ b/plugins/inputs/zipkin/codec/jsonV1/jsonV1_test.go @@ -703,7 +703,7 @@ func Test_annotation(t *testing.T) { t.Run(tt.name, func(t *testing.T) { an := annotation(tt.fields) a := &an - if got := a.Timestamp(); got != tt.tm { + if got := a.Timestamp(); !got.Equal(tt.tm) { t.Errorf("annotation.Timestamp() = %v, want %v", got, tt.tm) } if got := a.Value(); got != tt.val {