Fix #257 in preparation for #427, standardise options with fallbacks, and make it so every value can be computed dynamically

This commit is contained in:
w0rp 2017-04-15 13:35:54 +01:00
parent 2f009690c3
commit 706dd050f2
16 changed files with 69 additions and 36 deletions

View file

@ -4,12 +4,16 @@
" Set this option to change the cppcheck options " Set this option to change the cppcheck options
let g:ale_c_cppcheck_options = get(g:, 'ale_c_cppcheck_options', '--enable=style') let g:ale_c_cppcheck_options = get(g:, 'ale_c_cppcheck_options', '--enable=style')
function! ale_linters#c#cppcheck#GetCommand(buffer) abort
return 'cppcheck -q --language=c '
\ . g:ale_c_cppcheck_options
\ . ' %t'
endfunction
call ale#linter#Define('c', { call ale#linter#Define('c', {
\ 'name': 'cppcheck', \ 'name': 'cppcheck',
\ 'output_stream': 'both', \ 'output_stream': 'both',
\ 'executable': 'cppcheck', \ 'executable': 'cppcheck',
\ 'command': 'cppcheck -q --language=c ' \ 'command_callback': 'ale_linters#c#cppcheck#GetCommand',
\ . g:ale_c_cppcheck_options
\ . ' %t',
\ 'callback': 'ale#handlers#HandleCppCheckFormat', \ 'callback': 'ale#handlers#HandleCppCheckFormat',
\}) \})

View file

@ -62,4 +62,3 @@ call ale#linter#Define('elm', {
\ 'command_callback': 'ale_linters#elm#make#GetCommand', \ 'command_callback': 'ale_linters#elm#make#GetCommand',
\ 'callback': 'ale_linters#elm#make#Handle' \ 'callback': 'ale_linters#elm#make#Handle'
\}) \})

View file

@ -5,6 +5,7 @@ let g:ale_erlang_erlc_options = get(g:, 'ale_erlang_erlc_options', '')
function! ale_linters#erlang#erlc#GetCommand(buffer) abort function! ale_linters#erlang#erlc#GetCommand(buffer) abort
let l:output_file = tempname() let l:output_file = tempname()
call ale#engine#ManageFile(a:buffer, l:output_file) call ale#engine#ManageFile(a:buffer, l:output_file)
return 'erlc -o ' . fnameescape(l:output_file) . ' ' . g:ale_erlang_erlc_options . ' %t' return 'erlc -o ' . fnameescape(l:output_file) . ' ' . g:ale_erlang_erlc_options . ' %t'
endfunction endfunction

View file

@ -52,12 +52,16 @@ function! ale_linters#fortran#gcc#Handle(buffer, lines) abort
return l:output return l:output
endfunction endfunction
function! ale_linters#fortran#gcc#GetCommand(buffer) abort
return 'gcc -S -x f95 -fsyntax-only -ffree-form '
\ . g:ale_fortran_gcc_options
\ . ' -'
endfunction
call ale#linter#Define('fortran', { call ale#linter#Define('fortran', {
\ 'name': 'gcc', \ 'name': 'gcc',
\ 'output_stream': 'stderr', \ 'output_stream': 'stderr',
\ 'executable': 'gcc', \ 'executable': 'gcc',
\ 'command': 'gcc -S -x f95 -fsyntax-only -ffree-form ' \ 'command_callback': 'ale_linters#fortran#gcc#GetCommand',
\ . g:ale_fortran_gcc_options
\ . ' -',
\ 'callback': 'ale_linters#fortran#gcc#Handle', \ 'callback': 'ale_linters#fortran#gcc#Handle',
\}) \})

View file

