chore(linters): Enable `time-equal` rule for revive (#15838)

This commit is contained in:
Paweł Żak 2024-09-05 18:19:17 +02:00 committed by GitHub
parent 83561960a5
commit a0755797f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 6 additions and 5 deletions

View File

@ -277,6 +277,7 @@ linters-settings:
- name: string-of-int - name: string-of-int
- name: struct-tag - name: struct-tag
- name: superfluous-else - name: superfluous-else
- name: time-equal
- name: time-naming - name: time-naming
- name: unconditional-recursion - name: unconditional-recursion
- name: unexported-naming - name: unexported-naming

View File

@ -750,7 +750,7 @@ func updateWindow(start time.Time, roundInterval bool, period time.Duration) (ti
var until time.Time var until time.Time
if roundInterval { if roundInterval {
until = internal.AlignTime(start, period) until = internal.AlignTime(start, period)
if until == start { if until.Equal(start) {
until = internal.AlignTime(start.Add(time.Nanosecond), period) until = internal.AlignTime(start.Add(time.Nanosecond), period)
} }
} else { } else {

View File

@ -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. // If the current time is aligned the current time is returned.
func AlignTime(tm time.Time, interval time.Duration) time.Time { func AlignTime(tm time.Time, interval time.Duration) time.Time {
truncated := tm.Truncate(interval) truncated := tm.Truncate(interval)
if truncated == tm { if truncated.Equal(tm) {
return tm return tm
} }
return truncated.Add(interval) return truncated.Add(interval)

View File

@ -88,7 +88,7 @@ func (lc *logConnector) checkLogFreshness() error {
// - modification time has been changed // - modification time has been changed
// - file is not empty // - file is not empty
// - file doesn't contain clear_log command (it may appear for few milliseconds, just before file is cleared) // - 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 //refreshing succeed
lc.lastModTime = currModTime lc.lastModTime = currModTime
return nil return nil

View File

@ -292,7 +292,7 @@ func (e *Endpoint) queryPerformance(ctx context.Context, vsanClient *soap.Client
} }
if len(timeStamps) > 0 { if len(timeStamps) > 0 {
lastSample := timeStamps[len(timeStamps)-1] lastSample := timeStamps[len(timeStamps)-1]
if lastSample != (time.Time{}) && lastSample.After(latest) { if !lastSample.IsZero() && lastSample.After(latest) {
latest = lastSample latest = lastSample
} }
} }

View File

@ -703,7 +703,7 @@ func Test_annotation(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
an := annotation(tt.fields) an := annotation(tt.fields)
a := &an 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) t.Errorf("annotation.Timestamp() = %v, want %v", got, tt.tm)
} }
if got := a.Value(); got != tt.val { if got := a.Value(); got != tt.val {