From 5122dc498d4cc6a4fe17c66dcedd2d8ff04ed8c3 Mon Sep 17 00:00:00 2001 From: Ruben Paz Date: Tue, 21 Mar 2017 12:30:32 +0000 Subject: [PATCH] tslint parameterized executable and config path (#400) * Allow modifying the location of the tsling executable * Allow definition of config file path * fnameescape configuration file --- ale_linters/typescript/tslint.vim | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/ale_linters/typescript/tslint.vim b/ale_linters/typescript/tslint.vim index 2f4d235..8eeb98d 100644 --- a/ale_linters/typescript/tslint.vim +++ b/ale_linters/typescript/tslint.vim @@ -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', \})