From eb4080c3a4bbdacc9a8d0a2524007f2884ca2c40 Mon Sep 17 00:00:00 2001 From: Denis Date: Mon, 3 Jan 2022 21:48:05 +0300 Subject: [PATCH] add test rule --- go.mod | 2 ++ go.sum | 2 ++ main.go | 4 +++- rules/rules.go | 7 +++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index cb8296b..65b75bd 100644 --- a/go.mod +++ b/go.mod @@ -3,3 +3,5 @@ module github.com/peakle/dc-rules-example go 1.17 require github.com/quasilyte/go-ruleguard/dsl v0.3.10 + +require github.com/delivery-club/delivery-club-rules v0.0.5 // indirect diff --git a/go.sum b/go.sum index 9267ce9..67761c4 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ +github.com/delivery-club/delivery-club-rules v0.0.5 h1:pD4TV7f7AG5ECOkNyMHoIEognVbE2DGlKAqRKeXWmww= +github.com/delivery-club/delivery-club-rules v0.0.5/go.mod h1:oLl0AXS1ImTjYYbl1sJKnWjAYgqOwR3L6cs4RATfeMs= github.com/quasilyte/go-ruleguard/dsl v0.3.10 h1:4tVlVVcBT+nNWoF+t/zrAMO13sHAqYotX1K12Gc8f8A= github.com/quasilyte/go-ruleguard/dsl v0.3.10/go.mod h1:KeCP03KrjuSO0H1kTuZQCWlQPulDV6YMIXmpQss17rU= diff --git a/main.go b/main.go index e322370..790c54a 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "strings" + "time" ) var msg = fmt.Sprintf("123") // rule match example @@ -10,5 +11,6 @@ var msg = fmt.Sprintf("123") // rule match example func main() { s := strings.Replace(msg, "1", "", -1) //rule match example - fmt.Println(s) + l := time.Now().Second() // rule match example + fmt.Println(s, l) } diff --git a/rules/rules.go b/rules/rules.go index 1468378..b2a64d7 100644 --- a/rules/rules.go +++ b/rules/rules.go @@ -12,3 +12,10 @@ func stringsSimplify(m dsl.Matcher) { Report(`this Replace call can be simplified`). Suggest(`strings.ReplaceAll($s, $old, $new)`) } + +func timeUtc(m dsl.Matcher) { + m.Match(`time.Now().$method`). + Where(!m["method"].Text.Matches(`UTC()`)). + Report("maybe UTC() call forgotten"). + At(m["method"]) +}