]> git.madduck.net Git - etc/vim.git/blobdiff - .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:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / haml / hamllint.vim
diff --git a/.vim/bundle/ale/ale_linters/haml/hamllint.vim b/.vim/bundle/ale/ale_linters/haml/hamllint.vim
new file mode 100644 (file)
index 0000000..9fcd999
--- /dev/null
@@ -0,0 +1,57 @@
+" Author: Patrick Lewis - https://github.com/patricklewis, thenoseman - https://github.com/thenoseman
+" Description: haml-lint for Haml files
+
+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
+
+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 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 . ' ' : '')
+    \   . ale_linters#haml#hamllint#GetExecutable(a:buffer)
+    \   . (!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.
+    let l:pattern = '\v^.*:(\d+) \[([EW])\] (.+)$'
+    let l:output = []
+
+    for l:match in ale#util#GetMatches(a:lines, l:pattern)
+        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',
+\   'executable': function('ale_linters#haml#hamllint#GetExecutable'),
+\   'command': function('ale_linters#haml#hamllint#GetCommand'),
+\   'callback': 'ale_linters#haml#hamllint#Handle'
+\})