fixers/xo: support typescript options

This commit is contained in:
Charles B Johnson 2020-04-08 18:52:53 -05:00
parent 289f808ccd
commit e75ac9f497
No known key found for this signature in database
GPG key ID: 390184033B3454E3
4 changed files with 43 additions and 2 deletions

View file

@ -2,8 +2,17 @@
" 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:executable = ale#handlers#xo#GetExecutable(a:buffer, 'javascript') let l:filetype = getbufvar(a:buffer, '&filetype')
let l:options = ale#handlers#xo#GetOptions(a:buffer, 'javascript') 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)
return { return {
\ 'command': ale#node#Executable(a:buffer, l:executable) \ 'command': ale#node#Executable(a:buffer, l:executable)

View file

@ -1,6 +1,7 @@
Before: Before:
call ale#assert#SetUpFixerTest('javascript', 'xo') call ale#assert#SetUpFixerTest('javascript', 'xo')
runtime autoload/ale/handlers/xo.vim runtime autoload/ale/handlers/xo.vim
set filetype=javascript
After: After:
call ale#assert#TearDownFixerTest() call ale#assert#TearDownFixerTest()

View file

@ -0,0 +1,31 @@
Before:
call ale#assert#SetUpFixerTest('typescript', 'xo')
runtime autoload/ale/handlers/xo.vim
set filetype=typescript
After:
call ale#assert#TearDownFixerTest()
Execute(The xo callback should return the correct default values):
call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.ts')
AssertFixer
\ {
\ 'read_temporary_file': 1,
\ 'command': (has('win32') ? 'node.exe ' : '')
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/xo/cli.js'))
\ . ' --fix %t',
\ }
Execute(The xo callback should include custom xo options):
let g:ale_typescript_xo_options = '--space'
call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.ts')
AssertFixer
\ {
\ 'read_temporary_file': 1,
\ 'command': (has('win32') ? 'node.exe ' : '')
\ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/xo/cli.js'))
\ . ' --fix %t'
\ . ' --space',
\ }