adrienverge / yamllint

A linter for YAML files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

azure pipeline expression ${{ else }} false positive key-duplicates

mkieszek opened this issue · comments

I'm using two if/else expressions in variable section of azure pipeline and yamllint is reporting a key-duplicates.
Is there any way to exclude azure pipeline expressions from linting?

Same problem was described in this issue super-linter/super-linter#3335

Provided solution, to placing a # yamllint disable-line at line above, is not very elegant.

Hello,

For the record, the referenced example is as follows:

- template: /path-to/file.yml 
    parameters:
      param1: "foo"
      ${{ if condition1 }}:
        param2: "value1"
      ${{ else }}:
        param2: "Fooccess"
      param3: "fooX"
      
      param4: "fooY"
      ${{ if condition2 }}:
        param5: "value3"
      ${{ elseif condition3 }}:
        param5: "Fooccess"
      ${{ else }}:
        param5: "Foocked :("

This is not YAML, but a Azure DevOps template that is meant to be compiled into YAML (${{ }} are then replaced with real values).

In general, a YAML linter (either PyYAML or another one) is not able to parse such a language. Here, PyYAML is able to parse the file, but correctly extract two keys with the same name "${{ else }}". It's normal that yamllint reports it: that's what we expect from the rule key-duplicates.

If it's possible to you, I would suggest linting the output of what Azure DevOps generates (that should be valid YAML), rather than the source format.

Liniting output is to late task. We are developing Azure Pipelines and want to validate during a CI stage.
I understand that the file is not a strict YAML format. But we are using yamlint because this is the best what we can get. From my perspective it would be better to be able tweak yamllint instead building, even on top of it, a new tool.