@ -3,7 +3,9 @@
" CLI options " CLI options
let g:ale_html_tidy_executable = get(g:, 'ale_html_tidy_executable', 'tidy') let g:ale_html_tidy_executable = get(g:, 'ale_html_tidy_executable', 'tidy')
let g:ale_html_tidy_args = get(g:, 'ale_html_tidy_args', '-q -e -language en') " Look for the old _args variable first.
let s:default_options = get(g:, 'ale_html_tidy_args', '-q -e -language en')
let g:ale_html_tidy_options = get(g:, 'ale_html_tidy_options', s:default_options)
function! ale_linters#html#tidy#GetCommand(buffer) abort function! ale_linters#html#tidy#GetCommand(buffer) abort
" Specify file encoding in options " Specify file encoding in options
@ -25,11 +27,15 @@ function! ale_linters#html#tidy#GetCommand(buffer) abort
return printf('%s %s %s -', return printf('%s %s %s -',
\ g:ale_html_tidy_executable, \ g:ale_html_tidy_executable,
\ g:ale_html_tidy_args, \ g:ale_html_tidy_options,
\ l:file_encoding \ l:file_encoding
\) \)
endfunction endfunction
function! ale_linters#html#tidy#GetExecutable(buffer) abort
return g:ale_html_tidy_executable
endfunction
function! ale_linters#html#tidy#Handle(buffer, lines) abort function! ale_linters#html#tidy#Handle(buffer, lines) abort
" Matches patterns lines like the following: " Matches patterns lines like the following:
" line 7 column 5 - Warning: missing </title> before </head> " line 7 column 5 - Warning: missing </title> before </head>
@ -63,7 +69,7 @@ endfunction
call ale#linter#Define('html', { call ale#linter#Define('html', {
\ 'name': 'tidy', \ 'name': 'tidy',
\ 'executable': g:ale_html_tidy_executable, \ 'executable_callback': 'ale_linters#html#tidy#GetExecutable',
\ 'output_stream': 'stderr', \ 'output_stream': 'stderr',
\ 'command_callback': 'ale_linters#html#tidy#GetCommand', \ 'command_callback': 'ale_linters#html#tidy#GetCommand',
\ 'callback': 'ale_linters#html#tidy#Handle', \ 'callback': 'ale_linters#html#tidy#Handle',

View file

@ -4,6 +4,15 @@
let g:ale_lua_luacheck_executable = let g:ale_lua_luacheck_executable =
\ get(g:, 'ale_lua_luacheck_executable', 'luacheck') \ get(g:, 'ale_lua_luacheck_executable', 'luacheck')
function! ale_linters#lua#luacheck#GetExecutable(buffer) abort
return g:ale_lua_luacheck_executable
endfunction
function! ale_linters#lua#luacheck#GetCommand(buffer) abort
return ale_linters#lua#luacheck#GetExecutable(a:buffer)
\ . ' --formatter plain --codes --filename %s -'
endfunction
function! ale_linters#lua#luacheck#Handle(buffer, lines) abort function! ale_linters#lua#luacheck#Handle(buffer, lines) abort
" Matches patterns line the following: " Matches patterns line the following:
" "
@ -33,7 +42,7 @@ endfunction
call ale#linter#Define('lua', { call ale#linter#Define('lua', {
\ 'name': 'luacheck', \ 'name': 'luacheck',
\ 'executable': g:ale_lua_luacheck_executable, \ 'executable_callback': 'ale_linters#lua#luacheck#GetExecutable',
\ 'command': g:ale_lua_luacheck_executable . ' --formatter plain --codes --filename %s -', \ 'command_callback': 'ale_linters#lua#luacheck#GetCommand',
\ 'callback': 'ale_linters#lua#luacheck#Handle', \ 'callback': 'ale_linters#lua#luacheck#Handle',
\}) \})

View file

@ -1,7 +1,6 @@
" Author: Baabelfish " Author: Baabelfish
" Description: Typechecking for nim files " Description: Typechecking for nim files
function! ale_linters#nim#nimcheck#Handle(buffer, lines) abort function! ale_linters#nim#nimcheck#Handle(buffer, lines) abort
let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p:t') let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p:t')
let l:pattern = '^\(.\+\.nim\)(\(\d\+\), \(\d\+\)) \(.\+\)' let l:pattern = '^\(.\+\.nim\)(\(\d\+\), \(\d\+\)) \(.\+\)'
@ -52,7 +51,10 @@ endfunction
function! ale_linters#nim#nimcheck#GetCommand(buffer) abort function! ale_linters#nim#nimcheck#GetCommand(buffer) abort
return 'nim check --path:' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h')) . ' --threads:on --verbosity:0 --colors:off --listFullPaths %t' let l:directory = fnameescape(fnamemodify(bufname(a:buffer), ':p:h'))
return 'nim check --path:' . l:directory
\ . ' --threads:on --verbosity:0 --colors:off --listFullPaths %t'
endfunction endfunction

