Skip to content

Commit

Permalink
#2132 - Replace command_chain and chain_with with ale#command#Run
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rp committed Apr 7, 2019
1 parent cdf89f8 commit 3bebcb5
Show file tree
Hide file tree
Showing 48 changed files with 738 additions and 681 deletions.
5 changes: 1 addition & 4 deletions ale_linters/c/clang.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ call ale#linter#Define('c', {
\ 'name': 'clang',
\ 'output_stream': 'stderr',
\ 'executable': {b -> ale#Var(b, 'c_clang_executable')},
\ 'command_chain': [
\ {'callback': 'ale#c#GetMakeCommand', 'output_stream': 'stdout'},
\ {'callback': 'ale_linters#c#clang#GetCommand'}
\ ],
\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#c#clang#GetCommand'))},
\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes',
\})
5 changes: 1 addition & 4 deletions ale_linters/c/gcc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ call ale#linter#Define('c', {
\ 'name': 'gcc',
\ 'output_stream': 'stderr',
\ 'executable': {b -> ale#Var(b, 'c_gcc_executable')},
\ 'command_chain': [
\ {'callback': 'ale#c#GetMakeCommand', 'output_stream': 'stdout'},
\ {'callback': 'ale_linters#c#gcc#GetCommand'}
\ ],
\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#c#gcc#GetCommand'))},
\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes',
\})
5 changes: 1 addition & 4 deletions ale_linters/cpp/clang.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ call ale#linter#Define('cpp', {
\ 'name': 'clang',
\ 'output_stream': 'stderr',
\ 'executable': {b -> ale#Var(b, 'cpp_clang_executable')},
\ 'command_chain': [
\ {'callback': 'ale#c#GetMakeCommand', 'output_stream': 'stdout'},
\ {'callback': 'ale_linters#cpp#clang#GetCommand'},
\ ],
\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#cpp#clang#GetCommand'))},
\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes',
\})
5 changes: 1 addition & 4 deletions ale_linters/cpp/gcc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ call ale#linter#Define('cpp', {
\ 'aliases': ['g++'],
\ 'output_stream': 'stderr',
\ 'executable': {b -> ale#Var(b, 'cpp_gcc_executable')},
\ 'command_chain': [
\ {'callback': 'ale#c#GetMakeCommand', 'output_stream': 'stdout'},
\ {'callback': 'ale_linters#cpp#gcc#GetCommand'},
\ ],
\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#cpp#gcc#GetCommand'))},
\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes',
\})
21 changes: 15 additions & 6 deletions ale_linters/d/dmd.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: "dmd for D files"

function! ale_linters#d#dmd#DUBCommand(buffer) abort
function! ale_linters#d#dmd#GetDUBCommand(buffer) abort
" If we can't run dub, then skip this command.
if !executable('dub')
" Returning an empty string skips to the DMD command.
Expand All @@ -21,7 +21,18 @@ function! ale_linters#d#dmd#DUBCommand(buffer) abort
\ . ' && dub describe --import-paths'
endfunction

function! ale_linters#d#dmd#DMDCommand(buffer, dub_output) abort
function! ale_linters#d#dmd#RunDUBCommand(buffer) abort
let l:command = ale_linters#d#dmd#GetDUBCommand(a:buffer)

if empty(l:command)
" If we can't run DUB, just run DMD.
return ale_linters#d#dmd#DMDCommand(a:buffer, [], {})
endif

return ale#command#Run(a:buffer, l:command, function('ale_linters#d#dmd#DMDCommand'))
endfunction

function! ale_linters#d#dmd#DMDCommand(buffer, dub_output, meta) abort
let l:import_list = []

" Build a list of import paths generated from DUB, if available.
Expand Down Expand Up @@ -57,9 +68,7 @@ endfunction
call ale#linter#Define('d', {
\ 'name': 'dmd',
\ 'executable': 'dmd',
\ 'command_chain': [
\ {'callback': 'ale_linters#d#dmd#DUBCommand', 'output_stream': 'stdout'},
\ {'callback': 'ale_linters#d#dmd#DMDCommand', 'output_stream': 'stderr'},
\ ],
\ 'command': function('ale_linters#d#dmd#RunDUBCommand'),
\ 'callback': 'ale_linters#d#dmd#Handle',
\ 'output_stream': 'stderr',
\})
17 changes: 12 additions & 5 deletions ale_linters/erlang/syntaxerl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@

call ale#Set('erlang_syntaxerl_executable', 'syntaxerl')

