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

SC1090 does not recognize `~` as a single expansion #3022

Open sparr opened 4 months ago

sparr commented 4 months ago

For bugs

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

#!/bin/bash
. "${HOME}"/foo.sh
. ~/foo.sh

Here's what shellcheck currently says:

[Line 2:](javascript:setPosition(2, 3))
. "${HOME}"/foo.sh
  ^-- [SC1091](https://www.shellcheck.net/wiki/SC1091) (info): Not following: ./foo.sh was not specified as input (see shellcheck -x).

[Line 3:](javascript:setPosition(3, 3))
. ~/foo.sh
  ^-- [SC1090](https://www.shellcheck.net/wiki/SC1090) (warning): ShellCheck can't follow non-constant source. Use a directive to specify location.

Here's what I wanted or expected to see:

Line 3 should recognize ~ as [approximately] equivalent to $HOME and pass SC1090 with the "strip a single expansion followed by a slash" exception described on the wiki, instead behaving like Line 2 and triggering SC1091 (or, if run with shellcheck -x, succeeding as Line 2 would)