#810 - Handle output which is not JSON in many linters
This commit is contained in:
parent
db4d68eae7
commit
fa33faad9e
@ -4,31 +4,21 @@
|
|||||||
function! ale_linters#crystal#crystal#Handle(buffer, lines) abort
|
function! ale_linters#crystal#crystal#Handle(buffer, lines) abort
|
||||||
let l:output = []
|
let l:output = []
|
||||||
|
|
||||||
let l:lines = join(a:lines, '')
|
for l:error in ale#util#FuzzyJSONDecode(a:lines, [])
|
||||||
|
|
||||||
if !empty(l:lines)
|
|
||||||
let l:errors = json_decode(l:lines)
|
|
||||||
|
|
||||||
for l:error in l:errors
|
|
||||||
call add(l:output, {
|
call add(l:output, {
|
||||||
\ 'bufnr': a:buffer,
|
|
||||||
\ 'lnum': l:error.line + 0,
|
\ 'lnum': l:error.line + 0,
|
||||||
\ 'col': l:error.column + 0,
|
\ 'col': l:error.column + 0,
|
||||||
\ 'text': l:error.message,
|
\ 'text': l:error.message,
|
||||||
\ 'type': 'E',
|
|
||||||
\})
|
\})
|
||||||
endfor
|
endfor
|
||||||
endif
|
|
||||||
|
|
||||||
return l:output
|
return l:output
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#crystal#crystal#GetCommand(buffer) abort
|
function! ale_linters#crystal#crystal#GetCommand(buffer) abort
|
||||||
let l:crystal_cmd = 'crystal build -f json --no-codegen --no-color -o '
|
return 'crystal build -f json --no-codegen --no-color -o '
|
||||||
let l:crystal_cmd .= ale#Escape(g:ale#util#nul_file)
|
\ . ale#Escape(g:ale#util#nul_file)
|
||||||
let l:crystal_cmd .= ' %s'
|
\ . ' %s'
|
||||||
|
|
||||||
return l:crystal_cmd
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call ale#linter#Define('crystal', {
|
call ale#linter#Define('crystal', {
|
||||||
|
@ -16,16 +16,10 @@ function! ale_linters#handlebars#embertemplatelint#GetCommand(buffer) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#handlebars#embertemplatelint#Handle(buffer, lines) abort
|
function! ale_linters#handlebars#embertemplatelint#Handle(buffer, lines) abort
|
||||||
if len(a:lines) == 0
|
|
||||||
return []
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:output = []
|
let l:output = []
|
||||||
|
let l:json = ale#util#FuzzyJSONDecode(a:lines, {})
|
||||||
|
|
||||||
let l:input_json = json_decode(join(a:lines, ''))
|
for l:error in get(values(l:json), 0, [])
|
||||||
let l:file_errors = values(l:input_json)[0]
|
|
||||||
|
|
||||||
for l:error in l:file_errors
|
|
||||||
if has_key(l:error, 'fatal')
|
if has_key(l:error, 'fatal')
|
||||||
call add(l:output, {
|
call add(l:output, {
|
||||||
\ 'bufnr': a:buffer,
|
\ 'bufnr': a:buffer,
|
||||||
|
@ -2,15 +2,9 @@
|
|||||||
" Description: hlint for Haskell files
|
" Description: hlint for Haskell files
|
||||||
|
|
||||||
function! ale_linters#haskell#hlint#Handle(buffer, lines) abort
|
function! ale_linters#haskell#hlint#Handle(buffer, lines) abort
|
||||||
if empty(a:lines)
|
|
||||||
return []
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:errors = json_decode(join(a:lines, ''))
|
|
||||||
|
|
||||||
let l:output = []
|
let l:output = []
|
||||||
|
|
||||||
for l:error in l:errors
|
for l:error in ale#util#FuzzyJSONDecode(a:lines, [])
|
||||||
if l:error.severity ==# 'Error'
|
if l:error.severity ==# 'Error'
|
||||||
let l:type = 'E'
|
let l:type = 'E'
|
||||||
elseif l:error.severity ==# 'Suggestion'
|
elseif l:error.severity ==# 'Suggestion'
|
||||||
|
@ -5,20 +5,10 @@ let g:ale_ruby_brakeman_options =
|
|||||||
\ get(g:, 'ale_ruby_brakeman_options', '')
|
\ get(g:, 'ale_ruby_brakeman_options', '')
|
||||||
|
|
||||||
function! ale_linters#ruby#brakeman#Handle(buffer, lines) abort
|
function! ale_linters#ruby#brakeman#Handle(buffer, lines) abort
|
||||||
if len(a:lines) == 0
|
|
||||||
return []
|
|
||||||
endif
|
|
||||||
|
|
||||||
try
|
|
||||||
let l:result = json_decode(join(a:lines, ''))
|
|
||||||
catch /E474/
|
|
||||||
" Ignore invalid JSON
|
|
||||||
return []
|
|
||||||
endtry
|
|
||||||
|
|
||||||
let l:output = []
|
let l:output = []
|
||||||
|
let l:json = ale#util#FuzzyJSONDecode(a:lines, {})
|
||||||
|
|
||||||
for l:warning in l:result.warnings
|
for l:warning in get(l:json, 'warnings', [])
|
||||||
" Brakeman always outputs paths relative to the Rails app root
|
" Brakeman always outputs paths relative to the Rails app root
|
||||||
let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
|
let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
|
||||||
let l:warning_file = l:rails_root . '/' . l:warning.file
|
let l:warning_file = l:rails_root . '/' . l:warning.file
|
||||||
|
@ -5,15 +5,9 @@ let g:ale_ruby_rails_best_practices_options =
|
|||||||
\ get(g:, 'ale_ruby_rails_best_practices_options', '')
|
\ get(g:, 'ale_ruby_rails_best_practices_options', '')
|
||||||
|
|
||||||
function! ale_linters#ruby#rails_best_practices#Handle(buffer, lines) abort
|
function! ale_linters#ruby#rails_best_practices#Handle(buffer, lines) abort
|
||||||
if len(a:lines) == 0
|
|
||||||
return []
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:result = json_decode(join(a:lines, ''))
|
|
||||||
|
|
||||||
let l:output = []
|
let l:output = []
|
||||||
|
|
||||||
for l:warning in l:result
|
for l:warning in ale#util#FuzzyJSONDecode(a:lines, [])
|
||||||
if !ale#path#IsBufferPath(a:buffer, l:warning.filename)
|
if !ale#path#IsBufferPath(a:buffer, l:warning.filename)
|
||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
|
@ -1,22 +1,13 @@
|
|||||||
" Author: Eddie Lebow https://github.com/elebow
|
" Author: Eddie Lebow https://github.com/elebow
|
||||||
" Description: Reek, a code smell detector for Ruby files
|
" Description: Reek, a code smell detector for Ruby files
|
||||||
|
|
||||||
let g:ale_ruby_reek_show_context =
|
call ale#Set('ruby_reek_show_context', 0)
|
||||||
\ get(g:, 'ale_ruby_reek_show_context', 0)
|
call ale#Set('ruby_reek_show_wiki_link', 0)
|
||||||
|
|
||||||
let g:ale_ruby_reek_show_wiki_link =
|
|
||||||
\ get(g:, 'ale_ruby_reek_show_wiki_link', 0)
|
|
||||||
|
|
||||||
function! ale_linters#ruby#reek#Handle(buffer, lines) abort
|
function! ale_linters#ruby#reek#Handle(buffer, lines) abort
|
||||||
if len(a:lines) == 0
|
|
||||||
return []
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:errors = json_decode(a:lines[0])
|
|
||||||
|
|
||||||
let l:output = []
|
let l:output = []
|
||||||
|
|
||||||
for l:error in l:errors
|
for l:error in ale#util#FuzzyJSONDecode(a:lines, [])
|
||||||
for l:location in l:error.lines
|
for l:location in l:error.lines
|
||||||
call add(l:output, {
|
call add(l:output, {
|
||||||
\ 'lnum': l:location,
|
\ 'lnum': l:location,
|
||||||
|
@ -14,11 +14,7 @@ endfunction
|
|||||||
function! ale_linters#typescript#tslint#Handle(buffer, lines) abort
|
function! ale_linters#typescript#tslint#Handle(buffer, lines) abort
|
||||||
let l:output = []
|
let l:output = []
|
||||||
|
|
||||||
if empty(a:lines)
|
for l:error in ale#util#FuzzyJSONDecode(a:lines, [])
|
||||||
return []
|
|
||||||
endif
|
|
||||||
|
|
||||||
for l:error in json_decode(join(a:lines, ''))
|
|
||||||
if ale#path#IsBufferPath(a:buffer, l:error.name)
|
if ale#path#IsBufferPath(a:buffer, l:error.name)
|
||||||
call add(l:output, {
|
call add(l:output, {
|
||||||
\ 'type': (get(l:error, 'ruleSeverity', '') ==# 'WARNING' ? 'W' : 'E'),
|
\ 'type': (get(l:error, 'ruleSeverity', '') ==# 'WARNING' ? 'W' : 'E'),
|
||||||
|
@ -4,9 +4,7 @@ Execute(The crystal handler should parse lines correctly and add the column if i
|
|||||||
\ [
|
\ [
|
||||||
\ {
|
\ {
|
||||||
\ 'lnum': 2,
|
\ 'lnum': 2,
|
||||||
\ 'bufnr': 255,
|
|
||||||
\ 'col': 1,
|
\ 'col': 1,
|
||||||
\ 'type': 'E',
|
|
||||||
\ 'text': 'unexpected token: EOF'
|
\ 'text': 'unexpected token: EOF'
|
||||||
\ }
|
\ }
|
||||||
\ ],
|
\ ],
|
||||||
|
@ -75,9 +75,11 @@ Execute(The ember-template-lint handler should handle template parsing error cor
|
|||||||
|
|
||||||
Execute(The ember-template-lint handler should handle no lint errors/warnings):
|
Execute(The ember-template-lint handler should handle no lint errors/warnings):
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ [
|
\ [],
|
||||||
\ ],
|
|
||||||
\ ale_linters#handlebars#embertemplatelint#Handle(347, [])
|
\ ale_linters#handlebars#embertemplatelint#Handle(347, [])
|
||||||
|
AssertEqual
|
||||||
|
\ [],
|
||||||
|
\ ale_linters#handlebars#embertemplatelint#Handle(347, ['{}'])
|
||||||
|
|
||||||
After:
|
After:
|
||||||
call ale#linter#Reset()
|
call ale#linter#Reset()
|
||||||
|
@ -1,20 +1,15 @@
|
|||||||
Before:
|
Before:
|
||||||
" Switch to the test rails directory.
|
call ale#test#SetDirectory('/testplugin/test/handler')
|
||||||
let b:path = getcwd()
|
cd ..
|
||||||
silent! cd /testplugin/test/handler
|
|
||||||
cd ../ruby_fixtures/valid_rails_app/app/models
|
|
||||||
|
|
||||||
runtime ale_linters/ruby/rails_best_practices.vim
|
runtime ale_linters/ruby/rails_best_practices.vim
|
||||||
|
|
||||||
After:
|
After:
|
||||||
" Switch back to whatever directory it was that we started on.
|
call ale#test#RestoreDirectory()
|
||||||
silent! 'cd ' . fnameescape(b:path)
|
|
||||||
unlet! b:path
|
|
||||||
|
|
||||||
call ale#linter#Reset()
|
call ale#linter#Reset()
|
||||||
|
|
||||||
Execute(The rails_best_practices handler should parse JSON correctly):
|
Execute(The rails_best_practices handler should parse JSON correctly):
|
||||||
silent file! thing.rb
|
call ale#test#SetFilename('ruby_fixtures/valid_rails_app/app/models/thing.rb')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ [
|
\ [
|
||||||
@ -34,11 +29,11 @@ Execute(The rails_best_practices handler should parse JSON correctly):
|
|||||||
\ '{',
|
\ '{',
|
||||||
\ '"message": "use local variable",',
|
\ '"message": "use local variable",',
|
||||||
\ '"line_number": "5",',
|
\ '"line_number": "5",',
|
||||||
\ '"filename": "/testplugin/test/ruby_fixtures/valid_rails_app/app/models/thing.rb"',
|
\ '"filename": "' . g:dir . '/ruby_fixtures/valid_rails_app/app/models/thing.rb"',
|
||||||
\ '},{',
|
\ '},{',
|
||||||
\ '"message": "other advice",',
|
\ '"message": "other advice",',
|
||||||
\ '"line_number": "10",',
|
\ '"line_number": "10",',
|
||||||
\ '"filename": "/testplugin/test/ruby_fixtures/valid_rails_app/app/models/thing.rb"',
|
\ '"filename": "' . g:dir . '/ruby_fixtures/valid_rails_app/app/models/thing.rb"',
|
||||||
\ '}',
|
\ '}',
|
||||||
\ ']'
|
\ ']'
|
||||||
\ ])
|
\ ])
|
||||||
@ -48,3 +43,10 @@ Execute(The rails_best_practices handler should parse JSON correctly when there
|
|||||||
\ [],
|
\ [],
|
||||||
\ ale_linters#ruby#rails_best_practices#Handle(347, [
|
\ ale_linters#ruby#rails_best_practices#Handle(347, [
|
||||||
\ ])
|
\ ])
|
||||||
|
|
||||||
|
Execute(The rails_best_practices handler should handle garbage output):
|
||||||
|
AssertEqual
|
||||||
|
\ [],
|
||||||
|
\ ale_linters#ruby#rails_best_practices#Handle(347, [
|
||||||
|
\ 'No such command in 2.4.1 of ruby',
|
||||||
|
\ ])
|
||||||
|
@ -67,3 +67,10 @@ Execute(The reek handler should parse JSON correctly when there is no output fro
|
|||||||
\ [],
|
\ [],
|
||||||
\ ale_linters#ruby#reek#Handle(347, [
|
\ ale_linters#ruby#reek#Handle(347, [
|
||||||
\ ])
|
\ ])
|
||||||
|
|
||||||
|
Execute(The reek handler should handle garbage output):
|
||||||
|
AssertEqual
|
||||||
|
\ [],
|
||||||
|
\ ale_linters#ruby#reek#Handle(347, [
|
||||||
|
\ 'No such command in 2.4.1 of ruby',
|
||||||
|
\ ])
|
||||||
|
Loading…
Reference in New Issue
Block a user