shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

`SC2317` false positives triggered by `exit` at the end of a script

Open kdudka opened this issue 10 months ago • 0 comments

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.

kdudka avatar Apr 04 '25 13:04 kdudka