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

add time range expr simplify #1220

Merged
merged 6 commits into from Apr 29, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions checkers/rules/rules.go
Expand Up @@ -655,6 +655,24 @@ func timeExprSimplify(m dsl.Matcher) {
Report(`use $t.UnixMicro() instead of $$`)
}

//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)
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)")

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

//doc:summary Detects exposed methods from sync.Mutex and sync.RWMutex
//doc:tags style experimental
//doc:before type Foo struct{ ...; sync.Mutex; ... }
Expand Down
185 changes: 125 additions & 60 deletions checkers/rulesdata/rulesdata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.