In case anyone is still looking for information on this, there are a few ways to resolve this issue.
You can:
- set the path to the file with a
-P|--source-path=
- quiet the message with a disable directive
Each of these can be done in a few places. I'll cover each in turn.
In your .shellcheckrc file:
.shellcheckrc:
# tell shellcheck to look for include files in the users current directory
source-path=SCRIPTDIR
# or to disable these messages altogether (comma separated list)
# SC1090: Can't follow non-constant source. Use a directive to specify location.
disable=SC1090
In your source file:
main_file.sh:
# provide the path relative to where you opened the file
# shellcheck source=includes/source_file.sh
# if you've provided the path elsewhere (see below)
# or if the file is in your current path just the filename
# shellcheck source=source_file.sh
# or to disable these messages altogether (comma separated list)
# shellcheck disable=SC1090
In your .vimrc file:
" tell shellcheck to look for include files in the users current directory
let g:syntastic_sh_shellcheck_args="--external-sources --source-path=."
" or to quiet these messages altogether:
let g:syntastic_quiet_messages = { 'regex': 'SC2090' }
" to quiet multiple messages:
let g:syntastic_quiet_messages = { 'regex': 'SC2034\|SC2068\|SC2086\|SC2154' }
Debugging
Finally, it's worth noting that you can always run shellcheck from the command line. While this won't solve your vim problems directly, it can be useful for debugging. (One reason to keep disable directives in your shellcheckrc instead of vim.)
$ shellcheck --help
$ shellcheck -x -P . main_file.sh
In vim, you can see what your checker is sending to shellcheck by looking at the syntastic global variables from the current buffer. More involved debugging information can be found with :help syntastic-debug.
:echo g:syntastic_sh_shellcheck_args
:echo g:syntastic_quiet_messages
My solution
The solution that I've come to favor uses a per-project vimrc file in combination with a ftplugin file (or filetype autocmd).
First, to enable per-directory vimrc files:
~/.vimrc
set exrc " load .vimrc files in the current directory
set secure " limit commands run from .vimrc files outside of $HOME in some cases
Then in the project directory:
path/to/project/.vimrc
let g:syntastic_sh_include_dirs = 'src/include'
Finally, in my sh.vim file (https://vimways.org/2018/from-vimrc-to-vim/).
~/.vim/ftplugin/sh.vim
let g:syntastic_sh_shellcheck_args="--external-sources"
if exists('g:syntastic_sh_include_dirs')
let g:syntastic_sh_shellcheck_args .= " --source-path=" .. g:syntastic_sh_include_dirs
endif
Alternately, in a vimrc:
~/.vimrc
function! SetIncludeDirs()
if exists('g:syntastic_sh_include_dirs')
let g:syntastic_sh_shellcheck_args .= " --source-path=" .. g:syntastic_sh_include_dirs
endif
endfunction
augroup sh
autocmd!
autocmd call SetIncludeDirs()
augroup END
-xoption to theshellcheckchecker? – lcd047 Oct 22 '16 at 08:34.vimdirectory contents for theshellcheckexecution string and found none. – techraf Oct 22 '16 at 08:36