Show warnings for `dart_analyze` linter (#4237)

This commit is contained in:
Gabriel Remus 2022-06-24 12:18:08 -03:00 committed by GitHub
parent 0e99519500
commit 4a0d669c0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 8 deletions

View File

@ -4,15 +4,16 @@
call ale#Set('dart_analyze_executable', 'dart') call ale#Set('dart_analyze_executable', 'dart')
function! ale_linters#dart#dart_analyze#Handle(buffer, lines) abort function! ale_linters#dart#dart_analyze#Handle(buffer, lines) abort
let l:pattern = '\v^ ([a-z]+) - (.+):(\d+):(\d+) - (.+) - (.+)$' let l:pattern = '\v([a-z]+) - (.+):(\d+):(\d+) - (.+) - (.+)$'
let l:output = [] let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern) for l:match in ale#util#GetMatches(a:lines, l:pattern)
let [l:type, l:filename, l:lnum, l:col, l:message, l:code] = l:match[1:6]
call add(l:output, { call add(l:output, {
\ 'type': l:match[1] is# 'error' ? 'E' : 'W', \ 'type': l:type is# 'error' ? 'E' : l:type is# 'info' ? 'I' : 'W',
\ 'text': l:match[6] . ': ' . l:match[5], \ 'text': l:code . ': ' . l:message,
\ 'lnum': str2nr(l:match[3]), \ 'lnum': str2nr(l:lnum),
\ 'col': str2nr(l:match[4]), \ 'col': str2nr(l:col),
\}) \})
endfor endfor
@ -22,7 +23,7 @@ endfunction
call ale#linter#Define('dart', { call ale#linter#Define('dart', {
\ 'name': 'dart_analyze', \ 'name': 'dart_analyze',
\ 'executable': {b -> ale#Var(b, 'dart_analyze_executable')}, \ 'executable': {b -> ale#Var(b, 'dart_analyze_executable')},
\ 'command': '%e analyze %s', \ 'command': '%e analyze --fatal-infos %s',
\ 'callback': 'ale_linters#dart#dart_analyze#Handle', \ 'callback': 'ale_linters#dart#dart_analyze#Handle',
\ 'lint_file': 1, \ 'lint_file': 1,
\}) \})

View File

@ -19,10 +19,17 @@ Execute(Basic problems should be parsed correctly):
\ 'lnum': 2, \ 'lnum': 2,
\ 'col': 16, \ 'col': 16,
\ }, \ },
\ {
\ 'type': 'I',
\ 'text': 'dead_code: Dead code. Try removing the code, or fixing the code before it so that it can be reached.',
\ 'lnum': 8,
\ 'col': 3,
\ },
\ ], \ ],
\ ale_linters#dart#dart_analyze#Handle(bufnr(''), [ \ ale_linters#dart#dart_analyze#Handle(bufnr(''), [
\ 'Analyzing main.dart...', \ 'Analyzing main.dart...',
\ ' error - main.dart:5:1 - Expected to find ''}'' - expected_token', \ ' error - main.dart:5:1 - Expected to find ''}'' - expected_token',
\ ' warning - main.dart:2:16 - A value of type ''String'' can''t be assigned to a variable of type ''int'' - invalid_assignment', \ 'warning - main.dart:2:16 - A value of type ''String'' can''t be assigned to a variable of type ''int'' - invalid_assignment',
\ '1 error and 1 warning found.', \ ' info - main.dart:8:3 - Dead code. Try removing the code, or fixing the code before it so that it can be reached. - dead_code',
\ '3 issues found.',
\ ]) \ ])