View file

@ -2,7 +2,6 @@
" Description: nix-instantiate linter for nix files " Description: nix-instantiate linter for nix files
function! ale_linters#nix#nix#Handle(buffer, lines) abort function! ale_linters#nix#nix#Handle(buffer, lines) abort
let l:pattern = '^\(.\+\): \(.\+\), at .*:\(\d\+\):\(\d\+\)$' let l:pattern = '^\(.\+\): \(.\+\), at .*:\(\d\+\):\(\d\+\)$'
let l:output = [] let l:output = []

View file

@ -4,6 +4,12 @@
" Set to change the ruleset " Set to change the ruleset
let g:ale_php_phpmd_ruleset = get(g:, 'ale_php_phpmd_ruleset', 'cleancode,codesize,controversial,design,naming,unusedcode') let g:ale_php_phpmd_ruleset = get(g:, 'ale_php_phpmd_ruleset', 'cleancode,codesize,controversial,design,naming,unusedcode')
function! ale_linters#php#phpmd#GetCommand(buffer) abort
return 'phpmd %s text '
\ . g:ale_php_phpmd_ruleset
\ . ' --ignore-violations-on-exit %t'
endfunction
function! ale_linters#php#phpmd#Handle(buffer, lines) abort function! ale_linters#php#phpmd#Handle(buffer, lines) abort
" Matches against lines like the following: " Matches against lines like the following:
" "
@ -33,6 +39,6 @@ endfunction
call ale#linter#Define('php', { call ale#linter#Define('php', {
\ 'name': 'phpmd', \ 'name': 'phpmd',
\ 'executable': 'phpmd', \ 'executable': 'phpmd',
\ 'command': 'phpmd %s text ' . g:ale_php_phpmd_ruleset . ' --ignore-violations-on-exit %t', \ 'command_callback': 'ale_linters#php#phpmd#GetCommand',
\ 'callback': 'ale_linters#php#phpmd#Handle', \ 'callback': 'ale_linters#php#phpmd#Handle',
\}) \})

View file

@ -4,8 +4,10 @@
let g:ale_python_flake8_executable = let g:ale_python_flake8_executable =
\ get(g:, 'ale_python_flake8_executable', 'flake8') \ get(g:, 'ale_python_flake8_executable', 'flake8')
let g:ale_python_flake8_args = " Support an old setting as a fallback.
\ get(g:, 'ale_python_flake8_args', '') let s:default_options = get(g:, 'ale_python_flake8_args', '')
let g:ale_python_flake8_options =
\ get(g:, 'ale_python_flake8_options', s:default_options)
" A map from Python executable paths to semver strings parsed for those " A map from Python executable paths to semver strings parsed for those
" executables, so we don't have to look up the version number constantly. " executables, so we don't have to look up the version number constantly.

View file

@ -53,7 +53,7 @@ function! g:ale_linters#python#mypy#Handle(buffer, lines) abort
return l:output return l:output
endfunction endfunction
call g:ale#linter#Define('python', { call ale#linter#Define('python', {
\ 'name': 'mypy', \ 'name': 'mypy',
\ 'executable': 'mypy', \ 'executable': 'mypy',
\ 'command_callback': 'ale_linters#python#mypy#GetCommand', \ 'command_callback': 'ale_linters#python#mypy#GetCommand',

View file

@ -1,12 +1,6 @@
" Author: Paulo Alem <paulo.alem@gmail.com> " Author: Paulo Alem <paulo.alem@gmail.com>
" Description: Rudimentary SML checking with smlnj compiler " Description: Rudimentary SML checking with smlnj compiler
if exists('g:loaded_ale_sml_smlnj_checker')
finish
endif
let g:loaded_ale_sml_smlnj_checker = 1
function! ale_linters#sml#smlnj#Handle(buffer, lines) abort function! ale_linters#sml#smlnj#Handle(buffer, lines) abort
" Try to match basic sml errors " Try to match basic sml errors

View file

