From 79e8e063af1cf7a72ec42075f4eed30aa69607e8 Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 29 Jun 2017 11:40:03 +0100 Subject: Make pug-lint detect node_modules executables, and add options for pug-lint like the other linters --- ale_linters/pug/puglint.vim | 42 ++++++++++++- doc/ale-pug.txt | 44 +++++++++++++ doc/ale.txt | 2 + .../puglint_project/node_modules/.bin/pug-lint | 0 test/command_callback/puglint_project/package.json | 0 .../puglint_project/puglint_rc_dir/.pug-lintrc | 0 .../puglint_rc_js_dir/.pug-lintrc.js | 0 .../puglint_rc_json_dir/.pug-lintrc.json | 0 .../test_puglint_command_callback.vader | 72 ++++++++++++++++++++++ 9 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 doc/ale-pug.txt create mode 100644 test/command_callback/puglint_project/node_modules/.bin/pug-lint create mode 100644 test/command_callback/puglint_project/package.json create mode 100644 test/command_callback/puglint_project/puglint_rc_dir/.pug-lintrc create mode 100644 test/command_callback/puglint_project/puglint_rc_js_dir/.pug-lintrc.js create mode 100644 test/command_callback/puglint_project/puglint_rc_json_dir/.pug-lintrc.json create mode 100644 test/command_callback/test_puglint_command_callback.vader 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 - " 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', \}) diff --git a/doc/ale-pug.txt b/doc/ale-pug.txt new file mode 100644 index 00000000..ad984dc8 --- /dev/null +++ b/doc/ale-pug.txt @@ -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: diff --git a/doc/ale.txt b/doc/ale.txt index f9532fc4..d9c989be 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -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| diff --git a/test/command_callback/puglint_project/node_modules/.bin/pug-lint b/test/command_callback/puglint_project/node_modules/.bin/pug-lint new file mode 100644 index 00000000..e69de29b diff --git a/test/command_callback/puglint_project/package.json b/test/command_callback/puglint_project/package.json new file mode 100644 index 00000000..e69de29b diff --git a/test/command_callback/puglint_project/puglint_rc_dir/.pug-lintrc b/test/command_callback/puglint_project/puglint_rc_dir/.pug-lintrc new file mode 100644 index 00000000..e69de29b diff --git a/test/command_callback/puglint_project/puglint_rc_js_dir/.pug-lintrc.js b/test/command_callback/puglint_project/puglint_rc_js_dir/.pug-lintrc.js new file mode 100644 index 00000000..e69de29b diff --git a/test/command_callback/puglint_project/puglint_rc_json_dir/.pug-lintrc.json b/test/command_callback/puglint_project/puglint_rc_json_dir/.pug-lintrc.json new file mode 100644 index 00000000..e69de29b diff --git a/test/command_callback/test_puglint_command_callback.vader b/test/command_callback/test_puglint_command_callback.vader new file mode 100644 index 00000000..830d63b3 --- /dev/null +++ b/test/command_callback/test_puglint_command_callback.vader @@ -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('')) -- cgit v1.2.3