Skip to content

Commit 873d439

Browse files
committed
Update tsc check to read from config if present
See microsoft/TypeScript#5858, fixes neomake#200. Thanks to @HerringtonDarkholme for doing all the work.
1 parent efed015 commit 873d439

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

autoload/neomake/makers/ft/typescript.vim

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,54 @@ function! neomake#makers#ft#typescript#EnabledMakers()
44
return ['tsc', 'tslint']
55
endfunction
66

7+
let s:enabled_options = [
8+
\ 'target',
9+
\ 'emitDecoratorMetadata',
10+
\ 'experimentalDecorators',
11+
\ 'module',
12+
\ 'noImplicitAny',
13+
\ 'rootDir',
14+
\ 'noEmit',
15+
\ 'allowSyntheticDefaultImports',
16+
\ 'noImplicitReturn',
17+
\ 'allowUnreachableCode',
18+
\ 'allowUnusedLabels'
19+
\ ]
20+
721
function! neomake#makers#ft#typescript#tsc()
22+
let l:tsconfig = findfile('tsconfig.json', '.;')
23+
if len(l:tsconfig)
24+
let true = 1
25+
let false = 0
26+
let null = 0
27+
" ugly shortcut
28+
let l:jsonText = join(readfile(l:tsconfig, 'b'), '')
29+
let l:json = eval(l:jsonText)
30+
let l:option = get(l:json, 'compilerOptions', {})
31+
let l:option['noEmit'] = 1
32+
let l:args = []
33+
if !len(get(l:option, 'rootDir', ''))
34+
let l:option['rootDir'] = fnamemodify(l:tsconfig, ':h')
35+
endif
36+
for [key, value] in items(l:option)
37+
if index(s:enabled_options, key) == -1
38+
continue
39+
endif
40+
if value == 1
41+
call insert(l:args, '--'.key)
42+
elseif type(value) == type('')
43+
call insert(l:args, value)
44+
call insert(l:args, '--'.key)
45+
endif
46+
endfor
47+
else
48+
let l:args = [
49+
\ '-m', 'commonjs', '--noEmit', '--rootDir', '.'
50+
\ ]
51+
endif
52+
853
return {
9-
\ 'args': [
10-
\ '-m', 'commonjs', '--noEmit'
11-
\ ],
54+
\ 'args': l:args,
1255
\ 'errorformat':
1356
\ '%E%f %#(%l\,%c): error %m,' .
1457
\ '%E%f %#(%l\,%c): %m,' .

0 commit comments

Comments
 (0)