From a307c89fa379bf4dddcd630cc1a7d3e6ed845e2f Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Mon, 14 Feb 2022 01:42:12 +0300 Subject: [PATCH] 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. --- dsl/do.go | 19 +++++++++++++++++++ dsl/dsl.go | 4 ++++ 2 files changed, 23 insertions(+) create mode 100644 dsl/do.go diff --git a/dsl/do.go b/dsl/do.go new file mode 100644 index 0000000..86bc163 --- /dev/null +++ b/dsl/do.go @@ -0,0 +1,19 @@ +package dsl + +import ( + "github.com/quasilyte/go-ruleguard/dsl/types" +) + +type DoContext struct{} + +func (*DoContext) Var(varname string) *DoVar { return nil } + +func (*DoContext) SetReport(report string) {} + +func (*DoContext) SetSuggest(suggest string) {} + +type DoVar struct{} + +func (*DoVar) Text() string { return "" } + +func (*DoVar) Type() types.Type { return nil } diff --git a/dsl/dsl.go b/dsl/dsl.go index a374c9c..8ecb502 100644 --- a/dsl/dsl.go +++ b/dsl/dsl.go @@ -78,6 +78,10 @@ func (m Matcher) Suggest(suggestion string) Matcher { return m } +func (m Matcher) Do(fn func(*DoContext)) Matcher { + return m +} + // At binds the reported node to a named submatch. // If no explicit location is given, the outermost node ($$) is used. func (m Matcher) At(v Var) Matcher {