koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts
https://www.shellcheck.net
GNU General Public License v3.0
35.55k stars 1.74k forks source link

SC2039 - use different error-codes for different things #503

Open bittorf opened 8 years ago

bittorf commented 8 years ago

SC2039 is used for different issues which all are "not POSIX" e.g.

SC2039: In POSIX sh, echo flags are not supported. SC2039: In POSIX sh, HOSTNAME is not supported. SC2039: In POSIX sh, string replacement is not supported. SC2039: In POSIX sh, 'let' is not supported. SC2039: in POSIX sh - 'local' is not supported (and maybe more)

can we use different codes for different issues, so that selective muting works better?

dankegel commented 7 years ago

amen. I want to use 'local' because it's portable enough, and I don't want to disable all the other checks.

bittorf commented 7 years ago

@dankegel - for now we workaround that with e.g.

shellcheck --shell=dash "$FILE"

dash has special handling, e.g. 'local' is allowed

dankegel commented 7 years ago

Thanks! Or as it turns out, you can use the undocumented shell directive:

# shellcheck shell=dash

I submitted https://github.com/koalaman/shellcheck/pull/878 to document this.

koalaman commented 7 years ago

@dankegel Why not set the shebang to #!/bin/dash if you're using dash features that do not exist in POSIX sh?

euclio commented 6 years ago

Just ran into this. I'm trying to write a script that is only portable between bash and zsh, and it'd be nice to disable checks for local, without disabling other bashism checks.

dankegel commented 6 years ago

Because then the shell script would not run on the mac.

euclio commented 6 years ago

Yes, but this script is meant to stay on a Linux box.

Earnestly commented 6 years ago

Each of these checks should be separate indeed. There are reasonable concessions to make here because almost every relevant sh shell supports local and it is reasonable to use #!/bin/sh for them if the requirements are properly documented. (Fortunately local is being considered via two different means for the next edition of POSIX standard.)

It's difficult to use shellcheck in an automated fasion when a single warning indication is overloaded with many others.

dankegel commented 6 years ago

I don't know about euclio's scripts, but mine are most definitely meant to run on multiple operating systems. Requiring bash or dash is not an option.

Earnestly commented 5 years ago

I was actually caught out by this recently due to annotating the script that I make use of local but I didn't realise it was actually disabling the check on my use of ${@:3}. It was only after reformatting things that a check went through without the omission did I see it.

oliv3r commented 4 years ago

Just to ensure this issue is not forgotten a friendly bump. We too run into the issue where we want all of the SC2039 to be triggered, except for maybe 1 or 2 cases, we want to globally ignore. This is, sadly, not possible yet.