Skip to content

Commit

Permalink
feat: prefer whenexpressions over conditions rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamas Muncsan authored and madbence committed Oct 10, 2020
1 parent db03020 commit e05a1d1
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions .tektonlintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ rules: # error | warning | off
no-unused-param: warning
no-missing-resource: error
no-undefined-param: error
prefer-when-expression: warning
1 change: 1 addition & 0 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ for (const problem of problems) {
- _kebab-case_ naming violations
- `Task` & `Pipeline` definitions with `tekton.dev/v1alpha1` `apiVersion`
- Missing `TriggerBinding` parameter values
- Usage of deprecated `Condition` instead of `WhenExpression`

[tekton]: https://tekton.dev
[node]: https://nodejs.org
Expand Down
32 changes: 32 additions & 0 deletions regression-tests/__snapshots__/regresion.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ Array [
"path": "./regression-tests/conditions.yaml",
"rule": "no-invalid-name",
},
Object {
"level": "warning",
"loc": Object {
"endColumn": 1,
"endLine": 43,
"range": Array [
773,
807,
],
"startColumn": 9,
"startLine": 42,
},
"message": "Task 'tekton-without-params' in Pipeline 'pipeline-with-missing-condition' is guarded by condition(s) ('missing-condition'). Conditions are deprecated, use WhenExpressions instead.",
"path": "./regression-tests/conditions.yaml",
"rule": "prefer-when-expression",
},
Object {
"level": "error",
"loc": Object {
Expand All @@ -194,6 +210,22 @@ Array [
"path": "./regression-tests/conditions.yaml",
"rule": "no-missing-resource",
},
Object {
"level": "warning",
"loc": Object {
"endColumn": 1,
"endLine": 56,
"range": Array [
1033,
1131,
],
"startColumn": 9,
"startLine": 54,
},
"message": "Task 'tekton-without-params' in Pipeline 'pipeline-with-multiple-conditions' is guarded by condition(s) ('condition-with-unused-params, condition-with-unused-params'). Conditions are deprecated, use WhenExpressions instead.",
"path": "./regression-tests/conditions.yaml",
"rule": "prefer-when-expression",
},
Object {
"level": "warning",
"loc": Object {
Expand Down
13 changes: 13 additions & 0 deletions regression-tests/conditions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,16 @@ spec:
name: task-without-params
conditions:
- conditionRef: missing-condition
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: pipeline-with-multiple-conditions
spec:
tasks:
- name: tekton-without-params
taskRef:
name: task-without-params
conditions:
- conditionRef: condition-with-unused-params
- conditionRef: condition-with-unused-params
3 changes: 3 additions & 0 deletions rule-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const rules = {

// prefer-kebab-case
'prefer-kebab-case': require('./rules/prefer-kebab-case.js'),

// prefer-when-expression
'prefer-when-expression': require('./rules/prefer-when-expression.js'),
};

module.exports = rules;
10 changes: 10 additions & 0 deletions rules/prefer-when-expression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = (docs, tekton, report) => {
for (const pipeline of Object.values(tekton.pipelines)) {
for (const task of pipeline.spec.tasks) {
if (task.conditions) {
const guardedBy = task.conditions.map(condition => condition.conditionRef);
report(`Task '${task.name}' in Pipeline '${pipeline.metadata.name}' is guarded by condition(s) ('${guardedBy.join(', ')}'). Conditions are deprecated, use WhenExpressions instead.`, task, 'conditions');
}
}
}
};

0 comments on commit e05a1d1

Please sign in to comment.