Skip to content

Commit a307c89

Browse files
committed
dsl: add experimental Do() action
Unlike `Report()` and `Suggest()`, new `Do()` method allows a more granular match action handling. Now it's possible to emit a conditional report/suggest message based on the matching context. The API is experimental and is likely to change.
1 parent 2e73e37 commit a307c89

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

dsl/do.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package dsl
2+
3+
import (
4+
"github.com/quasilyte/go-ruleguard/dsl/types"
5+
)
6+
7+
type DoContext struct{}
8+
9+
func (*DoContext) Var(varname string) *DoVar { return nil }
10+
11+
func (*DoContext) SetReport(report string) {}
12+
13+
func (*DoContext) SetSuggest(suggest string) {}
14+
15+
type DoVar struct{}
16+
17+
func (*DoVar) Text() string { return "" }
18+
19+
func (*DoVar) Type() types.Type { return nil }

dsl/dsl.go

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ func (m Matcher) Suggest(suggestion string) Matcher {
7878
return m
7979
}
8080

81+
func (m Matcher) Do(fn func(*DoContext)) Matcher {
82+
return m
83+
}
84+
8185
// At binds the reported node to a named submatch.
8286
// If no explicit location is given, the outermost node ($$) is used.
8387
func (m Matcher) At(v Var) Matcher {

0 commit comments

Comments
 (0)