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', { call ale#linter#Define('javascript', {
\ 'name': 'xo', \ 'name': 'xo',
\ 'executable': {b -> ale#handlers#xo#GetExecutable(b, 'javascript')}, \ 'executable': {b -> ale#handlers#xo#GetExecutable(b)},
\ 'command': {b -> ale#handlers#xo#GetLintCommand(b, 'javascript')}, \ 'command': {b -> ale#handlers#xo#GetLintCommand(b)},
\ 'callback': 'ale#handlers#xo#HandleJSON', \ 'callback': 'ale#handlers#xo#HandleJSON',
\}) \})

View file

@ -1,6 +1,6 @@
call ale#linter#Define('typescript', { call ale#linter#Define('typescript', {
\ 'name': 'xo', \ 'name': 'xo',
\ 'executable': {b -> ale#handlers#xo#GetExecutable(b, 'typescript')}, \ 'executable': {b -> ale#handlers#xo#GetExecutable(b)},
\ 'command': {b -> ale#handlers#xo#GetLintCommand(b, 'typescript')}, \ 'command': {b -> ale#handlers#xo#GetLintCommand(b)},
\ 'callback': 'ale#handlers#xo#HandleJSON', \ 'callback': 'ale#handlers#xo#HandleJSON',
\}) \})

View file

@ -2,17 +2,8 @@
" Description: Fixing files with XO. " Description: Fixing files with XO.
function! ale#fixers#xo#Fix(buffer) abort function! ale#fixers#xo#Fix(buffer) abort
let l:filetype = getbufvar(a:buffer, '&filetype') let l:executable = ale#handlers#xo#GetExecutable(a:buffer)
let l:type = '' let l:options = ale#handlers#xo#GetOptions(a:buffer)
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)
return ale#semver#RunWithVersionCheck( return ale#semver#RunWithVersionCheck(
\ a:buffer, \ 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_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('typescript_xo_options', '') call ale#Set('typescript_xo_options', '')
function! ale#handlers#xo#GetExecutable(buffer, type) abort function! ale#handlers#xo#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, a:type . '_xo', [ 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/xo/cli.js',
\ 'node_modules/.bin/xo', \ 'node_modules/.bin/xo',
\]) \])
endfunction endfunction
function! ale#handlers#xo#GetLintCommand(buffer, type) abort function! ale#handlers#xo#GetLintCommand(buffer) abort
return ale#Escape(ale#handlers#xo#GetExecutable(a:buffer, a:type)) return ale#Escape(ale#handlers#xo#GetExecutable(a:buffer))
\ . ale#Pad(ale#handlers#xo#GetOptions(a:buffer, a:type)) \ . ale#Pad(ale#handlers#xo#GetOptions(a:buffer))
\ . ' --reporter json --stdin --stdin-filename %s' \ . ' --reporter json --stdin --stdin-filename %s'
endfunction endfunction
function! ale#handlers#xo#GetOptions(buffer, type) abort function! ale#handlers#xo#GetOptions(buffer) abort
return ale#Var(a:buffer, a:type . '_xo_options') 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 endfunction
" xo uses eslint and the output format is the same " xo uses eslint and the output format is the same