forked from rhysd/actionlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrule_step_id.go
43 lines (36 loc) · 1.06 KB
/
rule_step_id.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
package actionlint
import "strings"
// RuleStepID is a rule to check step IDs in workflow.
type RuleStepID struct {
RuleBase
seen map[string]*Pos
}
// NewRuleStepID creates a new RuleStepID instance.
func NewRuleStepID() *RuleStepID {
return &RuleStepID{
RuleBase: RuleBase{name: "step-id"},
}
}
// VisitJobPre is callback when visiting Job node before visiting its children.
func (rule *RuleStepID) VisitJobPre(n *Job) error {
rule.seen = map[string]*Pos{}
return nil
}
// VisitJobPost is callback when visiting Job node after visiting its children.
func (rule *RuleStepID) VisitJobPost(n *Job) error {
rule.seen = nil
return nil
}
// VisitStep is callback when visiting Step node.
func (rule *RuleStepID) VisitStep(n *Step) error {
if n.ID == nil {
return nil
}
id := strings.ToLower(n.ID.Value)
if prev, ok := rule.seen[id]; ok {
rule.errorf(n.ID.Pos, "step ID %q duplicates. previously defined at %s. step ID must be unique within a job. note that step ID is case insensitive", n.ID.Value, prev.String())
return nil
}
rule.seen[id] = n.ID.Pos
return nil
}