mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 12:44:23 +08:00
Add support for Bicep when installed as a plugin to Azure CLI (#4496)
* Add support for Bicep when installed as a plugin to Azure CLI The compiler for Microsoft's DSL Bicep can be installed both independently and as a plugin to Azure CLI. The latter is probably how most people install it. The program output is the same but Azure CLI wraps the arguments and has a slightly different interface, hence I opted to copy the old linter and modify it to match the plugin arguments. * Fix bicep/az_bicep tests, arguments and parsing * Actually test the ale_linters#bicep#az_bicep#Handle function in the test that should test that function, not ale_linters#bicep#bicep#Handle. * Use the same method as in bicep/bicep for discarding output file, i.e. by specifying --outfile to a null file. * Fix parsing of occasionally occurring leading error type (such as 'ERROR: '). * Correct option defaults for bicep & az_bicep specified in documentation
This commit is contained in:
69
ale_linters/bicep/az_bicep.vim
Normal file
69
ale_linters/bicep/az_bicep.vim
Normal file
@@ -0,0 +1,69 @@
|
||||
" Author: Carl Smedstad <carl.smedstad at protonmail dot com>
|
||||
" Description: az_bicep for bicep files
|
||||
|
||||
let g:ale_bicep_az_bicep_executable =
|
||||
\ get(g:, 'ale_bicep_az_bicep_executable', 'az')
|
||||
|
||||
let g:ale_bicep_az_bicep_options =
|
||||
\ get(g:, 'ale_bicep_az_bicep_options', '')
|
||||
|
||||
function! ale_linters#bicep#az_bicep#Executable(buffer) abort
|
||||
return ale#Var(a:buffer, 'bicep_az_bicep_executable')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#bicep#az_bicep#Command(buffer) abort
|
||||
let l:executable = ale_linters#bicep#az_bicep#Executable(a:buffer)
|
||||
let l:options = ale#Var(a:buffer, 'bicep_az_bicep_options')
|
||||
|
||||
if has('win32')
|
||||
let l:nullfile = 'NUL'
|
||||
else
|
||||
let l:nullfile = '/dev/null'
|
||||
endif
|
||||
|
||||
return ale#Escape(l:executable)
|
||||
\ . ' bicep build --outfile '
|
||||
\ . l:nullfile
|
||||
\ . ' --file '
|
||||
\ . '%s '
|
||||
\ . l:options
|
||||
endfunction
|
||||
|
||||
function! ale_linters#bicep#az_bicep#Handle(buffer, lines) abort
|
||||
let l:pattern = '\v^([A-Z]+)?(:\s)?(.*)\((\d+),(\d+)\)\s:\s([a-zA-Z]*)\s([-a-zA-Z0-9]*):\s(.*)'
|
||||
let l:output = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
if l:match[1] is# 'ERROR'
|
||||
let l:type = 'E'
|
||||
elseif l:match[1] is# 'WARNING'
|
||||
let l:type = 'W'
|
||||
elseif l:match[6] is# 'Error'
|
||||
let l:type = 'E'
|
||||
elseif l:match[6] is# 'Warning'
|
||||
let l:type = 'W'
|
||||
else
|
||||
let l:type = 'I'
|
||||
endif
|
||||
|
||||
call add(l:output, {
|
||||
\ 'filename': l:match[3],
|
||||
\ 'lnum': l:match[4] + 0,
|
||||
\ 'col': l:match[5] + 0,
|
||||
\ 'type': l:type,
|
||||
\ 'code': l:match[7],
|
||||
\ 'text': l:match[8],
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('bicep', {
|
||||
\ 'name': 'az_bicep',
|
||||
\ 'executable': function('ale_linters#bicep#az_bicep#Executable'),
|
||||
\ 'command': function('ale_linters#bicep#az_bicep#Command'),
|
||||
\ 'callback': 'ale_linters#bicep#az_bicep#Handle',
|
||||
\ 'output_stream': 'stderr',
|
||||
\ 'lint_file': 1,
|
||||
\})
|
||||
@@ -30,24 +30,25 @@ function! ale_linters#bicep#bicep#Command(buffer) abort
|
||||
endfunction
|
||||
|
||||
function! ale_linters#bicep#bicep#Handle(buffer, lines) abort
|
||||
let l:pattern = '\v^.*\((\d+),(\d+)\)\s:\s([a-zA-Z]*)\s([-a-zA-Z0-9]*):\s(.*)'
|
||||
let l:pattern = '\v^(.*)\((\d+),(\d+)\)\s:\s([a-zA-Z]*)\s([-a-zA-Z0-9]*):\s(.*)'
|
||||
let l:output = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
if l:match[3] is# 'Error'
|
||||
if l:match[4] is# 'Error'
|
||||
let l:type = 'E'
|
||||
elseif l:match[3] is# 'Warning'
|
||||
elseif l:match[4] is# 'Warning'
|
||||
let l:type = 'W'
|
||||
else
|
||||
let l:type = 'I'
|
||||
endif
|
||||
|
||||
call add(l:output, {
|
||||
\ 'lnum': l:match[1] + 0,
|
||||
\ 'col': l:match[2] + 0,
|
||||
\ 'filename': l:match[1],
|
||||
\ 'lnum': l:match[2] + 0,
|
||||
\ 'col': l:match[3] + 0,
|
||||
\ 'type': l:type,
|
||||
\ 'code': l:match[4],
|
||||
\ 'text': l:match[5],
|
||||
\ 'code': l:match[5],
|
||||
\ 'text': l:match[6],
|
||||
\})
|
||||
endfor
|
||||
|
||||
|
||||
Reference in New Issue
Block a user