summaryrefslogtreecommitdiff
path: root/ale_linters/haml
diff options
context:
space:
mode:
authorFrank Schumacher <frank.schumacher.privat@googlemail.com>2017-10-25 20:46:16 +0200
committerFrank Schumacher <frank.schumacher.privat@googlemail.com>2017-10-25 20:46:16 +0200
commit45ed37a5d91c99c9a43093aba2ae738d4524ccdf (patch)
treebcbded5ffae0ec4350fa78ce277f92839c2a078c /ale_linters/haml
parent960ae62aaa30d26fcfff57d6593e54a34a93ec68 (diff)
downloadale-45ed37a5d91c99c9a43093aba2ae738d4524ccdf.zip
auto-detect .rubocop.yml and .haml-lint.yml
Based on path to current file
Diffstat (limited to 'ale_linters/haml')
-rw-r--r--ale_linters/haml/hamllint.vim29
1 files changed, 27 insertions, 2 deletions
diff --git a/ale_linters/haml/hamllint.vim b/ale_linters/haml/hamllint.vim
index b1a6aa57..e56da090 100644
--- a/ale_linters/haml/hamllint.vim
+++ b/ale_linters/haml/hamllint.vim
@@ -1,6 +1,31 @@
-" Author: Patrick Lewis - https://github.com/patricklewis
+" Author: Patrick Lewis - https://github.com/patricklewis, thenoseman - https://github.com/thenoseman
" Description: haml-lint for Haml files
+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)
+ 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
+ endif
+
+ return (!empty(l:prefix) ? l:prefix . ' ' : '')
+ \ . 'haml-lint'
+ \ . (!empty(l:hamllint_config_file_path) ? ' --config ' . ale#Escape(l:hamllint_config_file_path) : '')
+ \ . ' %t'
+endfunction
+
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.
@@ -21,6 +46,6 @@ endfunction
call ale#linter#Define('haml', {
\ 'name': 'hamllint',
\ 'executable': 'haml-lint',
-\ 'command': 'haml-lint %t',
+\ 'command_callback': 'ale_linters#haml#hamllint#GetCommand',
\ 'callback': 'ale_linters#haml#hamllint#Handle'
\})