From 4cd20b821fd10a3b047d1ec9ff5647ce334381bf Mon Sep 17 00:00:00 2001 From: Filipe Kiss Date: Wed, 22 Aug 2018 17:52:14 -0300 Subject: [PATCH 1/4] Add html stylelint linter --- ale_linters/html/stylelint.vim | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ale_linters/html/stylelint.vim diff --git a/ale_linters/html/stylelint.vim b/ale_linters/html/stylelint.vim new file mode 100644 index 00000000..908c4b02 --- /dev/null +++ b/ale_linters/html/stylelint.vim @@ -0,0 +1,27 @@ +" Author: Filipe Kiss http://github.com/filipekiss + +call ale#Set('html_stylelint_executable', 'stylelint') +call ale#Set('html_stylelint_options', '') +call ale#Set('html_stylelint_use_global', 0) + +function! ale_linters#html#stylelint#GetExecutable(buffer) abort + return ale#node#FindExecutable(a:buffer, 'html_stylelint', [ + \ 'node_modules/.bin/stylelint', + \]) +endfunction + +function! ale_linters#html#stylelint#GetCommand(buffer) abort + let l:executable = ale_linters#html#stylelint#GetExecutable(a:buffer) + let l:options = ale#Var(a:buffer, 'html_stylelint_options') + + return ale#Escape(l:executable) + \ . (!empty(l:options) ? ' ' . l:options : '') + \ . ' --stdin-filename %s' +endfunction + +call ale#linter#Define('html', { +\ 'name': 'stylelint', +\ 'executable_callback': 'ale_linters#html#stylelint#GetExecutable', +\ 'command_callback': 'ale_linters#html#stylelint#GetCommand', +\ 'callback': 'ale#handlers#css#HandleStyleLintFormat', +\}) From b78ee188987f9a28a6ef0df08271f43133eeb238 Mon Sep 17 00:00:00 2001 From: Filipe Kiss Date: Wed, 22 Aug 2018 18:37:39 -0300 Subject: [PATCH 2/4] :umbrella: Add html stylelint test --- ...test_html_stylelint_command_callback.vader | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 test/command_callback/test_html_stylelint_command_callback.vader diff --git a/test/command_callback/test_html_stylelint_command_callback.vader b/test/command_callback/test_html_stylelint_command_callback.vader new file mode 100644 index 00000000..49d7d143 --- /dev/null +++ b/test/command_callback/test_html_stylelint_command_callback.vader @@ -0,0 +1,60 @@ +Before: + Save g:ale_html_stylelint_executable + Save g:ale_html_stylelint_use_global + Save g:ale_html_stylelint_options + + unlet! b:executable + + unlet! g:ale_html_stylelint_executable + unlet! g:ale_html_stylelint_use_global + unlet! g:ale_html_stylelint_options + + call ale#test#SetDirectory('/testplugin/test/command_callback') + call ale#test#SetFilename('testfile.html') + + runtime ale_linters/html/stylelint.vim + +After: + Restore + + unlet! b:executable + unlet! b:ale_html_stylelint_executable + unlet! b:ale_html_stylelint_use_global + unlet! b:ale_html_stylelint_options + + call ale#test#SetFilename('test.txt') + + call ale#test#RestoreDirectory() + call ale#linter#Reset() + +Execute(node_modules directories should be discovered): + call ale#test#SetFilename('stylelint_paths/nested/testfile.html') + + let b:executable = ale#path#Simplify( + \ g:dir + \ . '/stylelint_paths/node_modules/.bin/stylelint' + \) + + AssertEqual b:executable, ale_linters#html#stylelint#GetExecutable(bufnr('')) + AssertEqual + \ ale#Escape(b:executable) . ' --stdin-filename %s', + \ ale_linters#html#stylelint#GetCommand(bufnr('')) + +Execute(The global override should work): + let b:ale_html_stylelint_executable = 'foobar' + let b:ale_html_stylelint_use_global = 1 + + call ale#test#SetFilename('stylelint_paths/nested/testfile.html') + + AssertEqual 'foobar', ale_linters#html#stylelint#GetExecutable(bufnr('')) + AssertEqual + \ ale#Escape('foobar') . ' --stdin-filename %s', + \ ale_linters#html#stylelint#GetCommand(bufnr('')) + +Execute(Extra options should be configurable): + let b:ale_html_stylelint_options = '--whatever' + + AssertEqual 'stylelint', ale_linters#html#stylelint#GetExecutable(bufnr('')) + AssertEqual + \ ale#Escape('stylelint') . ' --whatever --stdin-filename %s', + \ ale_linters#html#stylelint#GetCommand(bufnr('')) From 935a132d8ff1f1b90732b1d62462cfda56bc98c0 Mon Sep 17 00:00:00 2001 From: Filipe Kiss Date: Wed, 22 Aug 2018 18:38:07 -0300 Subject: [PATCH 3/4] :books: Add docs for html stylelint --- doc/ale-html.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/doc/ale-html.txt b/doc/ale-html.txt index c5d5afa5..561808cd 100644 --- a/doc/ale-html.txt +++ b/doc/ale-html.txt @@ -76,6 +76,31 @@ write-good *ale-html-write-good* See |ale-write-good-options| +=============================================================================== +stylelint *ale-html-stylelint* + +g:ale_html_stylelint_executable *g:ale_html_stylelint_executable* + *b:ale_html_stylelint_executable* + Type: |String| + Default: `'stylelint'` + + See |ale-integrations-local-executables| + + +g:ale_html_stylelint_options *g:ale_html_stylelint_options* + *b:ale_html_stylelint_options* + Type: |String| + Default: `''` + + This variable can be set to pass additional options to stylelint. + + +g:ale_html_stylelint_use_global *g:ale_html_stylelint_use_global* + *b:ale_html_stylelint_use_global* + Type: |String| + Default: `0` + + See |ale-integrations-local-executables| =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: From c253fb72e3645f80d0a49b9a5194f3ecc7d6ced1 Mon Sep 17 00:00:00 2001 From: Filipe Kiss Date: Thu, 23 Aug 2018 17:23:04 -0300 Subject: [PATCH 4/4] :books: Add html stylelint to TOC --- doc/ale.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/ale.txt b/doc/ale.txt index e0002f77..c14bdd3d 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -94,6 +94,7 @@ CONTENTS *ale-contents* htmlhint............................|ale-html-htmlhint| tidy................................|ale-html-tidy| write-good..........................|ale-html-write-good| + stylelint...........................|ale-html-stylelint| idris.................................|ale-idris-options| idris...............................|ale-idris-idris| java..................................|ale-java-options|