shellcheck: check shebang first before linting instead of defaults to POSIX sh
ajhalili2006 opened this issue · comments
About this Issue
Currently, the extension will assume the shell script is written in purely dash (aka POSIX mode for bash), even through there's an explict usage of shebang pointing to bash.
Agree, extension ignores following shebang: #!/usr/bin/env bash
as well. It will check with sh
rules, which is wrong.
I have found 2 workarounds:
- Rename script to *.bash. Which usually is not suitable for me.
- Set this in global or local settings.json. Restart|Reload of vscode is needed in this case:
"linter.linters": {
"shellcheck": {
"args": ["--shell=bash"]
}
}
The latter works for me in most times as I am not pinned to core sh
shell.
It would be great if extension work correctly with shebangs.
I see that this extension calls ShellCheck with an explicit --shell sh
or --shell bash
based on the file extension here. I'm not sure why that's necessary when the command line tool appears to figure out the dialect from the shebang rather than the extension. The extension timonwong.shellcheck
appears to use a similar approach but only for extensions .ksh
, .bash
and .dash
.
When installed both fnando.linter
and timonwong.shellcheck
, disabling/uninstall the vscode-linter
helps to solve problems with Bash scripts as a quick workaround.
@fnando Adding the explicit --shell=sh
argument is a huge bug as it prevents shellcheck from correctly using the shebang of the file.
Sadly I will uninstall this extension as it is causing a huge amount of false-positives.