Merge branch 'zanona-less-lessc-linter'
This commit is contained in:
commit
5b3094558b
@ -109,6 +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) |
|
||||
| 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) |
|
||||
|
56
ale_linters/less/lessc.vim
Executable file
56
ale_linters/less/lessc.vim
Executable file
@ -0,0 +1,56 @@
|
||||
" Author: zanona <https://github.com/zanona>, w0rp <devw0rp@gmail.com>
|
||||
" Description: This file adds support for checking Less code with lessc.
|
||||
|
||||
call ale#Set('less_lessc_executable', 'lessc')
|
||||
call ale#Set('less_lessc_options', '')
|
||||
call ale#Set('less_lessc_use_global', 0)
|
||||
|
||||
function! ale_linters#less#lessc#GetExecutable(buffer) abort
|
||||
return ale#node#FindExecutable(a:buffer, 'less_lessc', [
|
||||
\ 'node_modules/.bin/lessc',
|
||||
\])
|
||||
endfunction
|
||||
|
||||
function! ale_linters#less#lessc#GetCommand(buffer) abort
|
||||
let l:executable = ale_linters#less#lessc#GetExecutable(a:buffer)
|
||||
let l:dir = expand('#' . a:buffer . ':p:h')
|
||||
let l:options = ale#Var(a:buffer, 'less_lessc_options')
|
||||
|
||||
return ale#Escape(l:executable)
|
||||
\ . ' --no-color --lint'
|
||||
\ . ' --include-path=' . ale#Escape(l:dir)
|
||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||
\ . ' -'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#less#lessc#Handle(buffer, lines) abort
|
||||
let l:dir = expand('#' . a:buffer . ':p:h')
|
||||
" Matches patterns like the following:
|
||||
let l:pattern = '^\(\w\+\): \(.\{-}\) in \(.\{-}\) on line \(\d\+\), column \(\d\+\):$'
|
||||
let l:output = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
let l:item = {
|
||||
\ 'lnum': l:match[4] + 0,
|
||||
\ 'col': l:match[5] + 0,
|
||||
\ 'text': l:match[2],
|
||||
\ 'type': 'E',
|
||||
\}
|
||||
|
||||
if l:match[3] isnot# '-'
|
||||
let l:item.filename = ale#path#GetAbsPath(l:dir, l:match[3])
|
||||
endif
|
||||
|
||||
call add(l:output, l:item)
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('less', {
|
||||
\ 'name': 'lessc',
|
||||
\ 'executable_callback': 'ale_linters#less#lessc#GetExecutable',
|
||||
\ 'command_callback': 'ale_linters#less#lessc#GetCommand',
|
||||
\ 'callback': 'ale_linters#less#lessc#Handle',
|
||||
\ 'output_stream': 'stderr',
|
||||
\})
|
@ -2,6 +2,33 @@
|
||||
ALE Less Integration *ale-less-options*
|
||||
|
||||
|
||||
===============================================================================
|
||||
lessc *ale-less-lessc*
|
||||
|
||||
g:ale_less_lessc_executable *g:ale_less_lessc_executable*
|
||||
*b:ale_less_lessc_executable*
|
||||
Type: |String|
|
||||
Default: `'lessc'`
|
||||
|
||||
See |ale-integrations-local-executables|
|
||||
|
||||
|
||||
g:ale_less_lessc_options *g:ale_less_lessc_options*
|
||||
*b:ale_less_lessc_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
This variable can be set to pass additional options to lessc.
|
||||
|
||||
|
||||
g:ale_less_lessc_use_global *g:ale_less_lessc_use_global*
|
||||
*b:ale_less_lessc_use_global*
|
||||
Type: |String|
|
||||
Default: `0`
|
||||
|
||||
See |ale-integrations-local-executables|
|
||||
|
||||
|
||||
===============================================================================
|
||||
prettier *ale-less-prettier*
|
||||
|
||||
@ -9,4 +36,4 @@ See |ale-javascript-prettier| for information about the available options.
|
||||
|
||||
|
||||
===============================================================================
|
||||
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||
|
@ -105,6 +105,7 @@ CONTENTS *ale-contents*
|
||||
latex.................................|ale-latex-options|
|
||||
write-good..........................|ale-latex-write-good|
|
||||
less..................................|ale-less-options|
|
||||
lessc...............................|ale-less-lessc|
|
||||
prettier............................|ale-less-prettier|
|
||||
llvm..................................|ale-llvm-options|
|
||||
llc.................................|ale-llvm-llc|
|
||||
@ -297,6 +298,7 @@ Notes:
|
||||
* JSON: `jsonlint`, `prettier`
|
||||
* Kotlin: `kotlinc`, `ktlint`
|
||||
* LaTeX (tex): `chktex`, `lacheck`, `proselint`, `write-good`
|
||||
* Less: `lessc`
|
||||
* LLVM: `llc`
|
||||
* Lua: `luacheck`
|
||||
* Mail: `proselint`, `vale`
|
||||
|
0
test/command_callback/lessc_paths/node_modules/.bin/lessc
generated
vendored
Executable file
0
test/command_callback/lessc_paths/node_modules/.bin/lessc
generated
vendored
Executable file
82
test/command_callback/test_lessc_command_callback.vader
Normal file
82
test/command_callback/test_lessc_command_callback.vader
Normal file
@ -0,0 +1,82 @@
|
||||
Before:
|
||||
Save g:ale_less_lessc_executable
|
||||
Save g:ale_less_lessc_use_global
|
||||
Save g:ale_less_lessc_options
|
||||
|
||||
unlet! b:executable
|
||||
|
||||
unlet! g:ale_less_lessc_executable
|
||||
unlet! g:ale_less_lessc_use_global
|
||||
unlet! g:ale_less_lessc_options
|
||||
|
||||
call ale#test#SetDirectory('/testplugin/test/command_callback')
|
||||
call ale#test#SetFilename('testfile.less')
|
||||
|
||||
runtime ale_linters/less/lessc.vim
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
unlet! b:executable
|
||||
unlet! b:ale_less_lessc_executable
|
||||
unlet! b:ale_less_lessc_use_global
|
||||
unlet! b:ale_less_lessc_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('lessc_paths/nested/testfile.less')
|
||||
|
||||
let b:executable = ale#path#Winify(
|
||||
\ g:dir
|
||||
\ . '/lessc_paths/node_modules/.bin/lessc'
|
||||
\)
|
||||
|
||||
AssertEqual
|
||||
\ b:executable,
|
||||
\ ale_linters#less#lessc#GetExecutable(bufnr(''))
|
||||
|
||||
AssertEqual
|
||||
\ ale#Escape(b:executable)
|
||||
\ . ' --no-color --lint'
|
||||
\ . ' --include-path='
|
||||
\ . ale#Escape(ale#path#Winify(g:dir . '/lessc_paths/nested'))
|
||||
\ . ' -',
|
||||
\ ale_linters#less#lessc#GetCommand(bufnr(''))
|
||||
|
||||
Execute(The global override should work):
|
||||
let b:ale_less_lessc_executable = 'foobar'
|
||||
let b:ale_less_lessc_use_global = 1
|
||||
|
||||
call ale#test#SetFilename('lessc_paths/nested/testfile.less')
|
||||
|
||||
AssertEqual
|
||||
\ 'foobar',
|
||||
\ ale_linters#less#lessc#GetExecutable(bufnr(''))
|
||||
|
||||
AssertEqual
|
||||
\ ale#Escape('foobar')
|
||||
\ . ' --no-color --lint'
|
||||
\ . ' --include-path='
|
||||
\ . ale#Escape(ale#path#Winify(g:dir . '/lessc_paths/nested'))
|
||||
\ . ' -',
|
||||
\ ale_linters#less#lessc#GetCommand(bufnr(''))
|
||||
|
||||
Execute(Extra options should be configurable):
|
||||
let b:ale_less_lessc_options = '--whatever'
|
||||
|
||||
AssertEqual
|
||||
\ 'lessc',
|
||||
\ ale_linters#less#lessc#GetExecutable(bufnr(''))
|
||||
|
||||
AssertEqual
|
||||
\ ale#Escape('lessc')
|
||||
\ . ' --no-color --lint'
|
||||
\ . ' --include-path='
|
||||
\ . ale#Escape(ale#path#Winify(g:dir))
|
||||
\ . ' --whatever'
|
||||
\ . ' -',
|
||||
\ ale_linters#less#lessc#GetCommand(bufnr(''))
|
69
test/handler/test_lessc_handler.vader
Normal file
69
test/handler/test_lessc_handler.vader
Normal file
@ -0,0 +1,69 @@
|
||||
Before:
|
||||
call ale#test#SetDirectory('/testplugin/test/handler')
|
||||
call ale#test#SetFilename('testfile.less')
|
||||
|
||||
runtime ale_linters/less/lessc.vim
|
||||
|
||||
After:
|
||||
call ale#test#RestoreDirectory()
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The lessc handler should handle errors for the current file correctly):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 2,
|
||||
\ 'col': 1,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'Unrecognised input. Possibly missing something',
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#less#lessc#Handle(bufnr(''), [
|
||||
\ 'ParseError: Unrecognised input. Possibly missing something in - on line 2, column 1:',
|
||||
\ '1 vwewww',
|
||||
\ '2 ',
|
||||
\])
|
||||
|
||||
Execute(The lessc handler should handle errors for other files in the same directory correctly):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 2,
|
||||
\ 'col': 1,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'Unrecognised input. Possibly missing something',
|
||||
\ 'filename': ale#path#Winify(g:dir . '/imported.less')
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 2,
|
||||
\ 'col': 1,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'Unrecognised input. Possibly missing something',
|
||||
\ 'filename': ale#path#Winify(g:dir . '/imported.less')
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#less#lessc#Handle(bufnr(''), [
|
||||
\ 'ParseError: Unrecognised input. Possibly missing something in imported.less on line 2, column 1:',
|
||||
\ '1 vwewww',
|
||||
\ '2 ',
|
||||
\ 'ParseError: Unrecognised input. Possibly missing something in ./imported.less on line 2, column 1:',
|
||||
\ '1 vwewww',
|
||||
\ '2 ',
|
||||
\])
|
||||
|
||||
Execute(The lessc handler should handle errors for files in directories above correctly):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 2,
|
||||
\ 'col': 1,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'Unrecognised input. Possibly missing something',
|
||||
\ 'filename': ale#path#Winify(g:dir . '/../imported2.less')
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#less#lessc#Handle(bufnr(''), [
|
||||
\ 'ParseError: Unrecognised input. Possibly missing something in ../imported2.less on line 2, column 1:',
|
||||
\ '1 vwewww',
|
||||
\ '2 ',
|
||||
\])
|
Loading…
Reference in New Issue
Block a user