mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-21 19:51:17 +08:00
Fix 3103 - add shellcheck shell directive detection. (#3216)
* Fix 3103 - add shellcheck shell directive detection. Searches for shellcheck shell directive to detect dialects for scripts that do not have shebang. * Change order of detection of shellcheck dialect In a situation where the filetype can be wrong (example: something.sh which is written in bash dialect) and has no hash-bang (since it is meant to be sourced) then the override specified within the script will be ignored. It probably is the most right thing to do if the script author has added a specific directive; it should trump everything else. Co-authored-by: Horacio Sanson <horacio@allm.inc> Co-authored-by: Dino Korah <dino.korah@redmatter.com>
This commit is contained in:
@@ -1,8 +1,32 @@
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Description: This file adds support for using the shellcheck linter
|
||||
|
||||
" Shellcheck supports shell directives to define the shell dialect for scripts
|
||||
" that do not have a shebang for some reason.
|
||||
" https://github.com/koalaman/shellcheck/wiki/Directive#shell
|
||||
function! ale#handlers#shellcheck#GetShellcheckDialectDirective(buffer) abort
|
||||
let l:linenr = 0
|
||||
let l:pattern = '\s\{-}#\s\{-}shellcheck\s\{-}shell=\(.*\)'
|
||||
let l:possible_shell = ['bash', 'dash', 'ash', 'tcsh', 'csh', 'zsh', 'ksh', 'sh']
|
||||
|
||||
while l:linenr < min([50, line('$')])
|
||||
let l:linenr += 1
|
||||
let l:match = matchlist(getline(l:linenr), l:pattern)
|
||||
|
||||
if len(l:match) > 1 && index(l:possible_shell, l:match[1]) >= 0
|
||||
return l:match[1]
|
||||
endif
|
||||
endwhile
|
||||
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! ale#handlers#shellcheck#GetDialectArgument(buffer) abort
|
||||
let l:shell_type = ale#handlers#sh#GetShellType(a:buffer)
|
||||
let l:shell_type = ale#handlers#shellcheck#GetShellcheckDialectDirective(a:buffer)
|
||||
|
||||
if empty(l:shell_type)
|
||||
let l:shell_type = ale#handlers#sh#GetShellType(a:buffer)
|
||||
endif
|
||||
|
||||
if !empty(l:shell_type)
|
||||
" Use the dash dialect for /bin/ash, etc.
|
||||
|
||||
Reference in New Issue
Block a user