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

Double braces can't be ignored #1329

Open
2 tasks done
balloonpopper opened this issue Sep 5, 2018 · 4 comments
Open
2 tasks done

Double braces can't be ignored #1329

balloonpopper opened this issue Sep 5, 2018 · 4 comments

Comments

@balloonpopper
Copy link

balloonpopper commented Sep 5, 2018

We use Ansible onsite to replace contents in placeholders dynamically within shell script "templates". Shellcheck complains about the placeholders (marked by "{{ name }}" which is fine, but I'm unable to use the disable directive to bypass the errors generated.

For bugs

  • Rule Id (if any, e.g. SC1000):
    SC1009,SC1073,SC1072 (SC1083, SC1056, and SC1054 also fire but can be successfully bypassed)

  • My shellcheck version (shellcheck --version or "online"):
    0.5.0

  • I read the issue's wiki page, e.g. https://github.com/koalaman/shellcheck/wiki/SC2086

  • I tried on shellcheck.net and verified that this is still a problem on the latest commit

Here's a snippet or screenshot that shows the problem:

#!/bin/bash
# shellcheck disable=SC1009,SC1054,SC1073,SC1056,SC1072

{{ abcd }}

Here's what shellcheck currently says:

In a.sh line 4:
{{ abcd }}
^-- SC1009: The mentioned syntax error was in this brace group.
^-- SC1073: Couldn't parse this brace group. Fix to allow more checks.

In a.sh line 5:

^-- SC1072: Missing '}'. Fix any mentioned problems and try again.

Here's what I wanted or expected to see:

No errors reported

@Potherca
Copy link

I've played around with this a bit and it looks like certain directives (SC1009,SC1072,SC1073) cannot be disabled globally (i.e. per file).

To clarify by example, this:

#!/bin/bash 
# shellcheck disable=SC1009,SC1072,SC1073,SC1054,SC1083,SC1126

{{ abcd }} # shellcheck disable=SC1072

does the same as this:

#!/bin/bash 
# shellcheck disable=SC1054,SC1083,SC1126

{{ abcd }} # shellcheck disable=SC1072

I'm no expert but my guess is that has to do with the fact that they all have to do with Parse Errors. I don't think they could be disabled globally because ShellCheck needs to be able to parse code in order to lint it.

As ShellCheck can not work without parsing, disabling those directives would be exactly the same as simply not using ShellCheck at all...

@holderbaum
Copy link

Hello @balloonpopper and @Potherca,

this is an interesting issue and I had similar ones. My solution is to use mostly variables whenever possible. An example:

#/bin/bash

external_ip="{{ external_ip }}"
port="{{ port }}"

python -m http.server --bind "$external_ip" "$port"

While this is admittedly an oversimplified example, it works in most cases from my experience. The added benefit is, that your templated shell scripts look much cleaner and easier to grasp most of the time.

WDYT?

@balloonpopper
Copy link
Author

Thanks for your replies. In my opinion, the setting should apply globally, regardless of the file contents. I should be able to throw any type of file at it, with any contents, and as long as the global ignore rule is there, it shouldn't trigger the error. Implementing that might not end up feasible due to how shellcheck parses the file, but that is my expectation for how it should behave.

@lonix1
Copy link

lonix1 commented Mar 27, 2020

Did you find a workaround?

These days ansible is used heavily for automation, so scripts contain {{foo}}.

(And this triggers SC1083)

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

4 participants