概要
super linterをGitHub Actionsで使っていてShellCheckで下記エラーが出た。
SC1090: Can't follow non-constant source. Use a directive to specify location.
super linterバージョン
linter.yaml
uses: docker://github/super-linter:v3
https://github.com/github/super-linter
ローカル検証時のバージョン
$shellcheck --version ShellCheck - shell script analysis tool version: 0.7.1 license: GNU General Public License, version 3 website: https://www.shellcheck.net
原因
https://github.com/koalaman/shellcheck/wiki/SC1090
ShellCheck is not able to include sourced files from paths that are determined at runtime. The file will not be read, potentially resulting in warnings about unassigned variables and similar.
ShellCheckは静的解析ツールなので動的に実行時に動的に決まるディレクトリを解析できない。
解決方法
方法1
代わりに読み込める固定のパスを書く。パスが読み込めなければエラーになるので注意。
# shellcheck source=src/util.sh . "${util_path}"
方法2
無効にする。
# shellcheck source=/dev/null "${util_path}"
方法3
無効にする。下記のように特定のルールをdisableすることも可。
#shellcheck disable=SC1090 "${util_path}"
参考
ShellCheckのインストール方法
brew install shellcheck