Merge branch 'tslint-rules'

This commit is contained in:
w0rp 2017-08-30 21:27:34 +01:00
commit 3bde390c58
3 changed files with 36 additions and 8 deletions

View File

@ -1,8 +1,9 @@
" Author: Prashanth Chandra https://github.com/prashcr " Author: Prashanth Chandra <https://github.com/prashcr>, Jonathan Clem <https://jclem.net>
" Description: tslint for TypeScript files " Description: tslint for TypeScript files
call ale#Set('typescript_tslint_executable', 'tslint') call ale#Set('typescript_tslint_executable', 'tslint')
call ale#Set('typescript_tslint_config_path', '') call ale#Set('typescript_tslint_config_path', '')
call ale#Set('typescript_tslint_rules_dir', '')
call ale#Set('typescript_tslint_use_global', 0) call ale#Set('typescript_tslint_use_global', 0)
function! ale_linters#typescript#tslint#GetExecutable(buffer) abort function! ale_linters#typescript#tslint#GetExecutable(buffer) abort
@ -38,15 +39,20 @@ function! ale_linters#typescript#tslint#GetCommand(buffer) abort
\ 'tslint.json', \ 'tslint.json',
\ ale#Var(a:buffer, 'typescript_tslint_config_path') \ ale#Var(a:buffer, 'typescript_tslint_config_path')
\) \)
let l:tslint_config_option = !empty(l:tslint_config_path) let l:tslint_config_option = !empty(l:tslint_config_path)
\ ? ' -c ' . ale#Escape(l:tslint_config_path) \ ? ' -c ' . ale#Escape(l:tslint_config_path)
\ : '' \ : ''
let l:tslint_rules_dir = ale#Var(a:buffer, 'typescript_tslint_rules_dir')
let l:tslint_rules_option = !empty(l:tslint_rules_dir)
\ ? ' -r ' . ale#Escape(l:tslint_rules_dir)
\ : ''
return ale#path#BufferCdString(a:buffer) return ale#path#BufferCdString(a:buffer)
\ . ale_linters#typescript#tslint#GetExecutable(a:buffer) \ . ale_linters#typescript#tslint#GetExecutable(a:buffer)
\ . ' --format json' \ . ' --format json'
\ . l:tslint_config_option \ . l:tslint_config_option
\ . l:tslint_rules_option
\ . ' %t' \ . ' %t'
endfunction endfunction

View File

@ -30,6 +30,14 @@ g:ale_typescript_tslint_config_path *g:ale_typescript_tslint_config_path*
such path exists, this variable will be used instead. such path exists, this variable will be used instead.
g:ale_typescript_tslint_rules_dir *g:ale_typescript_tslint_rules_dir*
*b:ale_typescript_tslint_rules_dir*
Type: |String|
Default: `''`
If this variable is set, ALE will use it as the rules directory for tslint.
g:ale_typescript_tslint_use_global *g:ale_typescript_tslint_use_global* g:ale_typescript_tslint_use_global *g:ale_typescript_tslint_use_global*
*b:ale_typescript_tslint_use_global* *b:ale_typescript_tslint_use_global*
Type: |Number| Type: |Number|

View File

@ -1,11 +1,13 @@
Before: Before:
Save g:typescript_tslint_executable Save g:ale_typescript_tslint_executable
Save g:typescript_tslint_config_path Save g:ale_typescript_tslint_config_path
Save g:typescript_tslint_use_global Save g:ale_typescript_tslint_rules_dir
Save g:ale_typescript_tslint_use_global
unlet! g:typescript_tslint_executable unlet! g:ale_typescript_tslint_executable
unlet! g:typescript_tslint_config_path unlet! g:ale_typescript_tslint_config_path
unlet! g:typescript_tslint_use_global unlet! g:ale_typescript_tslint_rules_dir
unlet! g:ale_typescript_tslint_use_global
runtime ale_linters/typescript/tslint.vim runtime ale_linters/typescript/tslint.vim
@ -14,6 +16,8 @@ Before:
After: After:
Restore Restore
unlet! b:ale_typescript_tslint_rules_dir
call ale#test#RestoreDirectory() call ale#test#RestoreDirectory()
call ale#linter#Reset() call ale#linter#Reset()
@ -22,3 +26,13 @@ Execute(The default tslint command should be correct):
\ 'cd ''' . expand('%:p:h') . ''' && ' \ 'cd ''' . expand('%:p:h') . ''' && '
\ . 'tslint --format json %t', \ . 'tslint --format json %t',
\ ale_linters#typescript#tslint#GetCommand(bufnr('')) \ ale_linters#typescript#tslint#GetCommand(bufnr(''))
Execute(The rules directory option should be included if set):
let b:ale_typescript_tslint_rules_dir = '/foo/bar'
AssertEqual
\ 'cd ''' . expand('%:p:h') . ''' && '
\ . 'tslint --format json'
\ . ' -r ' . ale#Escape('/foo/bar')
\ . ' %t',
\ ale_linters#typescript#tslint#GetCommand(bufnr(''))