summaryrefslogtreecommitdiff
path: root/ale_linters/pug
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-06-29 11:40:03 +0100
committerw0rp <devw0rp@gmail.com>2017-06-29 11:40:03 +0100
commit79e8e063af1cf7a72ec42075f4eed30aa69607e8 (patch)
treeeda18cb73dc90c5cd540cc8db63e14420f854b0c /ale_linters/pug
parent01ecf2a75f60fff8884ad7858da44b3c5f71bc11 (diff)
downloadale-79e8e063af1cf7a72ec42075f4eed30aa69607e8.zip
Make pug-lint detect node_modules executables, and add options for pug-lint like the other linters
Diffstat (limited to 'ale_linters/pug')
-rw-r--r--ale_linters/pug/puglint.vim42
1 files changed, 40 insertions, 2 deletions
diff --git a/ale_linters/pug/puglint.vim b/ale_linters/pug/puglint.vim
index 3f817c31..6c29efe9 100644
--- a/ale_linters/pug/puglint.vim
+++ b/ale_linters/pug/puglint.vim
@@ -1,10 +1,48 @@
" Author: w0rp - <devw0rp@gmail.com>
" Description: pug-lint for checking Pug/Jade files.
+call ale#Set('pug_puglint_options', '')
+call ale#Set('pug_puglint_executable', 'pug-lint')
+call ale#Set('pug_puglint_use_global', 0)
+
+function! ale_linters#pug#puglint#GetExecutable(buffer) abort
+ return ale#node#FindExecutable(a:buffer, 'pug_puglint', [
+ \ 'node_modules/.bin/pug-lint',
+ \])
+endfunction
+
+function! s:FindConfig(buffer) abort
+ for l:filename in [
+ \ '.pug-lintrc',
+ \ '.pug-lintrc.js',
+ \ '.pug-lintrc.json',
+ \ 'package.json',
+ \]
+ let l:config = ale#path#FindNearestFile(a:buffer, l:filename)
+
+ if !empty(l:config)
+ return l:config
+ endif
+ endfor
+
+ return ''
+endfunction
+
+function! ale_linters#pug#puglint#GetCommand(buffer) abort
+ let l:executable = ale_linters#pug#puglint#GetExecutable(a:buffer)
+ let l:options = ale#Var(a:buffer, 'pug_puglint_options')
+ let l:config = s:FindConfig(a:buffer)
+
+ return ale#Escape(l:executable)
+ \ . (!empty(l:options) ? ' ' . l:options : '')
+ \ . (!empty(l:config) ? ' -c ' . ale#Escape(l:config) : '')
+ \ . ' -r inline %t'
+endfunction
+
call ale#linter#Define('pug', {
\ 'name': 'puglint',
-\ 'executable': 'pug-lint',
+\ 'executable_callback': 'ale_linters#pug#puglint#GetExecutable',
\ 'output_stream': 'stderr',
-\ 'command': 'pug-lint -r inline %t',
+\ 'command_callback': 'ale_linters#pug#puglint#GetCommand',
\ 'callback': 'ale#handlers#unix#HandleAsError',
\})