]> git.madduck.net Git - etc/vim.git/blob - ale_linters/typescript/tslint.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / ale_linters / typescript / tslint.vim
1 " Author: Prashanth Chandra <https://github.com/prashcr>, Jonathan Clem <https://jclem.net>
2 " Description: tslint for TypeScript files
3
4 call ale#handlers#tslint#InitVariables()
5
6 function! ale_linters#typescript#tslint#Handle(buffer, lines) abort
7     " Do not output any errors for empty files if the option is on.
8     if ale#Var(a:buffer, 'typescript_tslint_ignore_empty_files')
9     \&& getbufline(a:buffer, 1, '$') == ['']
10         return []
11     endif
12
13     let l:dir = expand('#' . a:buffer . ':p:h')
14     let l:output = []
15
16     for l:error in ale#util#FuzzyJSONDecode(a:lines, [])
17         if get(l:error, 'ruleName', '') is# 'no-implicit-dependencies'
18             continue
19         endif
20
21         let l:item = {
22         \   'type': (get(l:error, 'ruleSeverity', '') is# 'WARNING' ? 'W' : 'E'),
23         \   'text': l:error.failure,
24         \   'lnum': l:error.startPosition.line + 1,
25         \   'col': l:error.startPosition.character + 1,
26         \   'end_lnum': l:error.endPosition.line + 1,
27         \   'end_col': l:error.endPosition.character + 1,
28         \}
29
30         let l:filename = ale#path#GetAbsPath(l:dir, l:error.name)
31
32         " Assume temporary files are this file.
33         if !ale#path#IsTempName(l:filename)
34             let l:item.filename = l:filename
35         endif
36
37         if has_key(l:error, 'ruleName')
38             let l:item.code = l:error.ruleName
39         endif
40
41         call add(l:output, l:item)
42     endfor
43
44     return l:output
45 endfunction
46
47 function! ale_linters#typescript#tslint#GetCommand(buffer) abort
48     let l:tslint_config_path = ale#path#ResolveLocalPath(
49     \   a:buffer,
50     \   'tslint.json',
51     \   ale#Var(a:buffer, 'typescript_tslint_config_path')
52     \)
53     let l:tslint_config_option = !empty(l:tslint_config_path)
54     \   ? ' -c ' . ale#Escape(l:tslint_config_path)
55     \   : ''
56
57     let l:tslint_rules_dir = ale#Var(a:buffer, 'typescript_tslint_rules_dir')
58     let l:tslint_rules_option = !empty(l:tslint_rules_dir)
59     \  ? ' -r ' . ale#Escape(l:tslint_rules_dir)
60     \  : ''
61
62     return ale#Escape(ale#handlers#tslint#GetExecutable(a:buffer))
63     \   . ' --format json'
64     \   . l:tslint_config_option
65     \   . l:tslint_rules_option
66     \   . ' %t'
67 endfunction
68
69 call ale#linter#Define('typescript', {
70 \   'name': 'tslint',
71 \   'executable': function('ale#handlers#tslint#GetExecutable'),
72 \   'cwd': '%s:h',
73 \   'command': function('ale_linters#typescript#tslint#GetCommand'),
74 \   'callback': 'ale_linters#typescript#tslint#Handle',
75 \})