function! ale_linters#erlang#syntaxerl#GetCommand(buffer, output) abort
function! ale_linters#erlang#syntaxerl#RunHelpCommand(buffer) abort
let l:executable = ale#Var(a:buffer, 'erlang_syntaxerl_executable')

return ale#command#Run(
\ a:buffer,
\ ale#Escape(l:executable) . ' -h',
\ function('ale_linters#erlang#syntaxerl#GetCommand'),
\)
endfunction

function! ale_linters#erlang#syntaxerl#GetCommand(buffer, output, meta) abort
let l:use_b_option = match(a:output, '\C\V-b, --base\>') > -1

return '%e' . (l:use_b_option ? ' -b %s %t' : ' %t')
Expand All @@ -27,9 +37,6 @@ endfunction
call ale#linter#Define('erlang', {
\ 'name': 'syntaxerl',
\ 'executable': {b -> ale#Var(b, 'erlang_syntaxerl_executable')},
\ 'command_chain': [
\ {'callback': {-> '%e -h'}},
\ {'callback': 'ale_linters#erlang#syntaxerl#GetCommand'},
\ ],
\ 'command': {b -> ale_linters#erlang#syntaxerl#RunHelpCommand(b)},
\ 'callback': 'ale_linters#erlang#syntaxerl#Handle',
\})
17 changes: 7 additions & 10 deletions ale_linters/eruby/erubi.vim
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
" Author: Eddie Lebow https://github.com/elebow
" Description: eruby checker using `erubi`

function! ale_linters#eruby#erubi#CheckErubi(buffer) abort
return 'ruby -r erubi/capture_end -e ' . ale#Escape('""')
endfunction

function! ale_linters#eruby#erubi#GetCommand(buffer, check_erubi_output) abort
function! ale_linters#eruby#erubi#GetCommand(buffer, output, meta) abort
let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)

if (!empty(a:check_erubi_output))
if !empty(a:output)
" The empty command in CheckErubi returns nothing if erubi runs and
" emits an error if erubi is not present
return ''
Expand All @@ -27,9 +23,10 @@ endfunction
call ale#linter#Define('eruby', {
\ 'name': 'erubi',
\ 'executable': 'ruby',
\ 'command_chain': [
\ {'callback': 'ale_linters#eruby#erubi#CheckErubi'},
\ {'callback': 'ale_linters#eruby#erubi#GetCommand', 'output_stream': 'stderr'},
\ ],
\ 'command': {buffer -> ale#command#Run(
\ buffer,
\ 'ruby -r erubi/capture_end -e ' . ale#Escape('""'),
\ function('ale_linters#eruby#erubi#GetCommand'),
\ )},
\ 'callback': 'ale#handlers#ruby#HandleSyntaxErrors',
\})
28 changes: 17 additions & 11 deletions ale_linters/java/javac.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,29 @@ call ale#Set('java_javac_executable', 'javac')
call ale#Set('java_javac_options', '')
call ale#Set('java_javac_classpath', '')

function! ale_linters#java#javac#GetImportPaths(buffer) abort
function! ale_linters#java#javac#RunWithImportPaths(buffer) abort
let l:command = ''
let l:pom_path = ale#path#FindNearestFile(a:buffer, 'pom.xml')

if !empty(l:pom_path) && executable('mvn')
return ale#path#CdString(fnamemodify(l:pom_path, ':h'))
let l:command = ale#path#CdString(fnamemodify(l:pom_path, ':h'))
\ . 'mvn dependency:build-classpath'
endif

let l:classpath_command = ale#gradle#BuildClasspathCommand(a:buffer)
" Try to use Gradle if Maven isn't available.
if empty(l:command)
let l:command = ale#gradle#BuildClasspathCommand(a:buffer)
endif

if !empty(l:classpath_command)
return l:classpath_command
if empty(l:command)
return ale_linters#java#javac#GetCommand(a:buffer, [], {})
endif

return ''
return ale#command#Run(
\ a:buffer,
\ l:command,
\ function('ale_linters#java#javac#GetCommand')
\)
endfunction

function! s:BuildClassPathOption(buffer, import_paths) abort
Expand All @@ -37,7 +45,7 @@ function! s:BuildClassPathOption(buffer, import_paths) abort
\ : ''
endfunction

function! ale_linters#java#javac#GetCommand(buffer, import_paths) abort
function! ale_linters#java#javac#GetCommand(buffer, import_paths, meta) abort
let l:cp_option = s:BuildClassPathOption(a:buffer, a:import_paths)
let l:sp_option = ''

