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', {
|
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',
|
||||||
\})
|
\})
|
||||||
|
|
|
@ -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',
|
||||||
\})
|
\})
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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
|
||||||
|
|
Reference in a new issue