Shellcheck: bats support

Created on 23 Jul 2015  路  16Comments  路  Source: koalaman/shellcheck

It would be nice if shellcheck supported/understood bats' @test nomenclature so that we could run shellcheck over bats input files.

Most helpful comment

I took a crack at this, but it seems to have more edge cases than I imagined.

I implemented the outlined additions, but bats apparently has a whole little DSL for including files and such that I didn't attempt to duplicate. It seems to work fine with bats' own tests.

If anyone wants to try it out, check the bats branch: https://github.com/koalaman/shellcheck/tree/bats

All 16 comments

+1

What would be required to do this?

  • Parse @test as brace groups
  • Ignore the variables status, lines and output
  • Assume bats in the shebang means bash

Am I missing anything?

I think that's it. If nothing else, it's a good start and the blanks can get filled in as we hit them.
Awesome thanks!

+1!

Any update on this? Otherwise a point in the right direction as to where we could help make this happen would be awesome!

Using bats-preprocess works well and preserves the original .bats file line numbers, column numbers, etc:

/usr/local/libexec/bats-preprocess < foo.bats | shellcheck -

Using this approach via Emacs + flycheck works well too: https://github.com/dougm/bats-mode/commit/001187c7544085c62c0141b380b43d8d77a497fb

@dougm I was looking for a solution that would eventually then be able to port to Atom - Plus it would be nice to be able to be checking Bats formatting with shellcheck instead of first processing it to bash.

@Skilgarriff agreed, it would be ideal for shellcheck to have native bats support.

I took a crack at this, but it seems to have more edge cases than I imagined.

I implemented the outlined additions, but bats apparently has a whole little DSL for including files and such that I didn't attempt to duplicate. It seems to work fine with bats' own tests.

If anyone wants to try it out, check the bats branch: https://github.com/koalaman/shellcheck/tree/bats

I just tested the bats branch with a few of my files. It works great :) Thanks!
(Note: I don't use the load feature extensively)

The bats branch is in version 0.4.4, latest master release is in 0.4.6.

@koalaman Is there something blocking the merging into master?

@edouard-lopez Lack of testing and interest.

Thanks to zmarouf for giving it a go.

@koalaman I use the bats branch for all my new shell projects and didn't notice issues so far. I'm using it through atom editor
Projects include:

I'm not using advanced features but still would recommend to merge to rise interest and feedback.

I'd love to see this merged. I depend heavily on Bats, and I hate having to disable Syntastic right now. (Might have to give @dougm's preprocessing approach a try, but it's a bit of a hack!)

Was this page helpful?
0 / 5 - 0 ratings