]> git.madduck.net Git - etc/vim.git/blob - ale_linters/php/tlint.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 / php / tlint.vim
1 " Author: Jose Soto <jose@tighten.co>
2 "
3 " Description: Tighten Opinionated PHP Linting
4 " Website: https://github.com/tightenco/tlint
5
6 call ale#Set('php_tlint_executable', 'tlint')
7 call ale#Set('php_tlint_use_global', get(g:, 'ale_use_global_executables', 0))
8 call ale#Set('php_tlint_options', '')
9
10 function! ale_linters#php#tlint#GetProjectRoot(buffer) abort
11     let l:composer_path = ale#path#FindNearestFile(a:buffer, 'composer.json')
12
13     if !empty(l:composer_path)
14         return fnamemodify(l:composer_path, ':h')
15     endif
16
17     let l:git_path = ale#path#FindNearestDirectory(a:buffer, '.git')
18
19     return !empty(l:git_path) ? fnamemodify(l:git_path, ':h:h') : ''
20 endfunction
21
22 function! ale_linters#php#tlint#GetExecutable(buffer) abort
23     return ale#path#FindExecutable(a:buffer, 'php_tlint', [
24     \   'vendor/bin/tlint',
25     \   'tlint',
26     \])
27 endfunction
28
29 function! ale_linters#php#tlint#GetCommand(buffer) abort
30     let l:executable = ale_linters#php#tlint#GetExecutable(a:buffer)
31     let l:options = ale#Var(a:buffer, 'php_tlint_options')
32
33     return ale#node#Executable(a:buffer, l:executable)
34     \   . (!empty(l:options) ? ' ' . l:options : '')
35     \   . ' lint %s'
36 endfunction
37
38 function! ale_linters#php#tlint#Handle(buffer, lines) abort
39     " Matches against lines like the following:
40     "
41     " ! There should be 1 space around `.` concatenations, and additional lines should always start with a `.`
42     " 22 : `        $something = 'a'.'name';`
43     "
44     let l:loop_count = 0
45     let l:messages_pattern = '^\! \(.*\)'
46     let l:output = []
47     let l:pattern = '^\(\d\+\) \:'
48     let l:temp_messages = []
49
50     for l:message in ale#util#GetMatches(a:lines, l:messages_pattern)
51         call add(l:temp_messages, l:message)
52     endfor
53
54     let l:loop_count = 0
55
56     for l:match in ale#util#GetMatches(a:lines, l:pattern)
57         let l:num = l:match[1]
58         let l:text = l:temp_messages[l:loop_count]
59
60         call add(l:output, {
61         \   'lnum': l:num,
62         \   'col': 0,
63         \   'text': l:text,
64         \   'type': 'W',
65         \   'sub_type': 'style',
66         \})
67
68         let l:loop_count += 1
69     endfor
70
71     return l:output
72 endfunction
73
74 call ale#linter#Define('php', {
75 \   'name': 'tlint',
76 \   'executable': function('ale_linters#php#tlint#GetExecutable'),
77 \   'command': function('ale_linters#php#tlint#GetCommand'),
78 \   'callback': 'ale_linters#php#tlint#Handle',
79 \   'project_root': function('ale_linters#php#tlint#GetProjectRoot'),
80 \})