koalaman / shellcheck

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

SC2119 / SC2120 false positives? #2926

Open dubo-dubon-duponey opened 9 months ago

dubo-dubon-duponey commented 9 months ago

For bugs

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

#!/usr/bin/env bash

foo(){
        local input="${1:-/dev/stdin}"
        cat "$input"
}

foo <<<"blah"

Here's what shellcheck currently says:

In test.sh line 3:
foo(){
^-- SC2120 (warning): foo references arguments, but none are ever passed.

In test.sh line 9:
foo <<<"blah"
^-----------^ SC2119 (info): Use foo "$@" if function's $1 should mean script's $1.

For more information:
  https://www.shellcheck.net/wiki/SC2120 -- foo references arguments, but non...
  https://www.shellcheck.net/wiki/SC2119 -- Use foo "$@" if function's $1 sho...

Here's what I wanted or expected to see:

It should say nothing about SC2120. An argument is being passed (a file descriptor), so, this one feels factually wrong to me.

SC2119, I am not quite sure what it would mean here, so, same thing, I would expect it to not say anything.

Apologies in advance if I am missing something here.

Thanks a lot!

nhed commented 5 months ago

I agree, IMO shellcheck should ignore this if any of the following are used - but especially the first

       ${parameter:-word}
       ${parameter:=word}
       ${parameter:?word}
       ${parameter:+word}