mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-08 21:44:47 +08:00
Handle powershell unexpected token with newline (#2588)
* Newline in unexpected token broke parser * fixed test to properly capture regressions * removed deprecated linter options for powershell
This commit is contained in:
@@ -49,11 +49,19 @@ function! ale_linters#powershell#powershell#Handle(buffer, lines) abort
|
|||||||
let l:matchcount = 1
|
let l:matchcount = 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" If the match is 0, it was a failed match
|
||||||
|
" probably due to an unexpected token which
|
||||||
|
" contained a newline. Reset matchcount. to
|
||||||
|
" continue to the next match
|
||||||
|
if !empty(l:match[1])
|
||||||
let l:item = {
|
let l:item = {
|
||||||
\ 'lnum': str2nr(l:match[1]),
|
\ 'lnum': str2nr(l:match[1]),
|
||||||
\ 'col': str2nr(l:match[2]),
|
\ 'col': str2nr(l:match[2]),
|
||||||
\ 'type': 'E',
|
\ 'type': 'E',
|
||||||
\}
|
\}
|
||||||
|
else
|
||||||
|
let l:matchcount = 0
|
||||||
|
endif
|
||||||
elseif l:matchcount == 2
|
elseif l:matchcount == 2
|
||||||
" Second match[0] grabs the full line in order
|
" Second match[0] grabs the full line in order
|
||||||
" to handles the text
|
" to handles the text
|
||||||
@@ -84,8 +92,8 @@ endfunction
|
|||||||
|
|
||||||
call ale#linter#Define('powershell', {
|
call ale#linter#Define('powershell', {
|
||||||
\ 'name': 'powershell',
|
\ 'name': 'powershell',
|
||||||
\ 'executable_callback': 'ale_linters#powershell#powershell#GetExecutable',
|
\ 'executable': function('ale_linters#powershell#powershell#GetExecutable'),
|
||||||
\ 'command_callback': 'ale_linters#powershell#powershell#GetCommand',
|
\ 'command': function('ale_linters#powershell#powershell#GetCommand'),
|
||||||
\ 'output_stream': 'stdout',
|
\ 'output_stream': 'stdout',
|
||||||
\ 'callback': 'ale_linters#powershell#powershell#Handle',
|
\ 'callback': 'ale_linters#powershell#powershell#Handle',
|
||||||
\})
|
\})
|
||||||
|
|||||||
@@ -60,3 +60,50 @@ Execute(The powershell handler should process multiple syntax errors from parsin
|
|||||||
\ '+ CategoryInfo : NotSpecified: (:) [], ParseException',
|
\ '+ CategoryInfo : NotSpecified: (:) [], ParseException',
|
||||||
\ '+ FullyQualifiedErrorId : ParseException'
|
\ '+ FullyQualifiedErrorId : ParseException'
|
||||||
\ ])
|
\ ])
|
||||||
|
Execute(The powershell handler should process unexecpected token that contains a newline character):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 2,
|
||||||
|
\ 'col': 8,
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ 'text': 'The string is missing the terminator: ".',
|
||||||
|
\ 'code': 'ParseException'
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 2,
|
||||||
|
\ 'col': 8,
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ 'text': 'Unexpected token ''"',
|
||||||
|
\ 'code': 'ParseException'
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 1,
|
||||||
|
\ 'col': 1,
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ 'text': 'Missing closing ''}'' in statement block or type definition.',
|
||||||
|
\ 'code': 'ParseException'
|
||||||
|
\ }
|
||||||
|
\ ],
|
||||||
|
\ ale_linters#powershell#powershell#Handle(bufnr(''), [
|
||||||
|
\ 'At line:2 char:8',
|
||||||
|
\ '+ "" "',
|
||||||
|
\ '+ ~',
|
||||||
|
\ 'The string is missing the terminator: ".',
|
||||||
|
\ 'At line:2 char:8',
|
||||||
|
\ '+ "" "',
|
||||||
|
\ '+ ~',
|
||||||
|
\ 'Unexpected token ''"',
|
||||||
|
\ '',
|
||||||
|
\ ' }'' in expression or statement.',
|
||||||
|
\ '',
|
||||||
|
\ 'At line:1 char:1',
|
||||||
|
\ '+ {',
|
||||||
|
\ '+ ~',
|
||||||
|
\ 'Missing closing ''}'' in statement block or type definition.',
|
||||||
|
\ 'At C:\Users\jpharris\AppData\Local\Temp\VIAA777.tmp\script.ps1:1 char:150',
|
||||||
|
\ '+ ... ontents); [void]$ExecutionContext.InvokeCommand.NewScriptBlock($Con ...',
|
||||||
|
\ '+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~',
|
||||||
|
\ ' + CategoryInfo : NotSpecified: (:) [], ParseException',
|
||||||
|
\ ' + FullyQualifiedErrorId : ParseException'
|
||||||
|
\ ])
|
||||||
|
|||||||
Reference in New Issue
Block a user