Fix #510 Support checking LESS files with stylelint
This commit is contained in:
parent
5b3094558b
commit
3c34848e02
@ -109,7 +109,7 @@ formatting.
|
|||||||
| JSON | [jsonlint](http://zaa.ch/jsonlint/), [prettier](https://github.com/prettier/prettier) |
|
| 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 |
|
| 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) |
|
| 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) |
|
| LLVM | [llc](https://llvm.org/docs/CommandGuide/llc.html) |
|
||||||
| Lua | [luacheck](https://github.com/mpeterv/luacheck) |
|
| Lua | [luacheck](https://github.com/mpeterv/luacheck) |
|
||||||
| Mail | [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) |
|
| Mail | [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) |
|
||||||
|
27
ale_linters/less/stylelint.vim
Normal file
27
ale_linters/less/stylelint.vim
Normal file
@ -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',
|
||||||
|
\})
|
@ -35,5 +35,32 @@ prettier *ale-less-prettier*
|
|||||||
See |ale-javascript-prettier| for information about the available options.
|
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:
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||||
|
@ -107,6 +107,7 @@ CONTENTS *ale-contents*
|
|||||||
less..................................|ale-less-options|
|
less..................................|ale-less-options|
|
||||||
lessc...............................|ale-less-lessc|
|
lessc...............................|ale-less-lessc|
|
||||||
prettier............................|ale-less-prettier|
|
prettier............................|ale-less-prettier|
|
||||||
|
stylelint...........................|ale-less-stylelint|
|
||||||
llvm..................................|ale-llvm-options|
|
llvm..................................|ale-llvm-options|
|
||||||
llc.................................|ale-llvm-llc|
|
llc.................................|ale-llvm-llc|
|
||||||
lua...................................|ale-lua-options|
|
lua...................................|ale-lua-options|
|
||||||
@ -298,7 +299,7 @@ Notes:
|
|||||||
* JSON: `jsonlint`, `prettier`
|
* JSON: `jsonlint`, `prettier`
|
||||||
* Kotlin: `kotlinc`, `ktlint`
|
* Kotlin: `kotlinc`, `ktlint`
|
||||||
* LaTeX (tex): `chktex`, `lacheck`, `proselint`, `write-good`
|
* LaTeX (tex): `chktex`, `lacheck`, `proselint`, `write-good`
|
||||||
* Less: `lessc`
|
* Less: `lessc`, `prettier`, `stylelint`
|
||||||
* LLVM: `llc`
|
* LLVM: `llc`
|
||||||
* Lua: `luacheck`
|
* Lua: `luacheck`
|
||||||
* Mail: `proselint`, `vale`
|
* Mail: `proselint`, `vale`
|
||||||
|
0
test/command_callback/stylelint_paths/node_modules/.bin/stylelint
generated
vendored
Executable file
0
test/command_callback/stylelint_paths/node_modules/.bin/stylelint
generated
vendored
Executable file
@ -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(''))
|
Loading…
Reference in New Issue
Block a user