summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles B Johnson <mail@cbjohnson.info>2021-01-19 22:16:10 -0600
committerCharles B Johnson <mail@cbjohnson.info>2021-01-22 09:23:54 -0600
commit4edfac4db64debcfd33d894f169d0c1dc6dc48a4 (patch)
treec15dfcefd85568d8066d194cfe7818ef253eada6
parent23ff19a162aadb048f3d5b2d4a4aa9cf3ec58a52 (diff)
downloadale-4edfac4db64debcfd33d894f169d0c1dc6dc48a4.zip
xo: inline filetype handling
-rw-r--r--ale_linters/javascript/xo.vim4
-rw-r--r--ale_linters/typescript/xo.vim4
-rw-r--r--autoload/ale/fixers/xo.vim13
-rw-r--r--autoload/ale/handlers/xo.vim32
4 files changed, 31 insertions, 22 deletions
diff --git a/ale_linters/javascript/xo.vim b/ale_linters/javascript/xo.vim
index 5b206df8..9cc1dc69 100644
--- a/ale_linters/javascript/xo.vim
+++ b/ale_linters/javascript/xo.vim
@@ -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',
\})
diff --git a/ale_linters/typescript/xo.vim b/ale_linters/typescript/xo.vim
index 13ae0cf7..2e25ba4c 100644
--- a/ale_linters/typescript/xo.vim
+++ b/ale_linters/typescript/xo.vim
@@ -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',
\})
diff --git a/autoload/ale/fixers/xo.vim b/autoload/ale/fixers/xo.vim
index 0f8f3ec6..dcf4c737 100644
--- a/autoload/ale/fixers/xo.vim
+++ b/autoload/ale/fixers/xo.vim
@@ -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,
diff --git a/autoload/ale/handlers/xo.vim b/autoload/ale/handlers/xo.vim
index 3f7c72cb..2439b4f9 100644
--- a/autoload/ale/handlers/xo.vim
+++ b/autoload/ale/handlers/xo.vim
@@ -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