From 55d01e7e1b9406cd05292f71f6df13b1f8d97830 Mon Sep 17 00:00:00 2001 From: mbwhite Date: Wed, 10 Jan 2024 14:51:43 +0000 Subject: [PATCH] fix: extra-params on embedded resources Signed-off-by: mbwhite --- regression-tests/general/no-extra-param.yaml | 24 +++++++++-- .../general/no-extra-param.yaml.expect.json | 2 +- .../triggertemplate-test.yaml.expect.json | 2 +- src/rules/no-extra-param.ts | 40 ++++++++++++++++--- 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/regression-tests/general/no-extra-param.yaml b/regression-tests/general/no-extra-param.yaml index 7791f3d..46f5d1c 100644 --- a/regression-tests/general/no-extra-param.yaml +++ b/regression-tests/general/no-extra-param.yaml @@ -16,13 +16,13 @@ spec: taskRef: name: no-extra-param-task params: - - name: foo + - name: no-extra-param-for-taskref-foo value: foo - name: step-1 taskSpec: steps: [] params: - - name: foo + - name: no-extra-param-for-taskspec-foo value: foo --- apiVersion: tekton.dev/v1 @@ -31,6 +31,18 @@ metadata: name: no-extra-param-template spec: resourcetemplates: + - apiVersion: tekton.dev/v1beta1 + kind: PipelineRun + metadata: + name: pipeline-run-3 + spec: + pipelineRef: + name: no-extra-param-pipeline + params: + - name: foo + value: foo + - name: notndeed + value: blank - apiVersion: tekton.dev/v1beta1 kind: PipelineRun metadata: @@ -41,25 +53,29 @@ spec: params: - name: foo value: foo + - name: reallynotndeed + value: blank - apiVersion: tekton.dev/v1beta1 kind: PipelineRun metadata: name: pipeline-run-2 spec: pipelineSpec: + params: + - name: reallyneeded tasks: - name: step-1 taskRef: name: no-extra-param-task params: - - name: foo + - name: unspecifified value: foo - name: step-2 taskSpec: steps: [] params: - name: foo - value: foo + value: $(params.readllyneeded) params: - name: extra-param-foo value: foo diff --git a/regression-tests/general/no-extra-param.yaml.expect.json b/regression-tests/general/no-extra-param.yaml.expect.json index 0a6f637..228d876 100644 --- a/regression-tests/general/no-extra-param.yaml.expect.json +++ b/regression-tests/general/no-extra-param.yaml.expect.json @@ -1 +1 @@ -[{"message":"Pipeline 'no-extra-param-pipeline' references task 'no-extra-param-task' (as 'step-1'), and supplies parameter 'foo' to it, but it's not a valid parameter","rule":"no-extra-param","level":"error","path":"./regression-tests/general/no-extra-param.yaml","loc":{"range":[291,322,322],"startLine":19,"startColumn":11,"endLine":21,"endColumn":1}},{"message":"Pipeline 'no-extra-param-pipeline' references task 'step-1', and supplies parameter 'foo' to it, but it's not a valid parameter","rule":"no-extra-param","level":"error","path":"./regression-tests/general/no-extra-param.yaml","loc":{"range":[399,430,430],"startLine":25,"startColumn":11,"endLine":27,"endColumn":1}},{"message":"TriggerTemplate 'no-extra-param-template' references pipeline 'no-extra-param-pipeline', and supplies 'foo', but it's not a valid parameter.","rule":"no-extra-param","level":"error","path":"./regression-tests/general/no-extra-param.yaml","loc":{"range":[758,791,791],"startLine":42,"startColumn":13,"endLine":44,"endColumn":1}}] \ No newline at end of file +[{"message":"Pipeline 'no-extra-param-pipeline' references task 'no-extra-param-task' (as 'step-1'), and supplies parameter 'no-extra-param-for-taskref-foo' to it, but it's not a valid parameter","rule":"no-extra-param","level":"error","path":"./regression-tests/general/no-extra-param.yaml","loc":{"range":[291,349,349],"startLine":19,"startColumn":11,"endLine":21,"endColumn":1}},{"message":"Pipeline 'no-extra-param-pipeline' references task 'step-1', and supplies parameter 'no-extra-param-for-taskspec-foo' to it, but it's not a valid parameter","rule":"no-extra-param","level":"error","path":"./regression-tests/general/no-extra-param.yaml","loc":{"range":[426,485,485],"startLine":25,"startColumn":11,"endLine":27,"endColumn":1}},{"message":"TriggerTemplate 'no-extra-param-template' references pipeline 'no-extra-param-pipeline', and supplies 'foo', but it's not a valid parameter.","rule":"no-extra-param","level":"error","path":"./regression-tests/general/no-extra-param.yaml","loc":{"range":[813,846,846],"startLine":42,"startColumn":13,"endLine":44,"endColumn":1}},{"message":"TriggerTemplate 'no-extra-param-template' references pipeline 'no-extra-param-pipeline', and supplies 'notndeed', but it's not a valid parameter.","rule":"no-extra-param","level":"error","path":"./regression-tests/general/no-extra-param.yaml","loc":{"range":[858,900,900],"startLine":44,"startColumn":13,"endLine":46,"endColumn":1}},{"message":"TriggerTemplate 'no-extra-param-template' references pipeline 'no-extra-param-pipeline', and supplies 'foo', but it's not a valid parameter.","rule":"no-extra-param","level":"error","path":"./regression-tests/general/no-extra-param.yaml","loc":{"range":[1107,1140,1140],"startLine":54,"startColumn":13,"endLine":56,"endColumn":1}},{"message":"TriggerTemplate 'no-extra-param-template' references pipeline 'no-extra-param-pipeline', and supplies 'reallynotndeed', but it's not a valid parameter.","rule":"no-extra-param","level":"error","path":"./regression-tests/general/no-extra-param.yaml","loc":{"range":[1152,1198,1198],"startLine":56,"startColumn":13,"endLine":58,"endColumn":1}},{"message":"TriggerTemplate 'no-extra-param-template' references pipeline 'pipeline-run-2', and supplies 'extra-param-foo', but it's not a valid parameter.","rule":"no-extra-param","level":"error","path":"./regression-tests/general/no-extra-param.yaml","loc":{"range":[1791,1836,1836],"startLine":80,"startColumn":13,"endLine":82,"endColumn":1}},{"message":"Undefined param 'readllyneeded' at .spec.resourcetemplates[2].spec.pipelineSpec.tasks[1].params[0].value in 'no-extra-param-template'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/no-extra-param.yaml","loc":{"range":[1739,1762,1763],"startLine":78,"startColumn":26,"endLine":78,"endColumn":49}}] \ No newline at end of file diff --git a/regression-tests/general/triggertemplate-test.yaml.expect.json b/regression-tests/general/triggertemplate-test.yaml.expect.json index c081817..9679d24 100644 --- a/regression-tests/general/triggertemplate-test.yaml.expect.json +++ b/regression-tests/general/triggertemplate-test.yaml.expect.json @@ -1 +1 @@ -[{"message":"Resource ServiceAccount 'tutorial-service' has an invalid 'resourceVersion' key in its resource definition.","rule":"no-resourceversion","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[10712,10720,10721],"startLine":463,"startColumn":26,"endLine":463,"endColumn":34}},{"message":"'template-pipelineref-null' is already defined (as a 'TriggerTemplate')","rule":"no-duplicate-resource","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[3716,3741,3742],"startLine":164,"startColumn":9,"endLine":164,"endColumn":34}},{"message":"Invalid name for TriggerTemplate 'template-with-pipelineSpec'. Names should be in lowercase, alphanumeric, kebab-case format. and follow DNS subdomain names","rule":"no-invalid-name","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[7045,7071,7072],"startLine":307,"startColumn":9,"endLine":307,"endColumn":35}},{"message":"Invalid name for TriggerTemplate 'template-pipelineSpec-without-tasks'. Names should be in lowercase, alphanumeric, kebab-case format. and follow DNS subdomain names","rule":"no-invalid-name","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[7990,8025,8026],"startLine":348,"startColumn":9,"endLine":348,"endColumn":44}},{"message":"Invalid name for TriggerTemplate 'template-pipelineSpec-missing-and-extra-params'. Names should be in lowercase, alphanumeric, kebab-case format. and follow DNS subdomain names","rule":"no-invalid-name","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[8866,8912,8913],"startLine":386,"startColumn":9,"endLine":386,"endColumn":55}},{"message":"Invalid name for TriggerTemplate 'template-with-serviceAccount'. Names should be in lowercase, alphanumeric, kebab-case format. and follow DNS subdomain names","rule":"no-invalid-name","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[10158,10186,10187],"startLine":443,"startColumn":9,"endLine":443,"endColumn":37}},{"message":"TriggerTemplate 'template-with-params' references pipeline 'pipeline-with-params', but the referenced pipeline cannot be found.","rule":"no-missing-resource","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[764,784,785],"startLine":34,"startColumn":17,"endLine":34,"endColumn":37}},{"message":"TriggerTemplate 'template-without-params' references pipeline 'pr-pipeline', but the referenced pipeline cannot be found.","rule":"no-missing-resource","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[1591,1602,1603],"startLine":70,"startColumn":17,"endLine":70,"endColumn":28}},{"message":"TriggerTemplate 'template-pipelineref-null' references pipeline 'pipelineref-missing', but the referenced pipeline cannot be found.","rule":"no-missing-resource","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[4415,4434,4435],"startLine":194,"startColumn":19,"endLine":194,"endColumn":38}},{"message":"TriggerTemplate 'template-without-pipelineref' references pipeline 'null', but the referenced pipeline cannot be found.","rule":"no-missing-resource","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[3548,3548,3548],"startLine":156,"startColumn":18,"endLine":156,"endColumn":18}},{"message":"TriggerTemplate 'template-without-pipelinerun-params' references pipeline 'pipeline-with-taskref-without-params', but the referenced pipeline cannot be found.","rule":"no-missing-resource","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[6110,6146,6147],"startLine":265,"startColumn":19,"endLine":265,"endColumn":55}},{"message":"TriggerTemplate 'template-with-null-pipelinerun-params' references pipeline 'null', but the referenced pipeline cannot be found.","rule":"no-missing-resource","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[6952,6952,6952],"startLine":301,"startColumn":18,"endLine":301,"endColumn":18}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-with-params'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[586,603,604],"startLine":27,"startColumn":18,"endLine":27,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-without-params'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[1413,1430,1431],"startLine":63,"startColumn":18,"endLine":63,"endColumn":35}},{"message":"Undefined param 'target-branch' at .spec.resourcetemplates[2].spec.params[0].value in 'template-without-params'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[1670,1693,1694],"startLine":73,"startColumn":20,"endLine":73,"endColumn":43}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-pipelineref-null'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[4235,4252,4253],"startLine":187,"startColumn":18,"endLine":187,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-without-pipelineref'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[3369,3386,3387],"startLine":149,"startColumn":18,"endLine":149,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-without-pipelinerun-params'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[5930,5947,5948],"startLine":258,"startColumn":18,"endLine":258,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-with-null-pipelinerun-params'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[6773,6790,6791],"startLine":294,"startColumn":18,"endLine":294,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-with-pipelineSpec'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[7565,7582,7583],"startLine":330,"startColumn":18,"endLine":330,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-pipelineSpec-without-tasks'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[8519,8536,8537],"startLine":371,"startColumn":18,"endLine":371,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-pipelineSpec-missing-and-extra-params'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[9406,9423,9424],"startLine":409,"startColumn":18,"endLine":409,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[0].stringData.API_KEY in 'template-with-secret'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[10064,10081,10082],"startLine":438,"startColumn":18,"endLine":438,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[0].stringData.API_KEY in 'template-with-serviceAccount'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[10417,10434,10435],"startLine":455,"startColumn":18,"endLine":455,"endColumn":35}},{"message":"TriggerTemplate 'template-without-resource-templates' defines parameter 'target-branch', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[1828,1881,1881],"startLine":81,"startColumn":7,"endLine":83,"endColumn":1}},{"message":"TriggerTemplate 'template-without-pipelinerun-params' defines parameter 'target-branch', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[5459,5512,5512],"startLine":238,"startColumn":7,"endLine":240,"endColumn":1}},{"message":"TriggerTemplate 'template-with-null-pipelinerun-params' defines parameter 'target-branch', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[6302,6355,6355],"startLine":274,"startColumn":7,"endLine":276,"endColumn":1}},{"message":"TriggerTemplate 'template-pipelineSpec-missing-and-extra-params' defines parameter 'target-branch', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[8935,8988,8988],"startLine":389,"startColumn":7,"endLine":391,"endColumn":1}},{"message":"TriggerTemplate 'template-with-secret' defines parameter 'target-branch', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[9856,9909,9909],"startLine":429,"startColumn":7,"endLine":431,"endColumn":1}},{"message":"TriggerTemplate 'template-with-serviceAccount' defines parameter 'target-branch', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[10209,10262,10262],"startLine":446,"startColumn":7,"endLine":448,"endColumn":1}}] \ No newline at end of file +[{"message":"Resource ServiceAccount 'tutorial-service' has an invalid 'resourceVersion' key in its resource definition.","rule":"no-resourceversion","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[10712,10720,10721],"startLine":463,"startColumn":26,"endLine":463,"endColumn":34}},{"message":"'template-pipelineref-null' is already defined (as a 'TriggerTemplate')","rule":"no-duplicate-resource","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[3716,3741,3742],"startLine":164,"startColumn":9,"endLine":164,"endColumn":34}},{"message":"TriggerTemplate 'template-pipelineSpec-without-tasks' references pipeline 'pipelinerun-$(uid)', and supplies 'target-branch', but it's not a valid parameter.","rule":"no-extra-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[8727,8790,8790],"startLine":380,"startColumn":13,"endLine":382,"endColumn":1}},{"message":"TriggerTemplate 'template-pipelineSpec-missing-and-extra-params' references pipeline 'pipelinerun-$(uid)', and supplies 'target-branch', but it's not a valid parameter.","rule":"no-extra-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[9673,9737,9737],"startLine":420,"startColumn":15,"endLine":422,"endColumn":1}},{"message":"Invalid name for TriggerTemplate 'template-with-pipelineSpec'. Names should be in lowercase, alphanumeric, kebab-case format. and follow DNS subdomain names","rule":"no-invalid-name","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[7045,7071,7072],"startLine":307,"startColumn":9,"endLine":307,"endColumn":35}},{"message":"Invalid name for TriggerTemplate 'template-pipelineSpec-without-tasks'. Names should be in lowercase, alphanumeric, kebab-case format. and follow DNS subdomain names","rule":"no-invalid-name","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[7990,8025,8026],"startLine":348,"startColumn":9,"endLine":348,"endColumn":44}},{"message":"Invalid name for TriggerTemplate 'template-pipelineSpec-missing-and-extra-params'. Names should be in lowercase, alphanumeric, kebab-case format. and follow DNS subdomain names","rule":"no-invalid-name","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[8866,8912,8913],"startLine":386,"startColumn":9,"endLine":386,"endColumn":55}},{"message":"Invalid name for TriggerTemplate 'template-with-serviceAccount'. Names should be in lowercase, alphanumeric, kebab-case format. and follow DNS subdomain names","rule":"no-invalid-name","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[10158,10186,10187],"startLine":443,"startColumn":9,"endLine":443,"endColumn":37}},{"message":"TriggerTemplate 'template-with-params' references pipeline 'pipeline-with-params', but the referenced pipeline cannot be found.","rule":"no-missing-resource","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[764,784,785],"startLine":34,"startColumn":17,"endLine":34,"endColumn":37}},{"message":"TriggerTemplate 'template-without-params' references pipeline 'pr-pipeline', but the referenced pipeline cannot be found.","rule":"no-missing-resource","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[1591,1602,1603],"startLine":70,"startColumn":17,"endLine":70,"endColumn":28}},{"message":"TriggerTemplate 'template-pipelineref-null' references pipeline 'pipelineref-missing', but the referenced pipeline cannot be found.","rule":"no-missing-resource","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[4415,4434,4435],"startLine":194,"startColumn":19,"endLine":194,"endColumn":38}},{"message":"TriggerTemplate 'template-without-pipelineref' references pipeline 'null', but the referenced pipeline cannot be found.","rule":"no-missing-resource","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[3548,3548,3548],"startLine":156,"startColumn":18,"endLine":156,"endColumn":18}},{"message":"TriggerTemplate 'template-without-pipelinerun-params' references pipeline 'pipeline-with-taskref-without-params', but the referenced pipeline cannot be found.","rule":"no-missing-resource","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[6110,6146,6147],"startLine":265,"startColumn":19,"endLine":265,"endColumn":55}},{"message":"TriggerTemplate 'template-with-null-pipelinerun-params' references pipeline 'null', but the referenced pipeline cannot be found.","rule":"no-missing-resource","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[6952,6952,6952],"startLine":301,"startColumn":18,"endLine":301,"endColumn":18}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-with-params'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[586,603,604],"startLine":27,"startColumn":18,"endLine":27,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-without-params'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[1413,1430,1431],"startLine":63,"startColumn":18,"endLine":63,"endColumn":35}},{"message":"Undefined param 'target-branch' at .spec.resourcetemplates[2].spec.params[0].value in 'template-without-params'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[1670,1693,1694],"startLine":73,"startColumn":20,"endLine":73,"endColumn":43}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-pipelineref-null'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[4235,4252,4253],"startLine":187,"startColumn":18,"endLine":187,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-without-pipelineref'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[3369,3386,3387],"startLine":149,"startColumn":18,"endLine":149,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-without-pipelinerun-params'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[5930,5947,5948],"startLine":258,"startColumn":18,"endLine":258,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-with-null-pipelinerun-params'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[6773,6790,6791],"startLine":294,"startColumn":18,"endLine":294,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-with-pipelineSpec'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[7565,7582,7583],"startLine":330,"startColumn":18,"endLine":330,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-pipelineSpec-without-tasks'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[8519,8536,8537],"startLine":371,"startColumn":18,"endLine":371,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[1].stringData.API_KEY in 'template-pipelineSpec-missing-and-extra-params'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[9406,9423,9424],"startLine":409,"startColumn":18,"endLine":409,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[0].stringData.API_KEY in 'template-with-secret'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[10064,10081,10082],"startLine":438,"startColumn":18,"endLine":438,"endColumn":35}},{"message":"Undefined param 'api-key' at .spec.resourcetemplates[0].stringData.API_KEY in 'template-with-serviceAccount'","rule":"no-undefined-param","level":"error","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[10417,10434,10435],"startLine":455,"startColumn":18,"endLine":455,"endColumn":35}},{"message":"TriggerTemplate 'template-without-resource-templates' defines parameter 'target-branch', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[1828,1881,1881],"startLine":81,"startColumn":7,"endLine":83,"endColumn":1}},{"message":"TriggerTemplate 'template-without-pipelinerun-params' defines parameter 'target-branch', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[5459,5512,5512],"startLine":238,"startColumn":7,"endLine":240,"endColumn":1}},{"message":"TriggerTemplate 'template-with-null-pipelinerun-params' defines parameter 'target-branch', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[6302,6355,6355],"startLine":274,"startColumn":7,"endLine":276,"endColumn":1}},{"message":"TriggerTemplate 'template-pipelineSpec-missing-and-extra-params' defines parameter 'target-branch', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[8935,8988,8988],"startLine":389,"startColumn":7,"endLine":391,"endColumn":1}},{"message":"TriggerTemplate 'template-with-secret' defines parameter 'target-branch', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[9856,9909,9909],"startLine":429,"startColumn":7,"endLine":431,"endColumn":1}},{"message":"TriggerTemplate 'template-with-serviceAccount' defines parameter 'target-branch', but it's not used anywhere in the spec","rule":"no-unused-param","level":"warning","path":"./regression-tests/general/triggertemplate-test.yaml","loc":{"range":[10209,10262,10262],"startLine":446,"startColumn":7,"endLine":448,"endColumn":1}}] \ No newline at end of file diff --git a/src/rules/no-extra-param.ts b/src/rules/no-extra-param.ts index d281585..84704be 100644 --- a/src/rules/no-extra-param.ts +++ b/src/rules/no-extra-param.ts @@ -63,19 +63,47 @@ export default (docs, tekton, report) => { } for (const pipeline of Object.values(tekton.pipelines)) { for (const template of Object.values(tekton.triggerTemplates)) { - const matchingResource = template.spec.resourcetemplates.find( + // iterate on the resources that athe pipelinelins + const matchingResource = template.spec.resourcetemplates.filter( (item) => item.spec && item.spec.pipelineRef && item.spec.pipelineRef.name === pipeline.metadata.name, ); - if (!matchingResource) continue; - const pipelineParams = pipeline.spec.params || []; - const templateParams = matchingResource.spec.params || []; + + if (matchingResource.length == 0) continue; + for (const resource of matchingResource) { + const pipelineParams = pipeline.spec.params || []; + const templateParams = resource.spec.params || []; + const extra = templateParams.filter( + (templateParam) => + !pipelineParams.some((pipelineParam) => pipelineParam.name === templateParam.name), + ); + + for (const param of extra) { + report( + `TriggerTemplate '${template.metadata.name}' references pipeline '${pipeline.metadata.name}', and supplies '${param.name}', but it's not a valid parameter.`, + templateParams.find((p) => p.name === param.name), + ); + } + } + } + } + + for (const template of Object.values(tekton.triggerTemplates)) { + // iterate on the resources that athe pipelinelins + const matchingResource = template.spec.resourcetemplates.filter((item) => item.spec && item.spec.pipelineSpec); + + if (matchingResource.length == 0) continue; + for (const resource of matchingResource) { + const pipeline = resource.spec.pipelineSpec; + + const pipelineParams = pipeline.params || []; + const templateParams = resource.spec.params || []; + const extra = templateParams.filter( (templateParam) => !pipelineParams.some((pipelineParam) => pipelineParam.name === templateParam.name), ); - for (const param of extra) { report( - `TriggerTemplate '${template.metadata.name}' references pipeline '${pipeline.metadata.name}', and supplies '${param.name}', but it's not a valid parameter.`, + `TriggerTemplate '${template.metadata.name}' references pipeline '${resource.metadata.name}', and supplies '${param.name}', but it's not a valid parameter.`, templateParams.find((p) => p.name === param.name), ); }