-
Notifications
You must be signed in to change notification settings - Fork 20
/
legacy_extra.go
54 lines (45 loc) · 1.29 KB
/
legacy_extra.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
50
51
52
53
54
package issues
import (
"strings"
"github.com/nyaruka/goflow/envs"
"github.com/nyaruka/goflow/excellent/tools"
"github.com/nyaruka/goflow/flows"
)
func init() {
registerType(TypeLegacyExtra, LegacyExtraCheck)
}
// TypeLegacyExtra is our type for a use of @legacy_extra
const TypeLegacyExtra string = "legacy_extra"
// LegacyExtra is a legacy extra issue
type LegacyExtra struct {
baseIssue
}
func newLegacyExtra(nodeUUID flows.NodeUUID, actionUUID flows.ActionUUID, language envs.Language) *LegacyExtra {
return &LegacyExtra{
baseIssue: newBaseIssue(
TypeLegacyExtra,
nodeUUID,
actionUUID,
language,
"use of @legacy_extra in an expression",
),
}
}
// LegacyExtraCheck checks for legacy extra usage
func LegacyExtraCheck(sa flows.SessionAssets, flow flows.Flow, tpls []flows.ExtractedTemplate, refs []flows.ExtractedReference, report func(flows.Issue)) {
for _, t := range tpls {
usesLegacyExtra := false
tools.FindContextRefsInTemplate(t.Template, flows.RunContextTopLevels, func(path []string) {
if strings.ToLower(path[0]) == "legacy_extra" {
usesLegacyExtra = true
}
})
if usesLegacyExtra {
var actionUUID flows.ActionUUID
if t.Action != nil {
actionUUID = t.Action.UUID()
}
report(newLegacyExtra(t.Node.UUID(), actionUUID, t.Language))
}
}
}