Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report duplicated env vars in merged env #68

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -930,6 +930,22 @@ Array [
"path": "./regression-tests/no-duplicate-env.yaml",
"rule": "no-latest-image",
},
Object {
"level": "error",
"loc": Object {
"endColumn": 20,
"endLine": 71,
"range": Array [
1085,
1088,
],
"startColumn": 17,
"startLine": 71,
},
"message": "StepTemplate in task 'no-duplicate-env-3' and Step 'step-1' define the same env variable.",
"path": "./regression-tests/no-duplicate-env.yaml",
"rule": "no-duplicate-env",
},
Object {
"level": "error",
"loc": Object {
Expand Down
5 changes: 4 additions & 1 deletion src/rules/no-duplicate-env.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default (docs, tekton, report) => {
for (const task of Object.values<any>(tekton.tasks)) {
const templateEnvVars = new Set();
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);
Expand All @@ -20,6 +20,9 @@ export default (docs, tekton, report) => {
} else {
report(`Step '${step.name}' has env variable '${env.name}' duplicated in task '${task.metadata.name}'.`, env, 'name');
}
if (templateEnvVars.has(env.name)) {
report(`StepTemplate in task '${task.metadata.name}' and Step '${step.name}' define the same env variable.`, env, 'name');
}
}
}
}
Expand Down
Loading