forked from rhysd/actionlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrule_env_var.go
54 lines (47 loc) · 1.2 KB
/
rule_env_var.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 actionlint
import "strings"
// RuleEnvVar is a rule checker to check environment variables setup.
type RuleEnvVar struct {
RuleBase
}
// NewRuleEnvVar creates new RuleEnvVar instance.
func NewRuleEnvVar() *RuleEnvVar {
return &RuleEnvVar{
RuleBase: RuleBase{name: "env-var"},
}
}
// VisitStep is callback when visiting Step node.
func (rule *RuleEnvVar) VisitStep(n *Step) error {
rule.checkEnv(n.Env)
return nil
}
// VisitJobPre is callback when visiting Job node before visiting its children.
func (rule *RuleEnvVar) VisitJobPre(n *Job) error {
rule.checkEnv(n.Env)
if n.Container != nil {
rule.checkEnv(n.Container.Env)
}
for _, s := range n.Services {
rule.checkEnv(s.Container.Env)
}
return nil
}
// VisitWorkflowPre is callback when visiting Workflow node before visiting its children.
func (rule *RuleEnvVar) VisitWorkflowPre(n *Workflow) error {
rule.checkEnv(n.Env)
return nil
}
func (rule *RuleEnvVar) checkEnv(env *Env) {
if env == nil {
return
}
for _, v := range env.Vars {
if strings.ContainsAny(v.Name.Value, "&= ") {
rule.errorf(
v.Name.Pos,
"environment variable name %q is invalid. '&', '=' and spaces should not be contained",
v.Name.Value,
)
}
}
}