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

[Bug / regression?] In file ignore directives (# shellcheck disable=<check_id>) are not specific & disable all checks instead (not just check_id) #2975

Closed
fedy-cz opened this issue Apr 25, 2024 · 1 comment

Comments

@fedy-cz
Copy link

fedy-cz commented Apr 25, 2024

Shellcheck version: 0.9.0

Stumbled upon this randomly, but it seems that shellcheck (v 0.9.0) ignores the rule numbers/IDs and just disables all the checks when ignore directives are used inside a file.

For example, here I try to ignore the rule SC2251:

#!/bin/bash
set -o errexit -o pipefail -o noclobber -o nounset

# -allow a command to fail with !’s side effect on errexit
# -use return value from ${PIPESTATUS[0]}, because ! hosed $?
#shellcheck disable=SC2251
! getopt --test > /dev/null
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
  echo "I’m sorry, 'getopt --test' failed in this environment." >&2
  exit 1
fi

... So far so good.

But if I change the line from:
#shellcheck disable=SC2251
to
#shellcheck disable=SC1000

I still get no errors.

Other versions affected:
https://www.shellcheck.net/ seems to be affected as well.

@koalaman
Copy link
Owner

koalaman commented May 4, 2024

Nice catch! This was due to one of ShellCheck's design mistakes: making directives separate nodes in the AST that checks match against to identify problems.

In this case, the check looked for ! cmd inside various compound command bodies. It neglected to look for ! cmd inside directives inside the compound command bodies. As a result, any type of directive (whether or not related to disabling warnings) would cause this particular check not to recognize the problem it aimed to.

It was fortunately not a general problem with disabling specific codes, but it's definitely not the first bug caused by this design mistake, and it certainly won't be the last.

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

2 participants