Expand Down Expand Up @@ -120,9 +128,7 @@ endfunction
call ale#linter#Define('java', {
\ 'name': 'javac',
\ 'executable': {b -> ale#Var(b, 'java_javac_executable')},
\ 'command_chain': [
\ {'callback': 'ale_linters#java#javac#GetImportPaths', 'output_stream': 'stdout'},
\ {'callback': 'ale_linters#java#javac#GetCommand', 'output_stream': 'stderr'},
\ ],
\ 'command': function('ale_linters#java#javac#RunWithImportPaths'),
\ 'output_stream': 'stderr',
\ 'callback': 'ale_linters#java#javac#Handle',
\})
36 changes: 9 additions & 27 deletions ale_linters/javascript/flow.vim
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,13 @@ function! ale_linters#javascript#flow#GetExecutable(buffer) abort
\])
endfunction

function! ale_linters#javascript#flow#VersionCheck(buffer) abort
let l:executable = ale_linters#javascript#flow#GetExecutable(a:buffer)

if empty(l:executable)
return ''
endif

return ale#Escape(l:executable) . ' --version'
endfunction

function! ale_linters#javascript#flow#GetCommand(buffer, version_lines) abort
let l:executable = ale_linters#javascript#flow#GetExecutable(a:buffer)

if empty(l:executable)
return ''
endif

let l:version = ale#semver#GetVersion(l:executable, a:version_lines)

function! ale_linters#javascript#flow#GetCommand(buffer, version) abort
" If we can parse the version number, then only use --respect-pragma
" if the version is >= 0.36.0, which added the argument.
let l:use_respect_pragma = ale#Var(a:buffer, 'javascript_flow_use_respect_pragma')
\ && (empty(l:version) || ale#semver#GTE(l:version, [0, 36]))
\ && (empty(a:version) || ale#semver#GTE(a:version, [0, 36]))

return ale#Escape(l:executable)
\ . ' check-contents'
return '%e check-contents'
\ . (l:use_respect_pragma ? ' --respect-pragma': '')
\ . ' --json --from ale %s < %t'
\ . (!has('win32') ? '; echo' : '')
Expand Down Expand Up @@ -87,7 +68,6 @@ function! s:ExtraErrorMsg(current, new) abort
return l:newMsg
endfunction


function! s:GetDetails(error) abort
let l:detail = ''

Expand Down Expand Up @@ -169,10 +149,12 @@ endfunction
call ale#linter#Define('javascript', {
\ 'name': 'flow',
\ 'executable': function('ale_linters#javascript#flow#GetExecutable'),
\ 'command_chain': [
\ {'callback': 'ale_linters#javascript#flow#VersionCheck'},
\ {'callback': 'ale_linters#javascript#flow#GetCommand'},
\ ],
\ 'command': {buffer -> ale#semver#RunWithVersionCheck(
\ buffer,
\ ale_linters#javascript#flow#GetExecutable(buffer),
\ '%e --version',
\ function('ale_linters#javascript#flow#GetCommand'),
\ )},
\ 'callback': 'ale_linters#javascript#flow#Handle',
\ 'read_buffer': 0,
\})
41 changes: 22 additions & 19 deletions ale_linters/kotlin/kotlinc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,33 @@ let g:ale_kotlin_kotlinc_module_filename = get(g:, 'ale_kotlin_kotlinc_module_fi

let s:classpath_sep = has('unix') ? ':' : ';'

function! ale_linters#kotlin#kotlinc#GetImportPaths(buffer) abort
function! ale_linters#kotlin#kotlinc#RunWithImportPaths(buffer) abort
" exec maven/gradle only if classpath is not set
if ale#Var(a:buffer, 'kotlin_kotlinc_classpath') isnot# ''
return ''
else
let l:pom_path = ale#path#FindNearestFile(a:buffer, 'pom.xml')
return ale_linters#kotlin#kotlinc#GetCommand(a:buffer, [], {})
endif

if !empty(l:pom_path) && executable('mvn')
return ale#path#CdString(fnamemodify(l:pom_path, ':h'))
\ . 'mvn dependency:build-classpath'
endif
let l:pom_path = ale#path#FindNearestFile(a:buffer, 'pom.xml')

let l:classpath_command = ale#gradle#BuildClasspathCommand(a:buffer)
if !empty(l:pom_path) && executable('mvn')
let l:command = ale#path#CdString(fnamemodify(l:pom_path, ':h'))
\ . 'mvn dependency:build-classpath'
endif

if !empty(l:classpath_command)
return l:classpath_command
endif
" Try to use Gradle if Maven isn't available.
if empty(l:command)
let l:command = ale#gradle#BuildClasspathCommand(a:buffer)
endif

return ''
if empty(l:command)
return ale_linters#kotlin#kotlinc#GetCommand(a:buffer, [], {})
endif

return ale#command#Run(
\ a:buffer,
\ l:command,
\ function('ale_linters#kotlin#kotlinc#GetCommand')
\)
endfunction

