shellcheck
shellcheck copied to clipboard
`SC2317` false positives triggered by `exit` at the end of a script
The following minimal example:
#!/bin/bash
fnc() { echo; }
cmd="$(declare -f fnc)
fnc"
eval "${cmd}"
exit
... triggers a SC2317 false positive:
In xxx.sh line 3:
fnc() { echo; }
^--^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
For more information:
https://www.shellcheck.net/wiki/SC2317 -- Command appears to be unreachable...
It seems expected because of the use of declare -f. However, if the final exit command is commented out, the false positive goes away, which is entirely unexpected.
This was discovered while reviewing https://github.com/csutils/csmock/pull/198 where the final exit command unexpectedly triggered 9 SC2317 false positives.