]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/haml/hamllint.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:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / ale_linters / haml / hamllint.vim
1 " Author: Patrick Lewis - https://github.com/patricklewis, thenoseman - https://github.com/thenoseman
2 " Description: haml-lint for Haml files
3
4 call ale#Set('haml_hamllint_executable', 'haml-lint')
5
6 function! ale_linters#haml#hamllint#GetExecutable(buffer) abort
7     return ale#Var(a:buffer, 'haml_hamllint_executable')
8 endfunction
9
10 function! ale_linters#haml#hamllint#GetCommand(buffer) abort
11     let l:prefix = ''
12
13     let l:rubocop_config_file_path = ale#path#FindNearestFile(a:buffer, '.rubocop.yml')
14     let l:hamllint_config_file_path = ale#path#FindNearestFile(a:buffer, '.haml-lint.yml')
15
16     " Set HAML_LINT_RUBOCOP_CONF variable as it is needed for haml-lint to
17     " pick up the rubocop config.
18     "
19     " See https://github.com/brigade/haml-lint/blob/master/lib/haml_lint/linter/rubocop.rb#L89
20     "     HamlLint::Linter::RuboCop#rubocop_flags
21     if !empty(l:rubocop_config_file_path)
22         if has('win32')
23             let l:prefix = 'set HAML_LINT_RUBOCOP_CONF=' . ale#Escape(l:rubocop_config_file_path) . ' &&'
24         else
25             let l:prefix = 'HAML_LINT_RUBOCOP_CONF=' . ale#Escape(l:rubocop_config_file_path)
26         endif
27     endif
28
29     return (!empty(l:prefix) ? l:prefix . ' ' : '')
30     \   . ale_linters#haml#hamllint#GetExecutable(a:buffer)
31     \   . (!empty(l:hamllint_config_file_path) ? ' --config ' . ale#Escape(l:hamllint_config_file_path) : '')
32     \   . ' %t'
33 endfunction
34
35 function! ale_linters#haml#hamllint#Handle(buffer, lines) abort
36     " Matches patterns like the following:
37     " <path>:51 [W] RuboCop: Use the new Ruby 1.9 hash syntax.
38     let l:pattern = '\v^.*:(\d+) \[([EW])\] (.+)$'
39     let l:output = []
40
41     for l:match in ale#util#GetMatches(a:lines, l:pattern)
42         call add(l:output, {
43         \   'lnum': l:match[1] + 0,
44         \   'type': l:match[2],
45         \   'text': l:match[3]
46         \})
47     endfor
48
49     return l:output
50 endfunction
51
52 call ale#linter#Define('haml', {
53 \   'name': 'hamllint',
54 \   'executable': function('ale_linters#haml#hamllint#GetExecutable'),
55 \   'command': function('ale_linters#haml#hamllint#GetCommand'),
56 \   'callback': 'ale_linters#haml#hamllint#Handle'
57 \})