Skip to content

Commit

Permalink
feat: report duplicated env vars in stepTemplate.env
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamas Muncsan authored and madbence committed Oct 27, 2020
1 parent 961ff93 commit 5c1baa2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions regression-tests/__snapshots__/regresion.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,22 @@ Array [
"path": "./regression-tests/no-duplicate-env.yaml",
"rule": "no-latest-image",
},
Object {
"level": "error",
"loc": Object {
"endColumn": 18,
"endLine": 48,
"range": Array [
733,
736,
],
"startColumn": 15,
"startLine": 48,
},
"message": "StepTemplate has env variable 'FOO' duplicated in task 'no-duplicate-env-2'.",
"path": "./regression-tests/no-duplicate-env.yaml",
"rule": "no-duplicate-env",
},
Object {
"level": "warning",
"loc": Object {
Expand Down
11 changes: 11 additions & 0 deletions src/rules/no-duplicate-env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
export default (docs, tekton, report) => {
for (const task of Object.values<any>(tekton.tasks)) {
if (task.spec.stepTemplate && task.spec.stepTemplate.env) {
const templateEnvVars = new Set();
for (const env of task.spec.stepTemplate.env) {
if (!templateEnvVars.has(env.name)) {
templateEnvVars.add(env.name);
} else {
report(`StepTemplate has env variable '${env.name}' duplicated in task '${task.metadata.name}'.`, env, 'name');
}
}
}

for (const step of task.spec.steps) {
if (!step.env) continue;
const envVariables = new Set();
Expand Down

0 comments on commit 5c1baa2

Please sign in to comment.