ShellDetect: fall back to filetype if no hashbang

Some files lack a hashbang line but still have an unambiguous filetype.
For example, the file `.zshrc` has the filetype `zsh`.

Augment ale#handlers#sh#GetShellType to fall back to the filetype if
no hashbang line can be found.
This commit is contained in:
Eddie Lebow
2019-11-23 00:06:03 -05:00
parent b91d82bfaa
commit 1997a8f7e2
2 changed files with 23 additions and 6 deletions

View File

@@ -98,6 +98,16 @@ Execute(The ksh dialect should be used for shellcheck if b:is_kornshell is 1):
AssertEqual 'ksh', ale_linters#sh#shellcheck#GetDialectArgument(bufnr(''))
Execute(The filetype should be used as the default shell type when there is no hashbang line):
set filetype=zsh
AssertEqual 'zsh', ale#handlers#sh#GetShellType(bufnr(''))
set filetype=tcsh
AssertEqual 'tcsh', ale#handlers#sh#GetShellType(bufnr(''))
set filetype=python
AssertEqual '', ale#handlers#sh#GetShellType(bufnr(''))
Given(A file with /bin/ash):
#!/bin/ash