Add support for Microsoft's DSL Bicep (#4310)

* Add support for Microsoft's DSL Bicep

The compilation command 'bicep build' catches compilation errors as well
as providing some lint warnings.

Repository for Bicep: https://github.com/Azure/bicep

* Different null file on Windows & hardcode commands
This commit is contained in:
Carl Smedstad
2022-09-14 01:13:41 +02:00
committed by GitHub
parent 77fcf9b2c2
commit 8e03ceecdc
7 changed files with 144 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
" Author: Carl Smedstad <carl.smedstad at protonmail dot com>
" Description: bicep for bicep files
let g:ale_bicep_bicep_executable =
\ get(g:, 'ale_bicep_bicep_executable', 'bicep')
let g:ale_bicep_bicep_options =
\ get(g:, 'ale_bicep_bicep_options', '')
function! ale_linters#bicep#bicep#Executable(buffer) abort
return ale#Var(a:buffer, 'bicep_bicep_executable')
endfunction
function! ale_linters#bicep#bicep#Command(buffer) abort
let l:executable = ale_linters#bicep#bicep#Executable(a:buffer)
let l:options = ale#Var(a:buffer, 'bicep_bicep_options')
if has('win32')
let l:nullfile = 'NUL'
else
let l:nullfile = '/dev/null'
endif
return ale#Escape(l:executable)
\ . ' build --outfile '
\ . l:nullfile
\ . ' '
\ . l:options
\ . ' %t'
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:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
if l:match[3] is# 'Error'
let l:type = 'E'
elseif l:match[3] 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,
\ 'type': l:type,
\ 'code': l:match[4],
\ 'text': l:match[5],
\})
endfor
return l:output
endfunction
call ale#linter#Define('bicep', {
\ 'name': 'bicep',
\ 'executable': function('ale_linters#bicep#bicep#Executable'),
\ 'command': function('ale_linters#bicep#bicep#Command'),
\ 'callback': 'ale_linters#bicep#bicep#Handle',
\ 'output_stream': 'both',
\})

24
doc/ale-bicep.txt Normal file
View File

@@ -0,0 +1,24 @@
===============================================================================
ALE Bicep Integration *ale-bicep-options*
===============================================================================
bicep *ale-bicep-bicep*
g:ale_bicep_bicep_executable *g:ale_bicep_bicep_executable*
*b:ale_bicep_bicep_executable*
Type: |String|
Default: `'bicep'`
This variable can be set to change the path to bicep.
g:ale_bicep_bicep_options *g:ale_bicep_bicep_options*
*b:ale_bicep_bicep_options*
Type: |String|
Default: `'build --outfile /dev/null'`
This variable can be set to pass additional options to bicep.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@@ -52,6 +52,8 @@ Notes:
* `buildifier`
* BibTeX
* `bibclean`
* Bicep
* `bicep`
* BitBake
* `oelint-adv`
* Bourne Shell

View File

@@ -2787,6 +2787,8 @@ documented in additional help files.
buildifier............................|ale-bazel-buildifier|
bib.....................................|ale-bib-options|
bibclean..............................|ale-bib-bibclean|
bicep...................................|ale-bicep-options|
bicep.................................|ale-bicep-bicep|
bitbake.................................|ale-bitbake-options|
oelint-adv............................|ale-bitbake-oelint_adv|
c.......................................|ale-c-options|

View File

@@ -61,6 +61,8 @@ formatting.
* [buildifier](https://github.com/bazelbuild/buildtools)
* BibTeX
* [bibclean](http://ftp.math.utah.edu/pub/bibclean/)
* Bicep
* [bicep](https://github.com/Azure/bicep)
* BitBake
* [oelint-adv](https://github.com/priv-kweihmann/oelint-adv)
* Bourne Shell

View File

@@ -0,0 +1,30 @@
Before:
runtime ale_linters/bicep/bicep.vim
After:
Restore
call ale#linter#Reset()
Execute(The cmake_lint handler should handle basic warnings):
AssertEqual
\ [
\ {
\ 'lnum': 7,
\ 'col': 10,
\ 'type': 'W',
\ 'code': 'no-unused-existing-resources',
\ 'text': 'Existing resource "asdasd" is declared but never used. [https://aka.ms/bicep/linter/no-unused-existing-resources]',
\ },
\ {
\ 'lnum': 106,
\ 'col': 6,
\ 'type': 'E',
\ 'code': 'BCP019',
\ 'text': 'Expected a new line character at this location.',
\ },
\ ],
\ ale_linters#bicep#bicep#Handle(1, [
\ '/tmp/nvimhxqs5D/1/dns.bicep(7,10) : Warning no-unused-existing-resources: Existing resource "asdasd" is declared but never used. [https://aka.ms/bicep/linter/no-unused-existing-resources]',
\ '/tmp/nvimhxqs5D/1/dns.bicep(106,6) : Error BCP019: Expected a new line character at this location.',
\ ])

View File

@@ -0,0 +1,21 @@
Before:
call ale#assert#SetUpLinterTest('bicep', 'bicep')
After:
call ale#assert#TearDownLinterTest()
Execute(The default command should be correct):
if has('win32')
AssertLinter 'bicep', ale#Escape('bicep') . ' build --outfile NUL %t'
else
AssertLinter 'bicep', ale#Escape('bicep') . ' build --outfile /dev/null %t'
endif
Execute(The executable should be configurable):
let g:ale_bicep_bicep_executable = 'foobar'
if has('win32')
AssertLinter 'foobar', ale#Escape('foobar') . ' build --outfile NUL %t'
else
AssertLinter 'foobar', ale#Escape('foobar') . ' build --outfile /dev/null %t'
endif