Add support for AVRA linting (#3950)

* Add support for AVRA linting

* Add tests for AVRA linting and improve code

* Fix test

* Fix warning detection

* Fix test

* Fix test

* Add AVRA as a supported language in docs
This commit is contained in:
Utkarsh Verma 2021-11-15 16:11:03 +05:30 committed by GitHub
parent 76c2293e68
commit 1e0e76bf96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 121 additions and 0 deletions

36
ale_linters/avra/avra.vim Normal file
View File

@ -0,0 +1,36 @@
" Author: Utkarsh Verma <utkarshverma@protonmail.com>
" Description: AVRA linter for avra syntax.
call ale#Set('avra_avra_executable', 'avra')
call ale#Set('avra_avra_options', '')
function! ale_linters#avra#avra#GetCommand(buffer) abort
return '%e'
\ . ' %t'
\ . ale#Pad(ale#Var(a:buffer, 'avra_avra_options'))
\ . ' -o ' . g:ale#util#nul_file
endfunction
function! ale_linters#avra#avra#Handle(buffer, lines) abort
" Note that we treat 'fatal' as errors.
let l:pattern = '^\S\+(\(\d\+\))\s\+:\s\+\(\S\+\)\s\+:\s\+\(.\+\)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'type': l:match[2] =~? 'Error' ? 'E' : 'W',
\ 'text': l:match[3],
\})
endfor
return l:output
endfunction
call ale#linter#Define('avra', {
\ 'name': 'avra',
\ 'output_stream': 'stderr',
\ 'executable': {b -> ale#Var(b, 'avra_avra_executable')},
\ 'command': function('ale_linters#avra#avra#GetCommand'),
\ 'callback': 'ale_linters#avra#avra#Handle',
\})

26
doc/ale-avra.txt Normal file
View File

@ -0,0 +1,26 @@
===============================================================================
ALE AVRA Integration *ale-avra-options*
===============================================================================
avra *ale-avra-avra*
g:ale_avra_avra_executable *g:ale_avra_avra_executable*
*b:ale_avra_avra_executable*
Type: |String|
Default `'avra'`
This variable can be changed to use different executable for AVRA.
g:ale_avra_avra_options *g:ale_avra_avra_options*
*b:ale_avra_avra_options*
Type: |String|
Default: `''`
This variable can be set to pass additional options to AVRA.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -33,6 +33,8 @@ Notes:
* `write-good` * `write-good`
* ASM * ASM
* `gcc` * `gcc`
* AVRA
* `avra`
* Awk * Awk
* `gawk` * `gawk`
* Bash * Bash

View File

@ -2633,6 +2633,8 @@ documented in additional help files.
textlint..............................|ale-asciidoc-textlint| textlint..............................|ale-asciidoc-textlint|
asm.....................................|ale-asm-options| asm.....................................|ale-asm-options|
gcc...................................|ale-asm-gcc| gcc...................................|ale-asm-gcc|
avra....................................|ale-avra-options|
avra..................................|ale-avra-avra|
awk.....................................|ale-awk-options| awk.....................................|ale-awk-options|
gawk..................................|ale-awk-gawk| gawk..................................|ale-awk-gawk|
bats....................................|ale-bats-options| bats....................................|ale-bats-options|

View File

@ -42,6 +42,8 @@ formatting.
* [write-good](https://github.com/btford/write-good) * [write-good](https://github.com/btford/write-good)
* ASM * ASM
* [gcc](https://gcc.gnu.org) * [gcc](https://gcc.gnu.org)
* AVRA
* [avra](https://github.com/Ro5bert/avra)
* Awk * Awk
* [gawk](https://www.gnu.org/software/gawk/) * [gawk](https://www.gnu.org/software/gawk/)
* Bash * Bash

View File

@ -0,0 +1,24 @@
Before:
runtime ale_linters/avra/avra.vim
After:
call ale#linter#Reset()
Execute(The avra handler should parse errors correctly):
AssertEqual
\ [
\ {
\ 'lnum': 3,
\ 'text': "Unknown device: atmega3228p",
\ 'type': 'E'
\ },
\ {
\ 'lnum': 12,
\ 'text': "Unknown directive: .EQ",
\ 'type': 'E'
\ }
\ ],
\ ale_linters#avra#avra#Handle(bufnr(''), [
\ "main.asm(3) : Error : Unknown device: atmega3228p",
\ "main.asm(12) : Error : Unknown directive: .EQ"
\ ])

View File

@ -0,0 +1,29 @@
Before:
call ale#assert#SetUpLinterTest('avra', 'avra')
let b:command_tail = ' %t -o ' . g:ale#util#nul_file
let b:command_tail_opt = ' %t --max_errors 20 -o ' . g:ale#util#nul_file
After:
unlet! b:command_tail
unlet! b:command_tail_opt
call ale#assert#TearDownLinterTest()
Execute(The executable should be configurable):
AssertLinter 'avra', ale#Escape('avra') . b:command_tail,
let b:ale_avra_avra_executable = '~/avra'
AssertLinter '~/avra', ale#Escape('~/avra') . b:command_tail
Execute(The options should be configurable):
let b:ale_avra_avra_options = '--max_errors 20'
AssertLinter 'avra', ale#Escape('avra')
\ . ' %t --max_errors 20 -o ' . g:ale#util#nul_file
Execute(The options should be used in command):
let b:ale_avra_avra_options = '--max_errors 20'
AssertLinter 'avra', ale#Escape('avra') . b:command_tail_opt