-
Notifications
You must be signed in to change notification settings - Fork 129
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
feat: support leading dynamic section when sourcing #1086
base: main
Are you sure you want to change the base?
Conversation
this can now handle all the below cases:. "$dir/file"
. "$dir/other/file"
. "$dir"/file
. $dir/file
. $dir"/file"
. "$dir"/"file"
. "${dir:-.}"/"file"
. ${dir}/"fi"l'e'
source "$dir/file" It intentionally fails on these:. "$dir/$file"
. "$dir/other/$file"
. "$(cmd)/file"
. $(cmd)/file |
is there a way to make it work? seems that's the much more usage case. |
potentially, but these cases are process substitution and dynamic file sourcing. if you really want to use process substitution, assign it to a variable, then use that - this way it will work with shellcheck too. as to dynamic file sourcing, at the point this is evaluated, there's no way to get the "static" value of a variable, so there's no meaningful way to support that. the current implementation matches shellcheck's behavior |
This does the same thing that ShellCheck does ([here](https://github.com/koalaman/shellcheck/blob/ba86c6363c30a5dbefd0b8b9a7c5f4ab0478dc91/src/ShellCheck/Parser.hs#L2277-L2283)). `To support the common pattern of . "$CONFIGDIR/mylib.sh", ShellCheck strips one leading, dynamic section before trying to locate the rest.` fixes bash-lsp#926, fixes bash-lsp#659
This fixes `${var}/path` and `"${var}"/path` as well as countless variations of these patterns Note: this turned out to be rather complex task, so it's broken out into a seperate function, which allows for early returns
This seemed the most appropriate place for it.
Adds a simple test for dynamic source paths and updates the snapshot to match new tests / behaivor. Note: all the line numbers in the snapshot increased by 2 because I added two new lines (the test and a blank one)
I added this to the bottom of the file to minimize snapshot diffs. they're large enough as it is.
🤔 ok, anyway, this looks was an good improvement. |
This would be great! All of our sources are of the form |
This does the same thing that ShellCheck does (here).
To support the common pattern of . "$CONFIGDIR/mylib.sh", ShellCheck strips one leading, dynamic section before trying to locate the rest.
fixes #926, fixes #659