forked from redpanda-data/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bloblang.go
49 lines (46 loc) · 1.23 KB
/
bloblang.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package docs
import (
"github.com/dafanshu/benthos/v4/public/bloblang"
)
// LintBloblangMapping is function for linting a config field expected to be a
// bloblang mapping.
func LintBloblangMapping(ctx LintContext, line, col int, v any) []Lint {
str, ok := v.(string)
if !ok {
return nil
}
if str == "" {
return nil
}
_, err := ctx.BloblangEnv.Parse(str)
if err == nil {
return nil
}
if mErr, ok := err.(*bloblang.ParseError); ok {
lint := NewLintError(line+mErr.Line-1, LintBadBloblang, mErr.ErrorMultiline())
lint.Column = col + mErr.Column
return []Lint{lint}
}
return []Lint{NewLintError(line, LintBadBloblang, err.Error())}
}
// LintBloblangField is function for linting a config field expected to be an
// interpolation string.
func LintBloblangField(ctx LintContext, line, col int, v any) []Lint {
str, ok := v.(string)
if !ok {
return nil
}
if str == "" {
return nil
}
err := ctx.BloblangEnv.CheckInterpolatedString(str)
if err == nil {
return nil
}
if mErr, ok := err.(*bloblang.ParseError); ok {
lint := NewLintError(line+mErr.Line-1, LintBadBloblang, mErr.ErrorMultiline())
lint.Column = col + mErr.Column
return []Lint{lint}
}
return []Lint{NewLintError(line, LintBadBloblang, err.Error())}
}