Skip to content

Commit

Permalink
#810 Ignore output which isn't JSON for brakeman
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rp committed Jul 26, 2017
1 parent 810e884 commit ded1bc1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
7 changes: 6 additions & 1 deletion ale_linters/ruby/brakeman.vim
Expand Up @@ -9,7 +9,12 @@ function! ale_linters#ruby#brakeman#Handle(buffer, lines) abort
return []
endif

let l:result = json_decode(join(a:lines, ''))
try
let l:result = json_decode(join(a:lines, ''))
catch /E474/
" Ignore invalid JSON
return []
endtry

let l:output = []

Expand Down
24 changes: 13 additions & 11 deletions test/handler/test_brakeman_handler.vader
@@ -1,20 +1,15 @@
Before:
" Switch to the test rails directory.
let b:path = getcwd()
silent! cd /testplugin/test/handler
cd ../ruby_fixtures/valid_rails_app/app/models
call ale#test#SetDirectory('/testplugin/test/handler')
cd ..

runtime ale_linters/ruby/brakeman.vim
runtime ale_linters/ruby/brakeman.vim

After:
" Switch back to whatever directory it was that we started on.
silent! 'cd ' . fnameescape(b:path)
unlet! b:path

call ale#linter#Reset()
call ale#test#RestoreDirectory()
call ale#linter#Reset()

Execute(The brakeman handler should parse JSON correctly):
silent file! thing.rb
call ale#test#SetFilename('ruby_fixtures/valid_rails_app/app/models/thing.rb')

AssertEqual
\ [
Expand Down Expand Up @@ -78,3 +73,10 @@ Execute(The brakeman handler should parse JSON correctly when there is no output
\ [],
\ ale_linters#ruby#brakeman#Handle(347, [
\ ])
\
Execute(The brakeman handler should handle garbage output):
AssertEqual
\ [],
\ ale_linters#ruby#brakeman#Handle(347, [
\ 'No such command in 2.4.1 of ruby',
\ ])

0 comments on commit ded1bc1

Please sign in to comment.