6

I have a Bash script which sources variables from another file. It passes the shellcheck -x, however Syntastic always complains:

Not following: sourced_file.sh was not specified as input (see shellcheck -x). [SC1091]

The script is:

#!/bin/bash

. sourced_file.sh

echo ${variable1}

The sourced_file.sh is:

variable1="value1"

I tried to add a directive (although I understand directives are supposed to be used only in case of a filename not given explicitly and here it is a static include):

# shellcheck source=main_file.sh

But it did not resolve the issue.

I don't want to disable the check completely. How can I tell Syntastic to source the file?

  • 1
    Have you considered adding the -x option to the shellcheck checker? – lcd047 Oct 22 '16 at 8:34
  • How can I do it? That's basically my question. I grepped .vim directory contents for the shellcheck execution string and found none. – techraf Oct 22 '16 at 8:36
  • The use of that feature is restricted to people who invest a few minutes into reading the manual. :) – lcd047 Oct 22 '16 at 8:38
  • 1
    Do you have any suggestions for improvement of this question? Because that's what the comment section is intended for on StackExchange. – techraf Oct 23 '16 at 0:16
  • Did you try the suggestion in the FAQ? – Herb Wolfe Oct 23 '16 at 0:38
10

As noted, the FAQ says:

4.5. Q. How can I pass additional arguments to a checker?

A. In most cases a command line is constructed using an internal function named makeprgBuild(), which provides a number of options that allow you to customise every part of the command that gets run. You can set these options using global variables.

The general form of the global args variable is syntastic_<filetype>_<checker>_args. Thus if you wanted to pass --my --args --here to the Ruby mri checker you would add this line to your vimrc:

let g:syntastic_ruby_mri_args = "--my --args --here"

See :help syntastic-checker-options for more information.

So, I'd expect something like this to work:

let g:syntastic_sh_shellcheck_args = "-x"
|improve this answer|||||
  • If you start answering trivial questions you'll end up with a deluge of trivialities. Syntastic is really meant to be a development tool, it isn't supposed to be used without reading the manual. Then again, this arrangement could work for me: if you guys are happy to answer questions like the OP, I could start bouncing them here from the issue tracker... – lcd047 Oct 23 '16 at 5:25
  • 5
    @lcd047 that's not why I answered this. I answered this because OP had taken the effort of reading the manual, but for whatever reason was digging in the wrong direction. It happens to all of us sometimes, especially if we are frustrated and not thinking straight. – muru Oct 23 '16 at 5:39
  • I imagine that the answer was a facepalm moment for the OP. :) – muru Oct 23 '16 at 5:40
  • 5
    I'd just like to add questions / answers like these are really valuable - I've found this with a quick Google search and it solves my problem. – Chris Stryczynski Oct 30 '17 at 11:26
2

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
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.