@ -5,20 +5,25 @@
let g:ale_vim_vint_show_style_issues = let g:ale_vim_vint_show_style_issues =
\ get(g:, 'ale_vim_vint_show_style_issues', 1) \ get(g:, 'ale_vim_vint_show_style_issues', 1)
let s:warning_flag = g:ale_vim_vint_show_style_issues ? '-s' : '-w'
let s:vint_version = ale#semver#Parse(system('vint --version')) let s:vint_version = ale#semver#Parse(system('vint --version'))
let s:has_no_color_support = ale#semver#GreaterOrEqual(s:vint_version, [0, 3, 7]) let s:has_no_color_support = ale#semver#GreaterOrEqual(s:vint_version, [0, 3, 7])
let s:enable_neovim = has('nvim') ? ' --enable-neovim ' : '' let s:enable_neovim = has('nvim') ? ' --enable-neovim ' : ''
let s:format = '-f "{file_path}:{line_number}:{column_number}: {severity}: {description} (see {reference})"' let s:format = '-f "{file_path}:{line_number}:{column_number}: {severity}: {description} (see {reference})"'
call ale#linter#Define('vim', { function! ale_linters#vim#vint#GetCommand(buffer) abort
\ 'name': 'vint', let l:warning_flag = g:ale_vim_vint_show_style_issues ? '-s' : '-w'
\ 'executable': 'vint',
\ 'command': 'vint ' return 'vint '
\ . s:warning_flag . ' ' \ . l:warning_flag . ' '
\ . (s:has_no_color_support ? '--no-color ' : '') \ . (s:has_no_color_support ? '--no-color ' : '')
\ . s:enable_neovim \ . s:enable_neovim
\ . s:format \ . s:format
\ . ' %t', \ . ' %t'
endfunction
call ale#linter#Define('vim', {
\ 'name': 'vint',
\ 'executable': 'vint',
\ 'command_callback': 'ale_linters#vim#vint#GetCommand',
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
\}) \})

View file

@ -71,5 +71,7 @@ check_errors ' \+$' 'Trailing whitespace'
check_errors '^ * end\?i\? *$' 'Write endif, not en, end, or endi' check_errors '^ * end\?i\? *$' 'Write endif, not en, end, or endi'
check_errors '^ [^ ]' 'Use four spaces, not two spaces' check_errors '^ [^ ]' 'Use four spaces, not two spaces'
check_errors $'\t' 'Use four spaces, not tabs' check_errors $'\t' 'Use four spaces, not tabs'
# This check should prevent people from using a particular inconsistent name.
check_errors 'let g:ale_\w\+_\w\+_args =' 'Name your option g:ale_<filetype>_<lintername>_options instead'
exit $RETURN_CODE exit $RETURN_CODE

View file

@ -47,7 +47,7 @@ g:ale_html_tidy_executable *g:ale_html_tidy_executable*
This variable can be changed to change the path to tidy. This variable can be changed to change the path to tidy.
g:ale_html_tidy_args *g:ale_html_tidy_args* g:ale_html_tidy_options *g:ale_html_tidy_options*
Type: |String| Type: |String|
Default: `'-q -e -language en'` Default: `'-q -e -language en'`

View file

@ -13,7 +13,7 @@ g:ale_python_flake8_executable *g:ale_python_flake8_executable*
This variable can be changed to modify the executable used for flake8. This variable can be changed to modify the executable used for flake8.
g:ale_python_flake8_args *g:ale_python_flake8_args* g:ale_python_flake8_options *g:ale_python_flake8_options*
Type: |String| Type: |String|
Default: `''` Default: `''`
@ -25,7 +25,7 @@ g:ale_python_flake8_args *g:ale_python_flake8_args*
Python 3, you may want to set > Python 3, you may want to set >
let g:ale_python_flake8_executable = 'python3' " or 'python' for Python 2 let g:ale_python_flake8_executable = 'python3' " or 'python' for Python 2
let g:ale_python_flake8_args = '-m flake8' let g:ale_python_flake8_options = '-m flake8'
< <
after making sure it's installed for the appropriate Python versions (e.g. after making sure it's installed for the appropriate Python versions (e.g.
`python3 -m pip install --user flake8`). `python3 -m pip install --user flake8`).