-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make pug-lint detect node_modules executables, and add options for pu…
…g-lint like the other linters
- Loading branch information
Showing
9 changed files
with
158 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
\}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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('')) |