Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kdudka opened this issue Apr 4, 2025 · 0 comments
Open

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

kdudka opened this issue Apr 4, 2025 · 0 comments

Comments

@kdudka
Copy link

kdudka commented Apr 4, 2025

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 csutils/csmock#198 where the final exit command unexpectedly triggered 9 SC2317 false positives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant