Shellcheck: `bats` integration errors

Created on 2 Jul 2016  路  4Comments  路  Source: koalaman/shellcheck

Firstly I had this issue: https://github.com/AtomLinter/linter-shellcheck/issues/67

But then I have tried to manually test the following file:

#!/usr/bin/env bats

@test "simple" {
  # [ "$output" == '' ]
  [ 1 -eq 1 ]
}

Here's the output:

In test.sh line 1:

!/usr/bin/env bats

^-- SC1008: This shebang was unrecognized. Note that ShellCheck only handles sh/bash/ksh.

In test.sh line 3:
@test "simple" {
^-- SC1083: This { is literal. Check expression (missing ;/\n?) or quote it.

In test.sh line 5:
[ 1 -eq 1 ]
^-- SC2050: This expression is constant. Did you forget the $ on a variable?

In test.sh line 6:
}
^-- SC1089: Parsing stopped here. Is this keyword correctly matched up?

Is it expected?

Most helpful comment

Neat! Bats support was also merged in https://github.com/koalaman/shellcheck/pull/1469 , but it's not yet part of a stable release.

All 4 comments

Preliminary bats support (from issue #417) is currently in a separate branch. It hasn't made it to the main branch due to a lack of testing and interest: https://github.com/koalaman/shellcheck/tree/bats

If you think native support would be useful, feel free to try out this branch and let me know how it works in practice (just reopen or comment on this issue).

In case anyone hits this issue, there is a pull request on bats-core to allow for a _bash compatible_ syntax. This would alleviate the need to do anything to shellcheck.

Neat! Bats support was also merged in https://github.com/koalaman/shellcheck/pull/1469 , but it's not yet part of a stable release.

This made bats support work for me on macOS 10.14.3 (Mojave):

brew --version
Homebrew 2.0.3
Homebrew/homebrew-core (git revision 7be50; last commit 2019-03-08)
Homebrew/homebrew-cask (git revision 9bd0e; last commit 2019-03-08)

brew unlink shellcheck
brew install cabal-install pandoc
brew install shellcheck --HEAD

I've solved an issue with vim-syntastic & bats files which might help others. Since a bats file is effectively a bash file, syntastic will run it through the sh shellchecker on save and will highlight false errors. The following config in .vim helped me fix this issue:

" Treat bats file like bash files
" Disable sh shellchecker to avoid false errors
" shellcheck will catch all errors
au BufRead,BufNewFile *.bats set ft=bash |
  \ let g:syntastic_sh_checkers = ['shellcheck']

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

szepeviktor picture szepeviktor  路  4Comments

balloonpopper picture balloonpopper  路  4Comments

bje- picture bje-  路  3Comments

helau picture helau  路  4Comments

koalaman picture koalaman  路  4Comments