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

Can't ignore spercific line #462

Closed
Alexhha opened this issue Jun 5, 2022 · 5 comments
Closed

Can't ignore spercific line #462

Alexhha opened this issue Jun 5, 2022 · 5 comments

Comments

@Alexhha
Copy link

Alexhha commented Jun 5, 2022

We have the following yaml file

    logging:
# yamllint disable-line
%{ if cloudwatch_enabled == "true" ~}
      driver: awslogs
      options:
        awslogs-region: us-east-1
        awslogs-group: group
        awslogs-stream: ${node_id}
%{ else ~}
      driver: json-file
      options:
        max-size: "50m"
        max-file: "10"
%{ endif ~}

But I still get syntax error

$ yamllint -d '{extends: default, rules: {line-length: {max: 128}, document-start: disable, empty-lines: disable}}' docker-compose.tftpl
docker-compose.tftpl
  45:2      error    syntax error: expected alphabetic or numeric character, but found '{' (syntax)

Did I miss something ? How can I ignore terraform template syntax %{ if }...%{ else }...%{ endif } ?

P.S.

$ yamllint -v
yamllint 1.26.3
@perlpunk
Copy link

perlpunk commented Jun 6, 2022

that's basically the same issue as rhe recent #460

@Alexhha
Copy link
Author

Alexhha commented Jun 6, 2022

Haven't seen the issue. Have I correctly understood - there is no way to skip checks just for 1 line in such case ?

@andrewimeson
Copy link
Contributor

@Alexhha the problem is that the file isn't valid YAML, and thus yamllint can't parse it. You can't ignore parser errors. You wouldn't want yamllint to ignore parser errors, because it might incorrectly parse what comes next in the file leading to false positives or negatives.

A good workaround is to put the non-yaml content in comments, like this

    logging:
# %{ if cloudwatch_enabled == "true" ~}
      driver: awslogs
      options:
        awslogs-region: us-east-1
        awslogs-group: group
        awslogs-stream: ${node_id}
# %{ else ~}
      driver: json-file
      options:
        max-size: "50m"
        max-file: "10"
# %{ endif ~}

andrewimeson added a commit to andrewimeson/yamllint that referenced this issue Jun 6, 2022
Lots of user confusion expecting `disable-line` to work around parser
errors caused by templating syntax.

Relates to adrienverge#61, adrienverge#65, adrienverge#128, adrienverge#311, adrienverge#460, adrienverge#462
andrewimeson added a commit to andrewimeson/yamllint that referenced this issue Jun 6, 2022
Lots of user confusion expecting `disable-line` to work around parser
errors caused by templating syntax.

Relates to adrienverge#61, adrienverge#65, adrienverge#128, adrienverge#311, adrienverge#460, adrienverge#462
andrewimeson added a commit to andrewimeson/yamllint that referenced this issue Jun 6, 2022
Lots of user confusion expecting `disable-line` to work around parser
errors caused by templating syntax.

Relates to adrienverge#61, adrienverge#65, adrienverge#128, adrienverge#311, adrienverge#460, adrienverge#462
andrewimeson added a commit to andrewimeson/yamllint that referenced this issue Jun 6, 2022
Lots of user confusion expecting `disable-line` to work around parser
errors caused by templating syntax.

Relates to adrienverge#61, adrienverge#65, adrienverge#128, adrienverge#311, adrienverge#460, adrienverge#462
andrewimeson added a commit to andrewimeson/yamllint that referenced this issue Jun 6, 2022
Lots of user confusion expecting `disable-line` to work around parser
errors caused by templating syntax.

Relates to adrienverge#61, adrienverge#65, adrienverge#128, adrienverge#311, adrienverge#460, adrienverge#462
@Alexhha
Copy link
Author

Alexhha commented Jun 7, 2022

@andrewimeson

Unfortunately it doesn't work in such way. Got the following result

    logging:
      #       driver: json-file
      options:
        max-size: "50m"
        max-file: "10"
    #     ulimits:
      nproc: 65535
      nofile:
        soft: 32000
        hard: 40000

andrewimeson added a commit to andrewimeson/yamllint that referenced this issue Jun 7, 2022
Lots of user confusion expecting `disable-line` to work around parser
errors caused by templating syntax.

Relates to adrienverge#61, adrienverge#65, adrienverge#128, adrienverge#311, adrienverge#460, adrienverge#462
andrewimeson added a commit to andrewimeson/yamllint that referenced this issue Jun 14, 2022
Lots of user confusion expecting `disable-line` to work around parser
errors caused by templating syntax.

Relates to adrienverge#61, adrienverge#65, adrienverge#128, adrienverge#311, adrienverge#460, adrienverge#462
adrienverge pushed a commit to andrewimeson/yamllint that referenced this issue Oct 24, 2022
Lots of user confusion expecting `disable-line` to work around parser
errors caused by templating syntax.

Relates to adrienverge#61, adrienverge#65, adrienverge#128, adrienverge#311, adrienverge#460, adrienverge#462
adrienverge pushed a commit to andrewimeson/yamllint that referenced this issue Oct 24, 2022
Lots of user confusion expecting `disable-line` to work around parser
errors caused by templating syntax.

Relates to adrienverge#61, adrienverge#65, adrienverge#128, adrienverge#311, adrienverge#460, adrienverge#462
adrienverge pushed a commit to andrewimeson/yamllint that referenced this issue Oct 24, 2022
Lots of user confusion expecting `disable-line` to work around parser
errors caused by templating syntax.

Relates to adrienverge#61, adrienverge#65, adrienverge#128, adrienverge#311, adrienverge#460, adrienverge#462
adrienverge pushed a commit that referenced this issue Oct 24, 2022
Lots of user confusion expecting `disable-line` to work around parser
errors caused by templating syntax.

Relates to #61, #65, #128, #311, #460, #462
@mwgamble
Copy link
Contributor

The real solution is to not use a string templating language to craft structured data. YAML files aren't plain text. They're structured data that has been serialised to a format that can be stored in a file (that happens to still be human editable, for better or worse).

You shouldn't rely on a string templating system that has no knowledge of what's being templated to do this properly. This is also how you wind up with cross-site scripting attacks, and it's one reason for why "traditional" stringy HTML templating engines have fallen out of favour, replaced by things like React and Vue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants