xo: inline filetype handling

This commit is contained in:
Charles B Johnson 2021-01-19 22:16:10 -06:00
parent 23ff19a162
commit 4edfac4db6
No known key found for this signature in database
GPG key ID: 390184033B3454E3
4 changed files with 31 additions and 22 deletions

View file

@ -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',
\})

View file

@ -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',
\})

View file

@ -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,

View file

@ -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