Make pug-lint detect node_modules executables, and add options for pug-lint like the other linters
This commit is contained in:
parent
01ecf2a75f
commit
79e8e063af
@ -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',
|
||||
\})
|
||||
|
44
doc/ale-pug.txt
Normal file
44
doc/ale-pug.txt
Normal file
@ -0,0 +1,44 @@
|
||||
===============================================================================
|
||||
ALE Pug Integration *ale-pug-options*
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
puglint *ale-pug-puglint*
|
||||
|
||||
The puglint linter will detect configuration files based on the path to the
|
||||
filename automatically. Configuration files will be loaded in this order:
|
||||
|
||||
1. `.pug-lintrc`
|
||||
2. `.pug-lintrc.js`
|
||||
3. `.pug-lintrc.json`
|
||||
4. `package.json`
|
||||
|
||||
You might need to create a configuration file for your project to get
|
||||
meaningful results.
|
||||
|
||||
g:ale_pug_puglint_executable *g:ale_pug_puglint_executable*
|
||||
*b:ale_pug_puglint_executable*
|
||||
Type: |String|
|
||||
Default: `'pug-lint'`
|
||||
|
||||
See |ale-integrations-local-executables|
|
||||
|
||||
|
||||
g:ale_pug_puglint_options *g:ale_pug_puglint_options*
|
||||
*b:ale_pug_puglint_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
This variable can be set to pass additional options to pug-lint.
|
||||
|
||||
|
||||
g:ale_pug_puglint_use_global *g:ale_pug_puglint_use_global*
|
||||
*b:ale_pug_puglint_use_global*
|
||||
Type: |Number|
|
||||
Default: `0`
|
||||
|
||||
See |ale-integrations-local-executables|
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
@ -72,6 +72,8 @@ CONTENTS *ale-contents*
|
||||
php...................................|ale-php-options|
|
||||
phpcs...............................|ale-php-phpcs|
|
||||
phpmd...............................|ale-php-phpmd|
|
||||
pug...................................|ale-pug-options|
|
||||
puglint.............................|ale-pug-puglint|
|
||||
python................................|ale-python-options|
|
||||
autopep8............................|ale-python-autopep8|
|
||||
flake8..............................|ale-python-flake8|
|
||||
|
0
test/command_callback/puglint_project/node_modules/.bin/pug-lint
generated
vendored
Normal file
0
test/command_callback/puglint_project/node_modules/.bin/pug-lint
generated
vendored
Normal file
0
test/command_callback/puglint_project/package.json
Normal file
0
test/command_callback/puglint_project/package.json
Normal file
72
test/command_callback/test_puglint_command_callback.vader
Normal file
72
test/command_callback/test_puglint_command_callback.vader
Normal file
@ -0,0 +1,72 @@
|
||||
Before:
|
||||
Save g:ale_pug_puglint_options
|
||||
Save g:ale_pug_puglint_executable
|
||||
Save g:ale_pug_puglint_use_global
|
||||
|
||||
let g:ale_pug_puglint_options = ''
|
||||
let g:ale_pug_puglint_executable = 'pug-lint'
|
||||
let g:ale_pug_puglint_use_global = 0
|
||||
|
||||
silent! cd /testplugin/test/command_callback
|
||||
let g:dir = getcwd()
|
||||
|
||||
runtime ale_linters/pug/puglint.vim
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
silent execute 'cd ' . fnameescape(g:dir)
|
||||
unlet! g:dir
|
||||
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(puglint should detect local executables and package.json):
|
||||
call ale#test#SetFilename('puglint_project/test.pug')
|
||||
|
||||
AssertEqual
|
||||
\ g:dir . '/puglint_project/node_modules/.bin/pug-lint',
|
||||
\ ale_linters#pug#puglint#GetExecutable(bufnr(''))
|
||||
AssertEqual
|
||||
\ ale#Escape(g:dir . '/puglint_project/node_modules/.bin/pug-lint')
|
||||
\ . ' -c ' . ale#Escape(g:dir . '/puglint_project/package.json')
|
||||
\ . ' -r inline %t',
|
||||
\ ale_linters#pug#puglint#GetCommand(bufnr(''))
|
||||
|
||||
Execute(puglint should use global executables if configured):
|
||||
let g:ale_pug_puglint_use_global = 1
|
||||
|
||||
call ale#test#SetFilename('puglint_project/test.pug')
|
||||
|
||||
AssertEqual 'pug-lint', ale_linters#pug#puglint#GetExecutable(bufnr(''))
|
||||
AssertEqual
|
||||
\ ale#Escape('pug-lint')
|
||||
\ . ' -c ' . ale#Escape(g:dir . '/puglint_project/package.json')
|
||||
\ . ' -r inline %t',
|
||||
\ ale_linters#pug#puglint#GetCommand(bufnr(''))
|
||||
|
||||
Execute(puglint should detect .pug-lintrc):
|
||||
call ale#test#SetFilename('puglint_project/puglint_rc_dir/subdir/test.pug')
|
||||
|
||||
AssertEqual
|
||||
\ ale#Escape(g:dir . '/puglint_project/node_modules/.bin/pug-lint')
|
||||
\ . ' -c ' . ale#Escape(g:dir . '/puglint_project/puglint_rc_dir/.pug-lintrc')
|
||||
\ . ' -r inline %t',
|
||||
\ ale_linters#pug#puglint#GetCommand(bufnr(''))
|
||||
|
||||
Execute(puglint should detect .pug-lintrc.js):
|
||||
call ale#test#SetFilename('puglint_project/puglint_rc_js_dir/subdir/test.pug')
|
||||
|
||||
AssertEqual
|
||||
\ ale#Escape(g:dir . '/puglint_project/node_modules/.bin/pug-lint')
|
||||
\ . ' -c ' . ale#Escape(g:dir . '/puglint_project/puglint_rc_js_dir/.pug-lintrc.js')
|
||||
\ . ' -r inline %t',
|
||||
\ ale_linters#pug#puglint#GetCommand(bufnr(''))
|
||||
|
||||
Execute(puglint should detect .pug-lintrc.json):
|
||||
call ale#test#SetFilename('puglint_project/puglint_rc_json_dir/subdir/test.pug')
|
||||
|
||||
AssertEqual
|
||||
\ ale#Escape(g:dir . '/puglint_project/node_modules/.bin/pug-lint')
|
||||
\ . ' -c ' . ale#Escape(g:dir . '/puglint_project/puglint_rc_json_dir/.pug-lintrc.json')
|
||||
\ . ' -r inline %t',
|
||||
\ ale_linters#pug#puglint#GetCommand(bufnr(''))
|
Loading…
Reference in New Issue
Block a user