Skip to content

Commit

Permalink
add test rule
Browse files Browse the repository at this point in the history
  • Loading branch information
peakle committed Jan 3, 2022
1 parent e7cbb8b commit eb4080c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package main
import (
"fmt"
"strings"
"time"
)

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)
}
7 changes: 7 additions & 0 deletions rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
}

0 comments on commit eb4080c

Please sign in to comment.