diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | ale_linters/less/stylelint.vim | 27 | ||||
-rw-r--r-- | doc/ale-less.txt | 27 | ||||
-rw-r--r-- | doc/ale.txt | 3 | ||||
-rwxr-xr-x | test/command_callback/stylelint_paths/node_modules/.bin/stylelint | 0 | ||||
-rw-r--r-- | test/command_callback/test_less_stylelint_command_callback.vader | 60 |
6 files changed, 117 insertions, 2 deletions
@@ -109,7 +109,7 @@ formatting. | JSON | [jsonlint](http://zaa.ch/jsonlint/), [prettier](https://github.com/prettier/prettier) | | Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !! see `:help ale-integration-kotlin` for configuration instructions | | LaTeX | [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | -| Less | [lessc](https://www.npmjs.com/package/less) | +| Less | [lessc](https://www.npmjs.com/package/less), [prettier](https://github.com/prettier/prettier), [stylelint](https://github.com/stylelint/stylelint) | | LLVM | [llc](https://llvm.org/docs/CommandGuide/llc.html) | | Lua | [luacheck](https://github.com/mpeterv/luacheck) | | Mail | [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) | diff --git a/ale_linters/less/stylelint.vim b/ale_linters/less/stylelint.vim new file mode 100644 index 00000000..690c8c93 --- /dev/null +++ b/ale_linters/less/stylelint.vim @@ -0,0 +1,27 @@ +" Author: diartyz <diartyz@gmail.com>, w0rp <devw0rp@gmail.com> + +call ale#Set('less_stylelint_executable', 'stylelint') +call ale#Set('less_stylelint_options', '') +call ale#Set('less_stylelint_use_global', 0) + +function! ale_linters#less#stylelint#GetExecutable(buffer) abort + return ale#node#FindExecutable(a:buffer, 'less_stylelint', [ + \ 'node_modules/.bin/stylelint', + \]) +endfunction + +function! ale_linters#less#stylelint#GetCommand(buffer) abort + let l:executable = ale_linters#less#stylelint#GetExecutable(a:buffer) + let l:options = ale#Var(a:buffer, 'less_stylelint_options') + + return ale#Escape(l:executable) + \ . (!empty(l:options) ? ' ' . l:options : '') + \ . ' --stdin-filename %s' +endfunction + +call ale#linter#Define('less', { +\ 'name': 'stylelint', +\ 'executable_callback': 'ale_linters#less#stylelint#GetExecutable', +\ 'command_callback': 'ale_linters#less#stylelint#GetCommand', +\ 'callback': 'ale#handlers#css#HandleStyleLintFormat', +\}) diff --git a/doc/ale-less.txt b/doc/ale-less.txt index a372afe0..05f56e2b 100644 --- a/doc/ale-less.txt +++ b/doc/ale-less.txt @@ -36,4 +36,31 @@ See |ale-javascript-prettier| for information about the available options. =============================================================================== +stylelint *ale-less-stylelint* + +g:ale_less_stylelint_executable *g:ale_less_stylelint_executable* + *b:ale_less_stylelint_executable* + Type: |String| + Default: `'stylelint'` + + See |ale-integrations-local-executables| + + +g:ale_less_stylelint_options *g:ale_less_stylelint_options* + *b:ale_less_stylelint_options* + Type: |String| + Default: `''` + + This variable can be set to pass additional options to stylelint. + + +g:ale_less_stylelint_use_global *g:ale_less_stylelint_use_global* + *b:ale_less_stylelint_use_global* + Type: |String| + 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 ff38cbbe..c83e39df 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -107,6 +107,7 @@ CONTENTS *ale-contents* less..................................|ale-less-options| lessc...............................|ale-less-lessc| prettier............................|ale-less-prettier| + stylelint...........................|ale-less-stylelint| llvm..................................|ale-llvm-options| llc.................................|ale-llvm-llc| lua...................................|ale-lua-options| @@ -298,7 +299,7 @@ Notes: * JSON: `jsonlint`, `prettier` * Kotlin: `kotlinc`, `ktlint` * LaTeX (tex): `chktex`, `lacheck`, `proselint`, `write-good` -* Less: `lessc` +* Less: `lessc`, `prettier`, `stylelint` * LLVM: `llc` * Lua: `luacheck` * Mail: `proselint`, `vale` diff --git a/test/command_callback/stylelint_paths/node_modules/.bin/stylelint b/test/command_callback/stylelint_paths/node_modules/.bin/stylelint new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/stylelint_paths/node_modules/.bin/stylelint diff --git a/test/command_callback/test_less_stylelint_command_callback.vader b/test/command_callback/test_less_stylelint_command_callback.vader new file mode 100644 index 00000000..d5aa3b97 --- /dev/null +++ b/test/command_callback/test_less_stylelint_command_callback.vader @@ -0,0 +1,60 @@ +Before: + Save g:ale_less_stylelint_executable + Save g:ale_less_stylelint_use_global + Save g:ale_less_stylelint_options + + unlet! b:executable + + unlet! g:ale_less_stylelint_executable + unlet! g:ale_less_stylelint_use_global + unlet! g:ale_less_stylelint_options + + call ale#test#SetDirectory('/testplugin/test/command_callback') + call ale#test#SetFilename('testfile.less') + + runtime ale_linters/less/stylelint.vim + +After: + Restore + + unlet! b:executable + unlet! b:ale_less_stylelint_executable + unlet! b:ale_less_stylelint_use_global + unlet! b:ale_less_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.less') + + let b:executable = ale#path#Winify( + \ g:dir + \ . '/stylelint_paths/node_modules/.bin/stylelint' + \) + + AssertEqual b:executable, ale_linters#less#stylelint#GetExecutable(bufnr('')) + AssertEqual + \ ale#Escape(b:executable) . ' --stdin-filename %s', + \ ale_linters#less#stylelint#GetCommand(bufnr('')) + +Execute(The global override should work): + let b:ale_less_stylelint_executable = 'foobar' + let b:ale_less_stylelint_use_global = 1 + + call ale#test#SetFilename('stylelint_paths/nested/testfile.less') + + AssertEqual 'foobar', ale_linters#less#stylelint#GetExecutable(bufnr('')) + AssertEqual + \ ale#Escape('foobar') . ' --stdin-filename %s', + \ ale_linters#less#stylelint#GetCommand(bufnr('')) + +Execute(Extra options should be configurable): + let b:ale_less_stylelint_options = '--whatever' + + AssertEqual 'stylelint', ale_linters#less#stylelint#GetExecutable(bufnr('')) + AssertEqual + \ ale#Escape('stylelint') . ' --whatever --stdin-filename %s', + \ ale_linters#less#stylelint#GetCommand(bufnr('')) |