tslint parameterized executable and config path (#400)

* Allow modifying the location of the tsling executable

* Allow definition of config file path

* fnameescape configuration file
This commit is contained in:
Ruben Paz 2017-03-21 12:30:32 +00:00 committed by w0rp
parent 51729346bf
commit 5122dc498d
1 changed files with 27 additions and 4 deletions

View File

@ -1,6 +1,20 @@
" Author: Prashanth Chandra https://github.com/prashcr
" Description: tslint for TypeScript files
let g:ale_typescript_tslint_executable =
\ get(g:, 'ale_typescript_tslint_executable', 'tslint')
let g:ale_typescript_tslint_config_path =
\ get(g:, 'ale_typescript_tslint_config_path', '')
function! ale_linters#typescript#tslint#GetExecutable(buffer) abort
return ale#util#ResolveLocalPath(
\ a:buffer,
\ 'node_modules/.bin/tslint',
\ g:ale_typescript_tslint_executable
\)
endfunction
function! ale_linters#typescript#tslint#Handle(buffer, lines) abort
" Matches patterns like the following:
"
@ -37,15 +51,24 @@ function! ale_linters#typescript#tslint#Handle(buffer, lines) abort
endfunction
function! ale_linters#typescript#tslint#BuildLintCommand(buffer) abort
let l:tsconfig_path = ale#util#FindNearestFile(a:buffer, 'tslint.json')
let l:tslint_options = empty(l:tsconfig_path) ? '' : '-c ' . l:tsconfig_path
let g:ale_typescript_tslint_config_path =
\ empty(g:ale_typescript_tslint_config_path) ?
\ ale#util#FindNearestFile(a:buffer, 'tslint.json')
\ : g:ale_typescript_tslint_config_path
return 'tslint ' . l:tslint_options . ' %t'
let l:tslint_options =
\ empty(g:ale_typescript_tslint_config_path) ?
\ ''
\ : '-c ' . fnameescape(g:ale_typescript_tslint_config_path)
return ale_linters#typescript#tslint#GetExecutable(a:buffer)
\ . ' ' . l:tslint_options
\ . ' %t'
endfunction
call ale#linter#Define('typescript', {
\ 'name': 'tslint',
\ 'executable': 'tslint',
\ 'executable_callback': 'ale_linters#typescript#tslint#GetExecutable',
\ 'command_callback': 'ale_linters#typescript#tslint#BuildLintCommand',
\ 'callback': 'ale_linters#typescript#tslint#Handle',
\})