From 85892658465cb0d625ac11fa7c5e596986d40837 Mon Sep 17 00:00:00 2001 From: mbwhite Date: Tue, 9 Jan 2024 17:48:42 +0000 Subject: [PATCH] fix: fix issue 36 Signed-off-by: mbwhite --- .../general/no-duplicate-param.yaml | 48 +++++++++---------- .../no-duplicate-param.yaml.expect.json | 2 +- src/rules/no-duplicate-param.ts | 15 ++++++ 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/regression-tests/general/no-duplicate-param.yaml b/regression-tests/general/no-duplicate-param.yaml index 36f8e7c..7e2c75e 100644 --- a/regression-tests/general/no-duplicate-param.yaml +++ b/regression-tests/general/no-duplicate-param.yaml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/regression-tests/general/no-duplicate-param.yaml.expect.json b/regression-tests/general/no-duplicate-param.yaml.expect.json index b75c3eb..f28ae62 100644 --- a/regression-tests/general/no-duplicate-param.yaml.expect.json +++ b/regression-tests/general/no-duplicate-param.yaml.expect.json @@ -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}}] \ No newline at end of file +[{"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}}] \ No newline at end of file diff --git a/src/rules/no-duplicate-param.ts b/src/rules/no-duplicate-param.ts index 553bede..0c8b3dd 100644 --- a/src/rules/no-duplicate-param.ts +++ b/src/rules/no-duplicate-param.ts @@ -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)) { @@ -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); + } + } + } + } } }