Skip to content

Conversation

quasilyte
Copy link
Member

The checker suggested a change that is not equivalent to the code being replaced. The results were different when the time values were identical.

This issue has no obvious fix, so the checker is removed completely. It was marked as experimental after all.

Fixes #1257

@quasilyte quasilyte requested a review from cristaloleg October 13, 2022 17:59
Copy link
Member

@cristaloleg cristaloleg left a comment

Choose a reason for hiding this comment

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

Sad but true.

@jufemaiz
Copy link

jufemaiz commented Jan 4, 2023

LGTM.

The alternative would be:

//doc:summary Detects Before/After call of time.Time that can be simplified
//doc:tags    style experimental
//doc:before  !t.Before(tt)
//doc:after   (t.After(tt) || t.Equal(tt))
func timeCmpSimplify(m dsl.Matcher) {
	isTime := func(v dsl.Var) bool {
		return v.Type.Is(`time.Time`) || v.Type.Is(`*time.Time`)
	}

	m.Match(`!$t.Before($tt)`).
		Where(isTime(m["t"])).
		Suggest("($t.After($tt) || $t.Equal($tt))")

	m.Match(`!$t.After($tt)`).
		Where(isTime(m["t"])).
		Suggest("($t.Before($tt) || $t.Equal($tt))")
}

@jufemaiz
Copy link

A year on should this get a move on and merged in?

@cristaloleg
Copy link
Member

Indeed, I will merge this today, thanks for the reminder.

The checker suggested a change that is not equivalent to the code
being replaced. The results were different when the time values
were identical.

This issue has no obvious fix, so the checker is removed completely.
It was marked as experimental after all.

Fixes #1257
@cristaloleg cristaloleg force-pushed the quasilyte/remove_timecmpsimplify branch from b95390c to c87bdc7 Compare February 15, 2024 10:11
@cristaloleg cristaloleg merged commit 4ff6063 into master Feb 15, 2024
@cristaloleg cristaloleg deleted the quasilyte/remove_timecmpsimplify branch February 15, 2024 10:15
akhilerm added a commit to akhilerm/publishing-bot that referenced this pull request Sep 19, 2024
Ref: go-critic/go-critic#1281
Signed-off-by: Akhil Mohan <akhilerm@gmail.com>
akhilerm added a commit to akhilerm/publishing-bot that referenced this pull request Sep 21, 2024
Ref: go-critic/go-critic#1281
Signed-off-by: Akhil Mohan <akhilerm@gmail.com>
akhilerm added a commit to akhilerm/publishing-bot that referenced this pull request Sep 21, 2024
Ref: go-critic/go-critic#1281
Signed-off-by: Akhil Mohan <akhilerm@gmail.com>
akhilerm added a commit to akhilerm/publishing-bot that referenced this pull request Sep 26, 2024
Ref: go-critic/go-critic#1281
Signed-off-by: Akhil Mohan <akhilerm@gmail.com>
akhilerm added a commit to akhilerm/publishing-bot that referenced this pull request Sep 27, 2024
Ref: go-critic/go-critic#1281
Signed-off-by: Akhil Mohan <akhilerm@gmail.com>
k8s-ci-robot pushed a commit to kubernetes/publishing-bot that referenced this pull request Sep 30, 2024
* update to go1.22.7

Signed-off-by: Akhil Mohan <akhilerm@gmail.com>

* update golangci-lint to v1.61.0

Signed-off-by: Akhil Mohan <akhilerm@gmail.com>

* removed sloppyTestFuncName

Ref: go-critic/go-critic#1376
Signed-off-by: Akhil Mohan <akhilerm@gmail.com>

* removed timeCmpSimplify

Ref: go-critic/go-critic#1281
Signed-off-by: Akhil Mohan <akhilerm@gmail.com>

* fix errors reported by emptyStringTest linter

Signed-off-by: Akhil Mohan <akhilerm@gmail.com>

* removed goerr113 and perfsprint

goerr113 and perfsprint linters are removed since the fixes reduces the readability

Signed-off-by: Akhil Mohan <akhilerm@gmail.com>

---------

Signed-off-by: Akhil Mohan <akhilerm@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

timeCmpSimplify rule is wrong
3 participants