]> git.madduck.net Git - etc/vim.git/blobdiff - .vim/bundle/ale/ale_linters/slim/slimlint.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 / slim / slimlint.vim
diff --git a/.vim/bundle/ale/ale_linters/slim/slimlint.vim b/.vim/bundle/ale/ale_linters/slim/slimlint.vim
new file mode 100644 (file)
index 0000000..1b365e2
--- /dev/null
@@ -0,0 +1,55 @@
+" Author: Markus Doits - https://github.com/doits
+" Description: slim-lint for Slim files
+
+function! ale_linters#slim#slimlint#GetCommand(buffer) abort
+    let l:command = 'slim-lint %t'
+
+    let l:rubocop_config = ale#path#FindNearestFile(a:buffer, '.rubocop.yml')
+
+    " Set SLIM_LINT_RUBOCOP_CONF variable as it is needed for slim-lint to
+    " pick up the rubocop config.
+    "
+    " See https://github.com/sds/slim-lint/blob/master/lib/slim_lint/linter/README.md#rubocop
+    if !empty(l:rubocop_config)
+        if has('win32')
+            let l:command = 'set SLIM_LINT_RUBOCOP_CONF=' . ale#Escape(l:rubocop_config) . ' && ' . l:command
+        else
+            let l:command = 'SLIM_LINT_RUBOCOP_CONF=' . ale#Escape(l:rubocop_config) . ' ' . l:command
+        endif
+    endif
+
+    return l:command
+endfunction
+
+function! ale_linters#slim#slimlint#Handle(buffer, lines) abort
+    " Matches patterns like the following:
+    " <path>:5 [W] LineLength: Line is too long. [150/120]
+    let l:pattern = '\v^.*:(\d+) \[([EW])\] (.+)$'
+    let l:output = []
+
+    for l:match in ale#util#GetMatches(a:lines, l:pattern)
+        let l:item = {
+        \   'lnum': l:match[1] + 0,
+        \   'type': l:match[2],
+        \   'text': l:match[3]
+        \}
+
+        let l:code_match = matchlist(l:item.text, '\v^([^:]+): (.+)$')
+
+        if !empty(l:code_match)
+            let l:item.code = l:code_match[1]
+            let l:item.text = l:code_match[2]
+        endif
+
+        call add(l:output, l:item)
+    endfor
+
+    return l:output
+endfunction
+
+call ale#linter#Define('slim', {
+\   'name': 'slimlint',
+\   'executable': 'slim-lint',
+\   'command': function('ale_linters#slim#slimlint#GetCommand'),
+\   'callback': 'ale_linters#slim#slimlint#Handle'
+\})