koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts
https://www.shellcheck.net
GNU General Public License v3.0
36.45k stars 1.78k forks source link

Please separate the issue of unused functions from SC2317 (Command appears to be unreachable) #2966

Closed ale5000-git closed 6 months ago

ale5000-git commented 7 months ago

For bugs

Here's a snippet or screenshot that shows the problem:

Script: https://github.com/micro5k/microg-unofficial-installer/blob/ecf1f9b/utils/device-info.sh

Here's what shellcheck currently says:

[Line 882:](javascript:setPosition(882, 3))
  adb 1> /dev/null 2>&1 shell '
  ^-- [SC2317](https://www.shellcheck.net/wiki/SC2317) (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

Here's what I wanted or expected to see:

Function is unused.

Edit: Updated.

brother commented 7 months ago

This bug only happens on https://www.shellcheck.net/ but not on the release.

Bug present at d80fdfa9e8e as well as the current HEAD (04a8624).

not sure what version "but not on the release." refers to, probably something before 0.10.0 as that falls between the two hashes above and both those show the same output locally.

ale5000-git commented 7 months ago

I have tried v0.10.0 on Windows and I didn't get any "info".

ale5000-git commented 7 months ago

So there 2 possibilities: 1) The bug doesn't happen on Windows, or 2) Dataflow Analysis is never active on Windows even when specifically asked.

brother commented 7 months ago

Interesting. Did you get other info lines? (maybe the severity setting is passed somewhere?).

ale5000-git commented 7 months ago

Sorry, I had an rc file in my repository and didn't remember it.

Now with --norc I get: Version 0.8.0 => OK Version 0.9.0 => issue Version 0.10.0 => issue

koalaman commented 7 months ago

The line does appear to be unreachable, but ShellCheck should probably still not warn about uninvoked functions.

ale5000-git commented 7 months ago

Just noticed now that all infos refer to the unused function.

In my opinion there should be a separate SC code (with a more clear message) for the unused functions (and just one per function).

brother commented 7 months ago

@ale5000-git maybe you can clean up the original report here and retitle the issue to make it to the point?

or close and open new if that's preferred.

stevecj commented 7 months ago

I am actually seeing Command appears to be unreachable. for every line in a function that actually is called from later in the script. The lines that call the function are reachable, and shellcheck does not claim otherwise. I am running v0.10.0.

ale5000-git commented 7 months ago

@stevecj Yours is a separate issue, also you need to post an example otherwise he cannot know why it happens.

koalaman commented 6 months ago

Unreachable functions now have a separate SC2329, and unreachable commands within them will no longer emit SC2317. This also fixes x=$(y) getting two separate SC2317, one for the assignment and one for the command in the substitution. Thanks!