2018-03-31 10:55:20 -04:00
|
|
|
" 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')
|
2018-06-14 06:31:12 -04:00
|
|
|
call ale#Set('pug_puglint_use_global', get(g:, 'ale_use_global_executables', 0))
|
2018-03-31 10:55:20 -04:00
|
|
|
|
|
|
|
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:options = ale#Var(a:buffer, 'pug_puglint_options')
|
|
|
|
let l:config = s:FindConfig(a:buffer)
|
|
|
|
|
2018-08-25 12:13:42 -04:00
|
|
|
return '%e' . ale#Pad(l:options)
|
2018-03-31 10:55:20 -04:00
|
|
|
\ . (!empty(l:config) ? ' -c ' . ale#Escape(l:config) : '')
|
|
|
|
\ . ' -r inline %t'
|
|
|
|
endfunction
|
|
|
|
|
2019-05-16 15:48:47 -04:00
|
|
|
function! ale_linters#pug#puglint#Handle(buffer, lines) abort
|
|
|
|
for l:line in a:lines[:10]
|
|
|
|
if l:line =~# '^SyntaxError: '
|
|
|
|
return [{
|
|
|
|
\ 'lnum': 1,
|
|
|
|
\ 'text': 'puglint configuration error (type :ALEDetail for more information)',
|
|
|
|
\ 'detail': join(a:lines, "\n"),
|
|
|
|
\}]
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return ale#handlers#unix#HandleAsError(a:buffer, a:lines)
|
|
|
|
endfunction
|
|
|
|
|
2018-03-31 10:55:20 -04:00
|
|
|
call ale#linter#Define('pug', {
|
|
|
|
\ 'name': 'puglint',
|
2021-06-30 12:54:34 -04:00
|
|
|
\ 'executable': {b -> ale#path#FindExecutable(b, 'pug_puglint', [
|
2018-08-25 12:13:42 -04:00
|
|
|
\ 'node_modules/.bin/pug-lint',
|
2019-03-08 06:04:56 -05:00
|
|
|
\ ])},
|
2018-03-31 10:55:20 -04:00
|
|
|
\ 'output_stream': 'stderr',
|
2019-03-08 06:04:56 -05:00
|
|
|
\ 'command': function('ale_linters#pug#puglint#GetCommand'),
|
2019-05-16 15:48:47 -04:00
|
|
|
\ 'callback': 'ale_linters#pug#puglint#Handle',
|
2018-03-31 10:55:20 -04:00
|
|
|
\})
|