diff --git a/regression-tests/__snapshots__/regresion.test.js.snap b/regression-tests/__snapshots__/regresion.test.js.snap index 7baa1d8..029d4c8 100644 --- a/regression-tests/__snapshots__/regresion.test.js.snap +++ b/regression-tests/__snapshots__/regresion.test.js.snap @@ -3186,6 +3186,22 @@ Array [ "path": "./regression-tests/prefer-when-expression.yaml", "rule": "no-missing-resource", }, + Object { + "level": "warning", + "loc": Object { + "endColumn": 13, + "endLine": 35, + "range": Array [ + 676, + 714, + ], + "startColumn": 17, + "startLine": 34, + }, + "message": "Task 'task-1' in PipelineRun 'prefer-when-expression-run' is guarded by condition(s) ('condition'). Conditions are deprecated, use WhenExpressions instead.", + "path": "./regression-tests/prefer-when-expression.yaml", + "rule": "prefer-when-expression", + }, Object { "level": "error", "loc": Object { diff --git a/src/rules/prefer-when-expression.ts b/src/rules/prefer-when-expression.ts index 68a0eea..4970467 100644 --- a/src/rules/prefer-when-expression.ts +++ b/src/rules/prefer-when-expression.ts @@ -7,4 +7,18 @@ export default (docs, tekton, report) => { } } } + + for (const triggerTemplate of Object.values(tekton.triggerTemplates)) { + for (const crd of triggerTemplate.spec.resourcetemplates) { + if (crd.kind !== 'PipelineRun') continue; + const pipelineSpec = crd.spec.pipelineSpec; + if (!pipelineSpec || !pipelineSpec.tasks) continue; + for (const task of pipelineSpec.tasks) { + if (task.conditions) { + const guardedBy = task.conditions.map(condition => condition.conditionRef); + report(`Task '${task.name}' in PipelineRun '${crd.metadata.name}' is guarded by condition(s) ('${guardedBy.join(', ')}'). Conditions are deprecated, use WhenExpressions instead.`, task, 'conditions'); + } + } + } + } };