2017-10-25 18:46:16 +00:00
|
|
|
" Author: Patrick Lewis - https://github.com/patricklewis, thenoseman - https://github.com/thenoseman
|
2017-03-03 20:27:07 +00:00
|
|
|
" Description: haml-lint for Haml files
|
|
|
|
|
2018-11-04 10:35:21 +00:00
|
|
|
call ale#Set('haml_hamllint_executable', 'haml-lint')
|
|
|
|
|
|
|
|
function! ale_linters#haml#hamllint#GetExecutable(buffer) abort
|
|
|
|
return ale#Var(a:buffer, 'haml_hamllint_executable')
|
|
|
|
endfunction
|
|
|
|
|
2017-10-25 18:46:16 +00:00
|
|
|
function! ale_linters#haml#hamllint#GetCommand(buffer) abort
|
|
|
|
let l:prefix = ''
|
|
|
|
|
|
|
|
let l:rubocop_config_file_path = ale#path#FindNearestFile(a:buffer, '.rubocop.yml')
|
|
|
|
let l:hamllint_config_file_path = ale#path#FindNearestFile(a:buffer, '.haml-lint.yml')
|
|
|
|
|
|
|
|
" Set HAML_LINT_RUBOCOP_CONF variable as it is needed for haml-lint to
|
|
|
|
" pick up the rubocop config.
|
|
|
|
"
|
|
|
|
" See https://github.com/brigade/haml-lint/blob/master/lib/haml_lint/linter/rubocop.rb#L89
|
|
|
|
" HamlLint::Linter::RuboCop#rubocop_flags
|
|
|
|
if !empty(l:rubocop_config_file_path)
|
2017-10-25 22:07:38 +00:00
|
|
|
if ale#Has('win32')
|
|
|
|
let l:prefix = 'set HAML_LINT_RUBOCOP_CONF=' . ale#Escape(l:rubocop_config_file_path) . ' &&'
|
|
|
|
else
|
|
|
|
let l:prefix = 'HAML_LINT_RUBOCOP_CONF=' . ale#Escape(l:rubocop_config_file_path)
|
|
|
|
endif
|
2017-10-25 18:46:16 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
return (!empty(l:prefix) ? l:prefix . ' ' : '')
|
2018-11-04 10:35:21 +00:00
|
|
|
\ . ale_linters#haml#hamllint#GetExecutable(a:buffer)
|
2017-10-25 22:07:38 +00:00
|
|
|
\ . (!empty(l:hamllint_config_file_path) ? ' --config ' . ale#Escape(l:hamllint_config_file_path) : '')
|
|
|
|
\ . ' %t'
|
2017-10-25 18:46:16 +00:00
|
|
|
endfunction
|
|
|
|
|
2017-03-03 20:27:07 +00:00
|
|
|
function! ale_linters#haml#hamllint#Handle(buffer, lines) abort
|
|
|
|
" Matches patterns like the following:
|
|
|
|
" <path>:51 [W] RuboCop: Use the new Ruby 1.9 hash syntax.
|
|
|
|
let l:pattern = '\v^.*:(\d+) \[([EW])\] (.+)$'
|
|
|
|
let l:output = []
|
|
|
|
|
2017-04-17 23:35:53 +00:00
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2017-03-03 20:27:07 +00:00
|
|
|
call add(l:output, {
|
|
|
|
\ 'lnum': l:match[1] + 0,
|
|
|
|
\ 'type': l:match[2],
|
|
|
|
\ 'text': l:match[3]
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('haml', {
|
|
|
|
\ 'name': 'hamllint',
|
2018-11-04 10:35:21 +00:00
|
|
|
\ 'executable_callback': 'ale_linters#haml#hamllint#GetExecutable',
|
2017-10-25 18:46:16 +00:00
|
|
|
\ 'command_callback': 'ale_linters#haml#hamllint#GetCommand',
|
2017-03-03 20:27:07 +00:00
|
|
|
\ 'callback': 'ale_linters#haml#hamllint#Handle'
|
|
|
|
\})
|