function! s:BuildClassPathOption(buffer, import_paths) abort
Expand All @@ -46,7 +53,7 @@ function! s:BuildClassPathOption(buffer, import_paths) abort
\ : ''
endfunction

function! ale_linters#kotlin#kotlinc#GetCommand(buffer, import_paths) abort
function! ale_linters#kotlin#kotlinc#GetCommand(buffer, import_paths, meta) abort
let l:kotlinc_opts = ale#Var(a:buffer, 'kotlin_kotlinc_options')
let l:command = 'kotlinc '

Expand Down Expand Up @@ -165,11 +172,7 @@ endfunction
call ale#linter#Define('kotlin', {
\ 'name': 'kotlinc',
\ 'executable': 'kotlinc',
\ 'command_chain': [
\ {'callback': 'ale_linters#kotlin#kotlinc#GetImportPaths', 'output_stream': 'stdout'},
\ {'callback': 'ale_linters#kotlin#kotlinc#GetCommand', 'output_stream': 'stderr'},
\ ],
\ 'command': function('ale_linters#kotlin#kotlinc#RunWithImportPaths'),
\ 'callback': 'ale_linters#kotlin#kotlinc#Handle',
\ 'lint_file': 1,
\})

37 changes: 9 additions & 28 deletions ale_linters/php/phpstan.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,13 @@ let g:ale_php_phpstan_executable = get(g:, 'ale_php_phpstan_executable', 'phpsta
let g:ale_php_phpstan_level = get(g:, 'ale_php_phpstan_level', '4')
let g:ale_php_phpstan_configuration = get(g:, 'ale_php_phpstan_configuration', '')

function! ale_linters#php#phpstan#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'php_phpstan_executable')
endfunction

function! ale_linters#php#phpstan#VersionCheck(buffer) abort
let l:executable = ale_linters#php#phpstan#GetExecutable(a:buffer)

" If we have previously stored the version number in a cache, then
" don't look it up again.
if ale#semver#HasVersion(l:executable)
" Returning an empty string skips this command.
return ''
endif

let l:executable = ale#Escape(l:executable)

return l:executable . ' --version'
endfunction

function! ale_linters#php#phpstan#GetCommand(buffer, version_output) abort
function! ale_linters#php#phpstan#GetCommand(buffer, version) abort
let l:configuration = ale#Var(a:buffer, 'php_phpstan_configuration')
let l:configuration_option = !empty(l:configuration)
\ ? ' -c ' . l:configuration
\ : ''

let l:executable = ale_linters#php#phpstan#GetExecutable(a:buffer)
let l:version = ale#semver#GetVersion(l:executable, a:version_output)
let l:error_format = ale#semver#GTE(l:version, [0, 10, 3])
let l:error_format = ale#semver#GTE(a:version, [0, 10, 3])
\ ? ' --error-format raw'
\ : ' --errorFormat raw'

Expand Down Expand Up @@ -65,10 +44,12 @@ endfunction

call ale#linter#Define('php', {
\ 'name': 'phpstan',
\ 'executable': function('ale_linters#php#phpstan#GetExecutable'),
\ 'command_chain': [
\ {'callback': 'ale_linters#php#phpstan#VersionCheck'},
\ {'callback': 'ale_linters#php#phpstan#GetCommand'},
\ ],
\ 'executable': {b -> ale#Var(b, 'php_phpstan_executable')},
\ 'command': {buffer -> ale#semver#RunWithVersionCheck(
\ buffer,
\ ale#Var(buffer, 'php_phpstan_executable'),
\ '%e --version',
\ function('ale_linters#php#phpstan#GetCommand'),
\ )},
\ 'callback': 'ale_linters#php#phpstan#Handle',
\})
Loading

0 comments on commit 3bebcb5

Please sign in to comment.