summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles B Johnson <mail@cbjohnson.info>2020-04-08 18:52:53 -0500
committerCharles B Johnson <mail@cbjohnson.info>2021-01-22 09:23:53 -0600
commite75ac9f4975be35e4f33b955f473ba5e336c9ca0 (patch)
treedfbe99a46ed5382ffb42689deed3e35d3291a4f5
parent289f808ccd3098cb19bc3bbbb274524a4fb85ff7 (diff)
downloadale-e75ac9f4975be35e4f33b955f473ba5e336c9ca0.zip
fixers/xo: support typescript options
-rw-r--r--autoload/ale/fixers/xo.vim13
-rw-r--r--test/eslint-test-files/react-app/subdir/testfile.ts0
-rw-r--r--test/fixers/test_xo_fixer_callback.vader1
-rw-r--r--test/fixers/test_xots_fixer_callback.vader31
4 files changed, 43 insertions, 2 deletions
diff --git a/autoload/ale/fixers/xo.vim b/autoload/ale/fixers/xo.vim
index 06e58508..6c2901db 100644
--- a/autoload/ale/fixers/xo.vim
+++ b/autoload/ale/fixers/xo.vim
@@ -2,8 +2,17 @@
" Description: Fixing files with XO.
function! ale#fixers#xo#Fix(buffer) abort
- let l:executable = ale#handlers#xo#GetExecutable(a:buffer, 'javascript')
- let l:options = ale#handlers#xo#GetOptions(a:buffer, 'javascript')
+ 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)
return {
\ 'command': ale#node#Executable(a:buffer, l:executable)
diff --git a/test/eslint-test-files/react-app/subdir/testfile.ts b/test/eslint-test-files/react-app/subdir/testfile.ts
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/eslint-test-files/react-app/subdir/testfile.ts
diff --git a/test/fixers/test_xo_fixer_callback.vader b/test/fixers/test_xo_fixer_callback.vader
index 0bb3108a..d36fe74c 100644
--- a/test/fixers/test_xo_fixer_callback.vader
+++ b/test/fixers/test_xo_fixer_callback.vader
@@ -1,6 +1,7 @@
Before:
call ale#assert#SetUpFixerTest('javascript', 'xo')
runtime autoload/ale/handlers/xo.vim
+ set filetype=javascript
After:
call ale#assert#TearDownFixerTest()
diff --git a/test/fixers/test_xots_fixer_callback.vader b/test/fixers/test_xots_fixer_callback.vader
new file mode 100644
index 00000000..1ef6a6dd
--- /dev/null
+++ b/test/fixers/test_xots_fixer_callback.vader
@@ -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',
+ \ }