shellcheck
shellcheck copied to clipboard
SC2119 for functions in sourced files with optional arguments
Given a function defined in a sourced file that has optional arguments, shellcheck treats it as if it's a mistake to not pass any arguments.
Minimal reproducible setup:
$ cat lib.sh
#!/bin/sh
f() { echo "f $*"; }
$ cat test.sh
#!/bin/sh
. lib.sh
f
$ shellcheck -x ./test.sh
In ./test.sh line 3:
f
^-- SC2119: Use f "$@" if function's $1 should mean script's $1.
If the function is defined in the same file, you correctly get a warning that the function is never called with arguments, but here this is not the case.
I ran into this when using db_go which is defined in /usr/share/debconf/confmodule on Debian/Ubuntu systems.
$ shellcheck --version
ShellCheck - shell script analysis tool
version: 0.7.0
license: GNU General Public License, version 3
website: https://www.shellcheck.net
I just ran into the same thing. db_go too.
I am seeing the same issue.
Same here, shellcheck 0.8.0