Add new fixer tslint for typescript, fixes #932
This commit is contained in:
parent
a790077136
commit
07ebfbeef0
3 changed files with 68 additions and 0 deletions
|
@ -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.
|
||||
|
|
22
autoload/ale/fixers/tslint.vim
Normal file
22
autoload/ale/fixers/tslint.vim
Normal file
|
@ -0,0 +1,22 @@
|
|||
" Author: carakan <carakan@gmail.com>
|
||||
" 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
|
41
test/fixers/test_tslint_fixer_callback.vader
Normal file
41
test/fixers/test_tslint_fixer_callback.vader
Normal file
|
@ -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(''))
|
Reference in a new issue