Skip to content

Commit

Permalink
fix: fix issue 36
Browse files Browse the repository at this point in the history
Signed-off-by: mbwhite <[email protected]>
  • Loading branch information
mbwhite committed Jan 9, 2024
1 parent 20a8288 commit 59d99c2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
48 changes: 24 additions & 24 deletions regression-tests/general/no-duplicate-param.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ metadata:
name: no-duplicate-param-1
spec:
params:
- name: foo
- name: triggerbinding-foo
value: foo
- name: foo
- name: triggerbinding-foo
value: foo
---
apiVersion: tekton.dev/v1beta1
Expand All @@ -16,18 +16,18 @@ metadata:
name: no-duplicate-param-2
spec:
params:
- name: foo
- name: foo
- name: pipeline-foo
- name: pipeline-foo
tasks:
- name: task
taskSpec:
params:
- name: foo
- name: foo
- name: pipelinetask-foo
- name: pipelinetask-foo
params:
- name: foo
- name: pipelinetask-foo
value: foo
- name: foo
- name: pipelinetask-foo
value: foo
---
apiVersion: tekton.dev/v1beta1
Expand All @@ -36,8 +36,8 @@ metadata:
name: no-duplicate-param-3
spec:
params:
- name: foo
- name: foo
- name: task-foo
- name: task-foo
steps: []
---
apiVersion: tekton.dev/v1alpha1
Expand All @@ -46,8 +46,8 @@ metadata:
name: no-duplicate-param-4
spec:
params:
- name: foo
- name: foo
- name: ttfoo
- name: ttfoo
resourcetemplates:
- apiVersion: v1
kind: ConfigMap
Expand All @@ -63,21 +63,21 @@ spec:
spec:
pipelineSpec:
params:
- name: foo
- name: foo
- name: psone
- name: psone
tasks:
- name: task
taskSpec:
params:
- name: foo
- name: foo
- name: taskspec-foo
- name: taskspec-foo
params:
- name: foo
value: foo
- name: foo
value: foo
- name: taskspec-foo
value: $(params.psone)
- name: taskspec-foo
value: $(params.psone)
params:
- name: foo
value: foo
- name: foo
value: foo
- name: psone
value: $(tt.params.ttfoo)
- name: psone
value: $(tt.params.ttfoo)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"message":"Duplicate param 'foo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[157,160,161],"startLine":10,"startColumn":13,"endLine":10,"endColumn":16}},{"message":"Duplicate param 'foo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[311,314,315],"startLine":20,"startColumn":13,"endLine":20,"endColumn":16}},{"message":"Duplicate param 'foo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[642,645,646],"startLine":40,"startColumn":13,"endLine":40,"endColumn":16}},{"message":"Duplicate param 'foo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[799,802,803],"startLine":50,"startColumn":13,"endLine":50,"endColumn":16}},{"message":"Duplicate param 'foo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[1522,1525,1526],"startLine":82,"startColumn":19,"endLine":82,"endColumn":22}},{"message":"Duplicate param 'foo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[488,491,492],"startLine":30,"startColumn":17,"endLine":30,"endColumn":20}},{"message":"Duplicate param 'foo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[413,416,417],"startLine":26,"startColumn":19,"endLine":26,"endColumn":22}},{"message":"Task 'no-duplicate-param-3' defines parameter 'foo', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[620,630,630],"startLine":39,"startColumn":7,"endLine":40,"endColumn":1}},{"message":"TriggerTemplate 'no-duplicate-param-4' defines parameter 'foo', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[777,787,787],"startLine":49,"startColumn":7,"endLine":50,"endColumn":1}},{"message":"Pipeline 'no-duplicate-param-2' defines parameter 'foo', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[289,299,299],"startLine":19,"startColumn":7,"endLine":20,"endColumn":1}}]
[{"message":"Duplicate param 'triggerbinding-foo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[172,190,191],"startLine":10,"startColumn":13,"endLine":10,"endColumn":31}},{"message":"Duplicate param 'pipeline-foo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[350,362,363],"startLine":20,"startColumn":13,"endLine":20,"endColumn":25}},{"message":"Duplicate param 'task-foo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[747,755,756],"startLine":40,"startColumn":13,"endLine":40,"endColumn":21}},{"message":"Duplicate param 'ttfoo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[911,916,917],"startLine":50,"startColumn":13,"endLine":50,"endColumn":18}},{"message":"Duplicate param 'psone'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[1717,1722,1723],"startLine":82,"startColumn":19,"endLine":82,"endColumn":24}},{"message":"Duplicate param 'psone'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[1269,1274,1275],"startLine":67,"startColumn":21,"endLine":67,"endColumn":26}},{"message":"Duplicate param 'taskspec-foo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[1567,1579,1580],"startLine":77,"startColumn":25,"endLine":77,"endColumn":37}},{"message":"Duplicate param 'taskspec-foo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[1430,1442,1443],"startLine":73,"startColumn":27,"endLine":73,"endColumn":39}},{"message":"Duplicate param 'pipelinetask-foo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[575,591,592],"startLine":30,"startColumn":17,"endLine":30,"endColumn":33}},{"message":"Duplicate param 'pipelinetask-foo'","rule":"no-duplicate-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[474,490,491],"startLine":26,"startColumn":19,"endLine":26,"endColumn":35}},{"message":"Undefined param 'psone' at .spec.resourcetemplates[1].spec.pipelineSpec.tasks[0].params[0].value in 'no-duplicate-param-4'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[1527,1542,1543],"startLine":76,"startColumn":26,"endLine":76,"endColumn":41}},{"message":"Undefined param 'psone' at .spec.resourcetemplates[1].spec.pipelineSpec.tasks[0].params[1].value in 'no-duplicate-param-4'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[1605,1620,1621],"startLine":78,"startColumn":26,"endLine":78,"endColumn":41}},{"message":"Task 'no-duplicate-param-3' defines parameter 'task-foo', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[720,735,735],"startLine":39,"startColumn":7,"endLine":40,"endColumn":1}},{"message":"Pipeline 'no-duplicate-param-2' defines parameter 'pipeline-foo', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/no-duplicate-param.yaml","loc":{"range":[319,338,338],"startLine":19,"startColumn":7,"endLine":20,"endColumn":1}}]
15 changes: 15 additions & 0 deletions src/rules/no-duplicate-param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function getParams(kind, spec) {
}

function checkParams(params, report) {
if (!params) return;
const names = new Set();
for (const param of params) {
if (names.has(param.name)) {
Expand All @@ -26,6 +27,20 @@ export default (docs, tekton, report) => {
for (const crd of template.spec.resourcetemplates) {
if (crd.kind !== 'PipelineRun') continue;
checkParams(getParams(crd.kind, crd.spec), report);

if (crd.spec.pipelineSpec) {
if (crd.spec.pipelineSpec.params) {
checkParams(crd.spec.pipelineSpec.params, report);
}
if (crd.spec.pipelineSpec.tasks) {
for (const t of crd.spec.pipelineSpec.tasks) {
checkParams(t.params, report);
if (t.taskSpec && t.taskSpec.params) {
checkParams(t.taskSpec.params, report);
}
}
}
}
}
}

Expand Down

0 comments on commit 59d99c2

Please sign in to comment.