diff options
author | Ian2020 <Ian2020@users.noreply.github.com> | 2020-05-08 12:55:54 +0100 |
---|---|---|
committer | Ian2020 <Ian2020@users.noreply.github.com> | 2020-05-08 12:55:54 +0100 |
commit | ca97f32258cc6e3f32b5f7605801f053e7dbe320 (patch) | |
tree | f593cbc9af75248f995f5eee23c3b46ad477829d | |
parent | 65bea1a5cbbc8ff2557410263c87c2e02cb4a42c (diff) | |
download | ale-ca97f32258cc6e3f32b5f7605801f053e7dbe320.zip |
Use a function to define shellcheck linters and vars needed, fixes tests
-rw-r--r-- | ale_linters/bats/shellcheck.vim | 11 | ||||
-rw-r--r-- | ale_linters/sh/shellcheck.vim | 10 | ||||
-rw-r--r-- | autoload/ale/handlers/shellcheck.vim | 46 | ||||
-rw-r--r-- | test/test_backwards_compatibility.vader | 2 |
4 files changed, 28 insertions, 41 deletions
diff --git a/ale_linters/bats/shellcheck.vim b/ale_linters/bats/shellcheck.vim index b5a1184b..5c2a0ea9 100644 --- a/ale_linters/bats/shellcheck.vim +++ b/ale_linters/bats/shellcheck.vim @@ -1,11 +1,4 @@ " Author: Ian2020 <https://github.com/Ian2020> -" Description: This file adds support for using the shellcheck linter with -" bats scripts. Heavily inspired by/copied from work by w0rp on shellcheck -" for sh files. +" Description: shellcheck linter for bats scripts. -call ale#linter#Define('bats', { -\ 'name': 'shellcheck', -\ 'executable': function('ale#handlers#shellcheck#GetExecutable'), -\ 'command': function('ale#handlers#shellcheck#GetCommand'), -\ 'callback': 'ale#handlers#shellcheck#Handle', -\}) +call ale#handlers#shellcheck#DefineLinter('bats') diff --git a/ale_linters/sh/shellcheck.vim b/ale_linters/sh/shellcheck.vim index fbd7e49b..d9945126 100644 --- a/ale_linters/sh/shellcheck.vim +++ b/ale_linters/sh/shellcheck.vim @@ -1,10 +1,4 @@ " Author: w0rp <devw0rp@gmail.com> -" Description: This file adds support for using the shellcheck linter with -" shell scripts. +" Description: shellcheck linter for shell scripts. -call ale#linter#Define('sh', { -\ 'name': 'shellcheck', -\ 'executable': function('ale#handlers#shellcheck#GetExecutable'), -\ 'command': function('ale#handlers#shellcheck#GetCommand'), -\ 'callback': 'ale#handlers#shellcheck#Handle', -\}) +call ale#handlers#shellcheck#DefineLinter('sh') diff --git a/autoload/ale/handlers/shellcheck.vim b/autoload/ale/handlers/shellcheck.vim index 2a5eadc3..b16280f0 100644 --- a/autoload/ale/handlers/shellcheck.vim +++ b/autoload/ale/handlers/shellcheck.vim @@ -1,16 +1,5 @@ " Author: w0rp <devw0rp@gmail.com> -" Description: This file adds support for using the shellcheck linter with -" shell scripts. - -" This global variable can be set with a string of comma-separated error -" codes to exclude from shellcheck. For example: -" -" let g:ale_sh_shellcheck_exclusions = 'SC2002,SC2004' -call ale#Set('sh_shellcheck_exclusions', get(g:, 'ale_linters_sh_shellcheck_exclusions', '')) -call ale#Set('sh_shellcheck_executable', 'shellcheck') -call ale#Set('sh_shellcheck_dialect', 'auto') -call ale#Set('sh_shellcheck_options', '') -call ale#Set('sh_shellcheck_change_directory', 1) +" Description: This file adds support for using the shellcheck linter function! ale#handlers#shellcheck#GetDialectArgument(buffer) abort let l:shell_type = ale#handlers#sh#GetShellType(a:buffer) @@ -36,7 +25,7 @@ function! ale#handlers#shellcheck#GetDialectArgument(buffer) abort return '' endfunction -function! ale#handlers#shellcheck#GetCommandWithVersion(buffer, version) abort +function! ale#handlers#shellcheck#GetCommand(buffer, version) abort let l:options = ale#Var(a:buffer, 'sh_shellcheck_options') let l:exclude_option = ale#Var(a:buffer, 'sh_shellcheck_exclusions') let l:dialect = ale#Var(a:buffer, 'sh_shellcheck_dialect') @@ -94,14 +83,25 @@ function! ale#handlers#shellcheck#Handle(buffer, lines) abort return l:output endfunction -function! ale#handlers#shellcheck#GetExecutable(buffer) abort - return ale#Var(a:buffer, 'sh_shellcheck_executable') -endfunction - -function! ale#handlers#shellcheck#GetCommand(buffer) abort - return ale#semver#RunWithVersionCheck(a:buffer, - \ ale#Var(a:buffer, 'sh_shellcheck_executable'), - \ '%e --version', - \ function('ale#handlers#shellcheck#GetCommandWithVersion'), - \) +function! ale#handlers#shellcheck#DefineLinter(filetype) abort + " This global variable can be set with a string of comma-separated error + " codes to exclude from shellcheck. For example: + " let g:ale_sh_shellcheck_exclusions = 'SC2002,SC2004' + call ale#Set('sh_shellcheck_exclusions', get(g:, 'ale_linters_sh_shellcheck_exclusions', '')) + call ale#Set('sh_shellcheck_executable', 'shellcheck') + call ale#Set('sh_shellcheck_dialect', 'auto') + call ale#Set('sh_shellcheck_options', '') + call ale#Set('sh_shellcheck_change_directory', 1) + + call ale#linter#Define(a:filetype, { + \ 'name': 'shellcheck', + \ 'executable': {buffer -> ale#Var(buffer, 'sh_shellcheck_executable')}, + \ 'command': {buffer -> ale#semver#RunWithVersionCheck( + \ buffer, + \ ale#Var(buffer, 'sh_shellcheck_executable'), + \ '%e --version', + \ function('ale#handlers#shellcheck#GetCommand'), + \ )}, + \ 'callback': 'ale#handlers#shellcheck#Handle', + \}) endfunction diff --git a/test/test_backwards_compatibility.vader b/test/test_backwards_compatibility.vader index e0e52bd4..e4e3756f 100644 --- a/test/test_backwards_compatibility.vader +++ b/test/test_backwards_compatibility.vader @@ -8,7 +8,7 @@ After: Execute(Old variable name for the 'shellcheck' linter should still work): let g:ale_linters_sh_shellcheck_exclusions = 'SC1234' - runtime autoload/ale/handlers/shellcheck.vim + runtime ale_linters/sh/shellcheck.vim AssertEqual 'SC1234', g:ale_sh_shellcheck_exclusions |