xo: inline filetype handling
This commit is contained in:
parent
23ff19a162
commit
4edfac4db6
4 changed files with 31 additions and 22 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
call ale#linter#Define('javascript', {
|
||||
\ 'name': 'xo',
|
||||
\ 'executable': {b -> ale#handlers#xo#GetExecutable(b, 'javascript')},
|
||||
\ 'command': {b -> ale#handlers#xo#GetLintCommand(b, 'javascript')},
|
||||
\ 'executable': {b -> ale#handlers#xo#GetExecutable(b)},
|
||||
\ 'command': {b -> ale#handlers#xo#GetLintCommand(b)},
|
||||
\ 'callback': 'ale#handlers#xo#HandleJSON',
|
||||
\})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
call ale#linter#Define('typescript', {
|
||||
\ 'name': 'xo',
|
||||
\ 'executable': {b -> ale#handlers#xo#GetExecutable(b, 'typescript')},
|
||||
\ 'command': {b -> ale#handlers#xo#GetLintCommand(b, 'typescript')},
|
||||
\ 'executable': {b -> ale#handlers#xo#GetExecutable(b)},
|
||||
\ 'command': {b -> ale#handlers#xo#GetLintCommand(b)},
|
||||
\ 'callback': 'ale#handlers#xo#HandleJSON',
|
||||
\})
|
||||
|
|
|
@ -2,17 +2,8 @@
|
|||
" Description: Fixing files with XO.
|
||||
|
||||
function! ale#fixers#xo#Fix(buffer) abort
|
||||
let l:filetype = getbufvar(a:buffer, '&filetype')
|
||||
let l:type = ''
|
||||
|
||||
if l:filetype =~# 'javascript'
|
||||
let l:type = 'javascript'
|
||||
elseif l:filetype =~# 'typescript'
|
||||
let l:type = 'typescript'
|
||||
endif
|
||||
|
||||
let l:executable = ale#handlers#xo#GetExecutable(a:buffer, l:type)
|
||||
let l:options = ale#handlers#xo#GetOptions(a:buffer, l:type)
|
||||
let l:executable = ale#handlers#xo#GetExecutable(a:buffer)
|
||||
let l:options = ale#handlers#xo#GetOptions(a:buffer)
|
||||
|
||||
return ale#semver#RunWithVersionCheck(
|
||||
\ a:buffer,
|
||||
|
|
|
@ -6,21 +6,39 @@ call ale#Set('typescript_xo_executable', 'xo')
|
|||
call ale#Set('typescript_xo_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||
call ale#Set('typescript_xo_options', '')
|
||||
|
||||
function! ale#handlers#xo#GetExecutable(buffer, type) abort
|
||||
return ale#node#FindExecutable(a:buffer, a:type . '_xo', [
|
||||
function! ale#handlers#xo#GetExecutable(buffer) abort
|
||||
let l:filetype = getbufvar(a:buffer, '&filetype')
|
||||
let l:type = ''
|
||||
|
||||
if l:filetype =~# 'javascript'
|
||||
let l:type = 'javascript'
|
||||
elseif l:filetype =~# 'typescript'
|
||||
let l:type = 'typescript'
|
||||
endif
|
||||
|
||||
return ale#node#FindExecutable(a:buffer, l:type . '_xo', [
|
||||
\ 'node_modules/xo/cli.js',
|
||||
\ 'node_modules/.bin/xo',
|
||||
\])
|
||||
endfunction
|
||||
|
||||
function! ale#handlers#xo#GetLintCommand(buffer, type) abort
|
||||
return ale#Escape(ale#handlers#xo#GetExecutable(a:buffer, a:type))
|
||||
\ . ale#Pad(ale#handlers#xo#GetOptions(a:buffer, a:type))
|
||||
function! ale#handlers#xo#GetLintCommand(buffer) abort
|
||||
return ale#Escape(ale#handlers#xo#GetExecutable(a:buffer))
|
||||
\ . ale#Pad(ale#handlers#xo#GetOptions(a:buffer))
|
||||
\ . ' --reporter json --stdin --stdin-filename %s'
|
||||
endfunction
|
||||
|
||||
function! ale#handlers#xo#GetOptions(buffer, type) abort
|
||||
return ale#Var(a:buffer, a:type . '_xo_options')
|
||||
function! ale#handlers#xo#GetOptions(buffer) abort
|
||||
let l:filetype = getbufvar(a:buffer, '&filetype')
|
||||
let l:type = ''
|
||||
|
||||
if l:filetype =~# 'javascript'
|
||||
let l:type = 'javascript'
|
||||
elseif l:filetype =~# 'typescript'
|
||||
let l:type = 'typescript'
|
||||
endif
|
||||
|
||||
return ale#Var(a:buffer, l:type . '_xo_options')
|
||||
endfunction
|
||||
|
||||
" xo uses eslint and the output format is the same
|
||||
|
|
Reference in a new issue