mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-08 13:34:46 +08:00
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:
63
ale_linters/bicep/bicep.vim
Normal file
63
ale_linters/bicep/bicep.vim
Normal 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
24
doc/ale-bicep.txt
Normal 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:
|
||||||
@@ -52,6 +52,8 @@ Notes:
|
|||||||
* `buildifier`
|
* `buildifier`
|
||||||
* BibTeX
|
* BibTeX
|
||||||
* `bibclean`
|
* `bibclean`
|
||||||
|
* Bicep
|
||||||
|
* `bicep`
|
||||||
* BitBake
|
* BitBake
|
||||||
* `oelint-adv`
|
* `oelint-adv`
|
||||||
* Bourne Shell
|
* Bourne Shell
|
||||||
|
|||||||
@@ -2787,6 +2787,8 @@ documented in additional help files.
|
|||||||
buildifier............................|ale-bazel-buildifier|
|
buildifier............................|ale-bazel-buildifier|
|
||||||
bib.....................................|ale-bib-options|
|
bib.....................................|ale-bib-options|
|
||||||
bibclean..............................|ale-bib-bibclean|
|
bibclean..............................|ale-bib-bibclean|
|
||||||
|
bicep...................................|ale-bicep-options|
|
||||||
|
bicep.................................|ale-bicep-bicep|
|
||||||
bitbake.................................|ale-bitbake-options|
|
bitbake.................................|ale-bitbake-options|
|
||||||
oelint-adv............................|ale-bitbake-oelint_adv|
|
oelint-adv............................|ale-bitbake-oelint_adv|
|
||||||
c.......................................|ale-c-options|
|
c.......................................|ale-c-options|
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ formatting.
|
|||||||
* [buildifier](https://github.com/bazelbuild/buildtools)
|
* [buildifier](https://github.com/bazelbuild/buildtools)
|
||||||
* BibTeX
|
* BibTeX
|
||||||
* [bibclean](http://ftp.math.utah.edu/pub/bibclean/)
|
* [bibclean](http://ftp.math.utah.edu/pub/bibclean/)
|
||||||
|
* Bicep
|
||||||
|
* [bicep](https://github.com/Azure/bicep)
|
||||||
* BitBake
|
* BitBake
|
||||||
* [oelint-adv](https://github.com/priv-kweihmann/oelint-adv)
|
* [oelint-adv](https://github.com/priv-kweihmann/oelint-adv)
|
||||||
* Bourne Shell
|
* Bourne Shell
|
||||||
|
|||||||
30
test/handler/test_bicep_bicep_handler.vader
Normal file
30
test/handler/test_bicep_bicep_handler.vader
Normal 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.',
|
||||||
|
\ ])
|
||||||
21
test/linter/test_bicep_bicep.vader
Normal file
21
test/linter/test_bicep_bicep.vader
Normal 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
|
||||||
Reference in New Issue
Block a user