shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

SC2119 for functions in sourced files with optional arguments

Open anlutro opened this issue 6 years ago • 5 comments

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

anlutro avatar Aug 23 '19 10:08 anlutro

I just ran into the same thing. db_go too.

jmccanta avatar May 30 '20 03:05 jmccanta

I am seeing the same issue.

leoheck avatar Mar 31 '22 00:03 leoheck

Same here, shellcheck 0.8.0

juliyvchirkov avatar Jun 10 '22 13:06 juliyvchirkov