Files
zeertzjqandGrant Hutchins eee7609f30 vim-patch:9.2.1254: filetype: Bats files are detected as sh
Problem:  Bats test files are detected as "sh", so plugins and parsers
          cannot tell them apart from plain Bash scripts, and Bats
          extensions are highlighted as plain Bash: the "test" in "@test"
          is highlighted as the test command and the test body is not a
          function body, so it does not fold.
Solution: Detect *.bats files and bats shebang lines as "bats", include
          filetype, indent and syntax scripts that reuse the "sh" ones
          with b:is_bash set, highlight @test with its name and fold its
          body like a function, highlight "# bats test_tags=" and
          "file_tags=" comments and the commands bats-core provides, and
          add a syntax test (Grant Hutchins).

Bats (Bash Automated Testing System) test files are Bash with extensions
such as `@test "name" { ... }` blocks, which Bash parsers like
tree-sitter-bash do not understand.  Tools that do need a filetype to key
on: bash-language-server parses .bats files with a bats dialect, ALE has
bats linters, and tree-sitter-bats provides a grammar for editors that
use tree-sitter.  Highlighting, indenting and the "sh" filetype plugin
behave as before, the same way the "bash" filetype works.

Commands from add-on libraries such as bats-assert are not highlighted.

related: vim/vim#14039
closes:  vim/vim#21516

https://github.com/vim/vim/commit/d8ae4348a0393c7e2b03f68541c3d1d920292165

Co-authored-by: Grant Hutchins <git@nertzy.com>
2026-10-31 08:46:05 +08:00

20 lines
458 B
VimL

" Vim filetype plugin file
" Language: Bats (Bash Automated Testing System)
" Maintainer: Grant Hutchins <git@nertzy.com>
" Last Change: 2026 Oct 12
"
" Bats test files are Bash scripts with a few extensions, such as @test
" blocks. Use the "sh" filetype plugin with b:is_bash set.
if exists("b:did_ftplugin")
finish
endif
unlet! b:is_sh
unlet! b:is_kornshell
let b:is_bash = 1
runtime! ftplugin/sh.vim ftplugin/sh_*.vim ftplugin/sh/*.vim
" vim: ts=8