mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-10 06:21:53 +08:00
Merge pull request #2268 from m-pilia/alex
Add settings for the Alex linter
This commit is contained in:
@@ -1,10 +1,23 @@
|
||||
" Author: Johannes Wienke <languitar@semipol.de>
|
||||
" Description: Error handling for errors in alex output format
|
||||
|
||||
function! ale#handlers#alex#GetExecutable(buffer) abort
|
||||
return ale#node#FindExecutable(a:buffer, 'alex', [
|
||||
\ 'node_modules/.bin/alex',
|
||||
\ 'node_modules/alex/cli.js',
|
||||
\])
|
||||
endfunction
|
||||
|
||||
function! ale#handlers#alex#CreateCommandCallback(flags) abort
|
||||
return {b -> ale#node#Executable(b, ale#handlers#alex#GetExecutable(b))
|
||||
\ . ' %s '
|
||||
\ . a:flags}
|
||||
endfunction
|
||||
|
||||
function! ale#handlers#alex#Handle(buffer, lines) abort
|
||||
" Example output:
|
||||
" 6:256-6:262 warning Be careful with “killed”, it’s profane in some cases killed retext-profanities
|
||||
let l:pattern = '^ *\(\d\+\):\(\d\+\)-\(\d\+\):\(\d\+\) \+warning \+\(.\{-\}\) \+\(.\{-\}\) \+\(.\{-\}\)$'
|
||||
let l:pattern = '\v^ *(\d+):(\d+)-(\d+):(\d+) +warning +(.{-}) +(.{-}) +(.{-})$'
|
||||
let l:output = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
@@ -20,3 +33,21 @@ function! ale#handlers#alex#Handle(buffer, lines) abort
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
" Define a linter for a specific filetype. Accept flags to adapt to the filetype.
|
||||
" no flags treat input as markdown
|
||||
" --html treat input as HTML
|
||||
" --text treat input as plaintext
|
||||
function! ale#handlers#alex#DefineLinter(filetype, flags) abort
|
||||
call ale#Set('alex_executable', 'alex')
|
||||
call ale#Set('alex_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||
|
||||
call ale#linter#Define(a:filetype, {
|
||||
\ 'name': 'alex',
|
||||
\ 'executable_callback': 'ale#handlers#alex#GetExecutable',
|
||||
\ 'command_callback': ale#handlers#alex#CreateCommandCallback(a:flags),
|
||||
\ 'output_stream': 'stderr',
|
||||
\ 'callback': 'ale#handlers#alex#Handle',
|
||||
\ 'lint_file': 1,
|
||||
\})
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user