From 07ebfbeef0ac3eb895182675c87cd5324bd3bf3c Mon Sep 17 00:00:00 2001 From: Carlos Ramos Date: Mon, 16 Oct 2017 00:53:17 -0400 Subject: Add new fixer tslint for typescript, fixes #932 --- autoload/ale/fix/registry.vim | 5 ++++ autoload/ale/fixers/tslint.vim | 22 +++++++++++++++ test/fixers/test_tslint_fixer_callback.vader | 41 ++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 autoload/ale/fixers/tslint.vim create mode 100644 test/fixers/test_tslint_fixer_callback.vader diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 93c0860d..93ddf0f5 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -102,6 +102,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['go'], \ 'description': 'Fix Go files with go fmt.', \ }, +\ 'tslint': { +\ 'function': 'ale#fixers#tslint#Fix', +\ 'suggested_filetypes': ['typescript'], +\ 'description': 'Fix typescript files with tslint --fix.', +\ }, \} " Reset the function registry to the default entries. diff --git a/autoload/ale/fixers/tslint.vim b/autoload/ale/fixers/tslint.vim new file mode 100644 index 00000000..4d905a08 --- /dev/null +++ b/autoload/ale/fixers/tslint.vim @@ -0,0 +1,22 @@ +" Author: carakan +" Description: Fixing files with tslint. + +function! ale#fixers#tslint#Fix(buffer) abort + let l:executable = ale_linters#typescript#tslint#GetExecutable(a:buffer) + + let l:tslint_config_path = ale#path#ResolveLocalPath( + \ a:buffer, + \ 'tslint.json', + \ ale#Var(a:buffer, 'typescript_tslint_config_path') + \) + let l:tslint_config_option = !empty(l:tslint_config_path) + \ ? ' -c ' . ale#Escape(l:tslint_config_path) + \ : '' + + return { + \ 'command': ale#node#Executable(a:buffer, l:executable) + \ . l:tslint_config_option + \ . ' --fix %t', + \ 'read_temporary_file': 1, + \} +endfunction diff --git a/test/fixers/test_tslint_fixer_callback.vader b/test/fixers/test_tslint_fixer_callback.vader new file mode 100644 index 00000000..73871137 --- /dev/null +++ b/test/fixers/test_tslint_fixer_callback.vader @@ -0,0 +1,41 @@ +Before: + Save g:ale_typescript_tslint_executable + Save g:ale_typescript_tslint_config_path + + let g:ale_typescript_tslint_executable = 'xxxinvalid' + let g:ale_typescript_tslint_config_path = '' + + call ale#test#SetDirectory('/testplugin/test/fixers') + silent cd .. + silent cd command_callback + let g:dir = getcwd() + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The tslint callback should return the correct default values): + call ale#test#SetFilename('../prettier-test-files/testfile.ts') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_typescript_tslint_executable) + \ . ' -c tslint.json' + \ . ' --fix %t', + \ }, + \ ale#fixers#tslint#Fix(bufnr('')) + +Execute(The tslint callback should include custom tslint config option): + let g:ale_typescript_tslint_config_path = '.tslintrc' + call ale#test#SetFilename('../prettier-test-files/testfile.ts') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_typescript_tslint_executable) + \ . ' -c ' . ale#Escape(g:ale_typescript_tslint_config_path) + \ . ' --fix %t', + \ }, + \ ale#fixers#tslint#Fix(bufnr('')) -- cgit v1.2.3 From 8a8879a28fe2decc06739fdd2244ea0e021625c0 Mon Sep 17 00:00:00 2001 From: Carlos Ramos Date: Mon, 16 Oct 2017 12:08:10 -0400 Subject: fix test't --- test/fixers/test_tslint_fixer_callback.vader | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fixers/test_tslint_fixer_callback.vader b/test/fixers/test_tslint_fixer_callback.vader index 73871137..5bfafe24 100644 --- a/test/fixers/test_tslint_fixer_callback.vader +++ b/test/fixers/test_tslint_fixer_callback.vader @@ -3,7 +3,7 @@ Before: Save g:ale_typescript_tslint_config_path let g:ale_typescript_tslint_executable = 'xxxinvalid' - let g:ale_typescript_tslint_config_path = '' + let g:ale_typescript_tslint_config_path = 'tslint.json' call ale#test#SetDirectory('/testplugin/test/fixers') silent cd .. @@ -22,7 +22,7 @@ Execute(The tslint callback should return the correct default values): \ { \ 'read_temporary_file': 1, \ 'command': ale#Escape(g:ale_typescript_tslint_executable) - \ . ' -c tslint.json' + \ . ' -c ' . ale#Escape('tslint.json') \ . ' --fix %t', \ }, \ ale#fixers#tslint#Fix(bufnr('')) -- cgit v1.2.3