diff --git a/pipeline/frontend/yaml/linter/linter.go b/pipeline/frontend/yaml/linter/linter.go index 3654de3df..81b88c967 100644 --- a/pipeline/frontend/yaml/linter/linter.go +++ b/pipeline/frontend/yaml/linter/linter.go @@ -342,8 +342,10 @@ func (l *Linter) lintBadHabits(config *WorkflowConfig) (err error) { // root whens do not necessarily have an event filter, check steps for _, step := range parsed.Steps.ContainerList { var field string + var msg string if len(step.When.Constraints) == 0 { field = fmt.Sprintf("steps.%s", step.Name) + msg = "Consider adding a `when` block with an `event` filter to this step or the entire workflow" } else { stepEventIndex := -1 for i, c := range step.When.Constraints { @@ -354,12 +356,13 @@ func (l *Linter) lintBadHabits(config *WorkflowConfig) (err error) { } if stepEventIndex > -1 { field = fmt.Sprintf("steps.%s.when[%d]", step.Name, stepEventIndex) + msg = "Set an event filter for all steps or the entire workflow on all items of the `when` block" } } if field != "" { err = multierr.Append(err, &pipeline_errors.PipelineError{ Type: pipeline_errors.PipelineErrorTypeBadHabit, - Message: "Set an event filter for all steps or the entire workflow on all items of the `when` block", + Message: msg, Data: pipeline_errors.BadHabitErrorData{ File: config.File, Field: field, diff --git a/pipeline/frontend/yaml/linter/linter_test.go b/pipeline/frontend/yaml/linter/linter_test.go index 8223042bf..33e9c7ad4 100644 --- a/pipeline/frontend/yaml/linter/linter_test.go +++ b/pipeline/frontend/yaml/linter/linter_test.go @@ -214,10 +214,14 @@ func TestBadHabits(t *testing.T) { }{ { from: "steps: { build: { image: golang } }", - want: "Set an event filter for all steps or the entire workflow on all items of the `when` block", + want: "Consider adding a `when` block with an `event` filter to this step or the entire workflow", }, { from: "when: [{branch: xyz}, {event: push}]\nsteps: { build: { image: golang } }", + want: "Consider adding a `when` block with an `event` filter to this step or the entire workflow", + }, + { + from: "steps: { build: { image: golang, when: [{branch: main}] } }", want: "Set an event filter for all steps or the entire workflow on all items of the `when` block", }, }