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

support --stdin-filename when passing files via stdin #2735

Open vapier opened 1 year ago

vapier commented 1 year ago

For new checks and feature suggestions

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

#!/bin/sh
[[ $# -eq 0 ]]

Here's what shellcheck currently says:

$ shellcheck test.sh 

In test.sh line 2:
[[ $# -eq 0 ]]
^------------^ SC3010 (warning): In POSIX sh, [[ ]] is undefined.

For more information:
  https://www.shellcheck.net/wiki/SC3010 -- In POSIX sh, [[ ]] is undefined.
$ shellcheck - <test.sh

In - line 2:
[[ $# -eq 0 ]]
^------------^ SC3010 (warning): In POSIX sh, [[ ]] is undefined.

For more information:
  https://www.shellcheck.net/wiki/SC3010 -- In POSIX sh, [[ ]] is undefined.

Here's what I wanted or expected to see:

The output of - in the diagnostics is confusing, especially when passing other files. It's also problematic when using --external-sources as SCRIPTDIR isn't set to anything useful.

Would like to have an option like --stdin-filename so that I can pass test.sh and it'll use that name when processing stdin.

j0sh commented 5 months ago

This feature would be useful. Right now I have to annotate stdin checks separately to distinguish them from one another.

Ordoviz commented 5 months ago

This would be useful when hacking together a simple shellcheck wrapper where parsing shellcheck's JSON output is not worth it. For example, in markdown-shellcheck I have to use regexes to replace the - with the filename.