2016-10-05 10:35:09 +00:00
scriptencoding utf -8
2016-10-03 12:18:27 +00:00
" Author: w0rp <devw0rp@gmail.com>
" Description: This file defines some standard error format handlers. Any
" linter which outputs warnings and errors in a format accepted by one of
" these functions can simply use one of these pre-defined error handlers.
2016-10-27 06:24:32 +00:00
let s :path_pattern = '[a-zA-Z]\?\\\?:\?[[:alnum:]/\.\-_]\+'
2016-10-11 13:54:41 +00:00
2016-10-11 12:48:42 +00:00
function ! s :HandleUnixFormat ( buffer , lines , type ) abort
" Matches patterns line the following:
"
" file.go:27: missing argument for Printf("%s"): format reads arg 2, have only 1 args
" file.go:53:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
" file.go:5:2: expected declaration, found 'STRING' "log"
2017-02-11 18:49:12 +00:00
let l :pattern = '^' . s :path_pattern . ':\(\d\+\):\?\(\d\+\)\?:\? \(.\+\)$'
2016-10-11 12:48:42 +00:00
let l :output = []
for l :line in a :lines
let l :match = matchlist ( l :line , l :pattern )
if len ( l :match ) = = 0
continue
endif
" vcol is Needed to indicate that the column is a character.
call add ( l :output , {
\ 'bufnr' : a :buffer ,
\ 'lnum' : l :match [1 ] + 0 ,
\ 'vcol' : 0 ,
\ 'col' : l :match [2 ] + 0 ,
\ 'text' : l :match [3 ],
\ 'type' : a :type ,
\ 'nr' : -1 ,
\})
endfor
return l :output
endfunction
function ! ale #handlers #HandleUnixFormatAsError ( buffer , lines ) abort
return s :HandleUnixFormat ( a :buffer , a :lines , 'E' )
endfunction
function ! ale #handlers #HandleUnixFormatAsWarning ( buffer , lines ) abort
return s :HandleUnixFormat ( a :buffer , a :lines , 'W' )
endfunction
First pass at optimizing ale to autoload (#80)
* First pass at optimizing ale to autoload
First off, the structure/function names should be revised a bit,
but I will wait for @w0rp's input before unifying the naming style.
Second off, the docs probably need some more work, I just did some
simple find-and-replace work.
With that said, this pull brings major performance gains for ale. On my
slowest system, fully loading ale and all its code takes around 150ms.
I have moved all of ale's autoload-able code to autoload/, and in
addition, implemented lazy-loading of linters. This brings load time on
that same system down to 5ms.
The only downside of lazy loading is that `g:ale_linters` cannot be
changed at runtime; however, it also speeds up performance at runtime by
simplfying the logic greatly.
Please let me know what you think!
Closes #59
* Address Travis/Vint errors
For some reason, ale isn't running vint for me...
* Incorporate feedback, make fixes
Lazy-loading logic is much improved.
* Add header comments; remove incorrect workaround
* Remove unneeded plugin guards
* Fix lazy-loading linter logic
Set the wrong variable....
* Fix capitialization
2016-10-10 18:51:29 +00:00
function ! ale #handlers #HandleGCCFormat ( buffer , lines ) abort
2016-10-03 12:18:27 +00:00
" Look for lines like the following.
"
" <stdin>:8:5: warning: conversion lacks type at end of format [-Wformat=]
" <stdin>:10:27: error: invalid operands to binary - (have ‘ int’ and ‘ char *’ )
" -:189:7: note: $/${} is unnecessary on arithmetic variables. [SC2004]
2016-10-10 23:00:09 +00:00
let l :pattern = '^.\+:\(\d\+\):\(\d\+\): \([^:]\+\): \(.\+\)$'
let l :output = []
2016-10-03 12:18:27 +00:00
2016-10-10 23:00:09 +00:00
for l :line in a :lines
let l :match = matchlist ( l :line , l :pattern )
2016-10-03 12:18:27 +00:00
if len ( l :match ) = = 0
continue
endif
2016-10-10 23:00:09 +00:00
call add ( l :output , {
2016-10-03 12:18:27 +00:00
\ 'bufnr' : a :buffer ,
\ 'lnum' : l :match [1 ] + 0 ,
\ 'vcol' : 0 ,
\ 'col' : l :match [2 ] + 0 ,
\ 'text' : l :match [4 ],
2016-12-07 23:14:23 +00:00
\ 'type' : l :match [3 ] = ~ # 'error' ? 'E' : 'W' ,
2016-10-03 12:18:27 +00:00
\ 'nr' : -1 ,
\})
endfor
2016-10-10 23:00:09 +00:00
return l :output
2016-10-03 12:18:27 +00:00
endfunction
2016-10-03 22:24:18 +00:00
2016-10-20 11:30:45 +00:00
function ! ale #handlers #HandleCppCheckFormat ( buffer , lines ) abort
" Look for lines like the following.
"
" [test.cpp:5]: (error) Array 'a[10]' accessed at index 10, which is out of bounds
let l :pattern = '^\[.\{-}:\(\d\+\)\]: (\(.\{-}\)) \(.\+\)'
let l :output = []
for l :line in a :lines
let l :match = matchlist ( l :line , l :pattern )
if len ( l :match ) = = 0
continue
endif
call add ( l :output , {
\ 'bufnr' : a :buffer ,
\ 'lnum' : l :match [1 ] + 0 ,
\ 'vcol' : 0 ,
\ 'col' : 0 ,
\ 'text' : l :match [3 ] . ' (' . l :match [2 ] . ')' ,
\ 'type' : l :match [2 ] = = # 'error' ? 'E' : 'W' ,
\ 'nr' : -1 ,
\})
endfor
2016-10-21 03:52:25 +00:00
return l :output
2016-10-20 11:30:45 +00:00
endfunction
2016-10-21 03:52:25 +00:00
function ! ale #handlers #HandlePEP8Format ( buffer , lines ) abort
2016-10-20 14:23:23 +00:00
" Matches patterns line the following:
"
" Matches patterns line the following:
"
" stdin:6:6: E111 indentation is not a multiple of four
" test.yml:35: [EANSIBLE0002] Trailing whitespace
let l :pattern = '^' . s :path_pattern . ':\(\d\+\):\?\(\d\+\)\?: \[\?\(\([[:alpha:]]\)[[:alnum:]]\+\)\]\? \(.*\)$'
let l :output = []
for l :line in a :lines
let l :match = matchlist ( l :line , l :pattern )
if len ( l :match ) = = 0
continue
endif
let l :code = l :match [3 ]
if ( l :code = = # 'W291' | | l :code = = # 'W293' | | l :code = = # 'EANSIBLE002' )
\ && ! g :ale_warn_about_trailing_whitespace
" Skip warnings for trailing whitespace if the option is off.
continue
endif
2016-12-07 22:50:34 +00:00
if l :code = = # 'I0011'
" Skip 'Locally disabling' message
continue
endif
2016-10-20 14:23:23 +00:00
call add ( l :output , {
\ 'bufnr' : a :buffer ,
\ 'lnum' : l :match [1 ] + 0 ,
\ 'vcol' : 0 ,
\ 'col' : l :match [2 ] + 0 ,
\ 'text' : l :code . ': ' . l :match [5 ],
\ 'type' : l :match [4 ] = = # 'E' ? 'E' : 'W' ,
\ 'nr' : -1 ,
\})
endfor
return l :output
endfunction
2016-10-20 11:30:45 +00:00
First pass at optimizing ale to autoload (#80)
* First pass at optimizing ale to autoload
First off, the structure/function names should be revised a bit,
but I will wait for @w0rp's input before unifying the naming style.
Second off, the docs probably need some more work, I just did some
simple find-and-replace work.
With that said, this pull brings major performance gains for ale. On my
slowest system, fully loading ale and all its code takes around 150ms.
I have moved all of ale's autoload-able code to autoload/, and in
addition, implemented lazy-loading of linters. This brings load time on
that same system down to 5ms.
The only downside of lazy loading is that `g:ale_linters` cannot be
changed at runtime; however, it also speeds up performance at runtime by
simplfying the logic greatly.
Please let me know what you think!
Closes #59
* Address Travis/Vint errors
For some reason, ale isn't running vint for me...
* Incorporate feedback, make fixes
Lazy-loading logic is much improved.
* Add header comments; remove incorrect workaround
* Remove unneeded plugin guards
* Fix lazy-loading linter logic
Set the wrong variable....
* Fix capitialization
2016-10-10 18:51:29 +00:00
function ! ale #handlers #HandleCSSLintFormat ( buffer , lines ) abort
2016-10-03 22:24:18 +00:00
" Matches patterns line the following:
"
" something.css: line 2, col 1, Error - Expected RBRACE at line 2, col 1. (errors)
" something.css: line 2, col 5, Warning - Expected (inline | block | list-item | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | grid | inline-grid | run-in | ruby | ruby-base | ruby-text | ruby-base-container | ruby-text-container | contents | none | -moz-box | -moz-inline-block | -moz-inline-box | -moz-inline-grid | -moz-inline-stack | -moz-inline-table | -moz-grid | -moz-grid-group | -moz-grid-line | -moz-groupbox | -moz-deck | -moz-popup | -moz-stack | -moz-marker | -webkit-box | -webkit-inline-box | -ms-flexbox | -ms-inline-flexbox | flex | -webkit-flex | inline-flex | -webkit-inline-flex) but found 'wat'. (known-properties)
"
" These errors can be very massive, so the type will be moved to the front
" so you can actually read the error type.
2016-10-10 23:00:09 +00:00
let l :pattern = '^.*: line \(\d\+\), col \(\d\+\), \(Error\|Warning\) - \(.\+\) (\([^)]\+\))$'
let l :output = []
2016-10-03 22:24:18 +00:00
2016-10-10 23:00:09 +00:00
for l :line in a :lines
let l :match = matchlist ( l :line , l :pattern )
2016-10-03 22:24:18 +00:00
if len ( l :match ) = = 0
continue
endif
2016-10-10 23:00:09 +00:00
let l :text = l :match [4 ]
let l :type = l :match [3 ]
let l :errorGroup = l :match [5 ]
2016-10-03 22:24:18 +00:00
" Put the error group at the front, so we can see what kind of error
" it is on small echo lines.
2016-10-10 23:00:09 +00:00
let l :text = '(' . l :errorGroup . ') ' . l :text
2016-10-03 22:24:18 +00:00
" vcol is Needed to indicate that the column is a character.
2016-10-10 23:00:09 +00:00
call add ( l :output , {
2016-10-03 22:24:18 +00:00
\ 'bufnr' : a :buffer ,
2016-10-04 17:17:02 +00:00
\ 'lnum' : l :match [1 ] + 0 ,
2016-10-03 22:24:18 +00:00
\ 'vcol' : 0 ,
\ 'col' : l :match [2 ] + 0 ,
2016-10-10 23:00:09 +00:00
\ 'text' : l :text ,
\ 'type' : l :type = = # 'Warning' ? 'W' : 'E' ,
2016-10-03 22:24:18 +00:00
\ 'nr' : -1 ,
\})
endfor
2016-10-10 23:00:09 +00:00
return l :output
2016-10-03 22:24:18 +00:00
endfunction
2016-12-06 13:14:14 +00:00
function ! ale #handlers #HandleStyleLintFormat ( buffer , lines ) abort
" Matches patterns line the following:
"
" src/main.css
" 108:10 ✖ Unexpected leading zero number-leading-zero
" 116:20 ✖ Expected a trailing semicolon declaration-block-trailing-semicolon
let l :pattern = '^.* \(\d\+\):\(\d\+\) \s\+\(\S\+\)\s\+ \(\u.\+\) \(.\+\)$'
let l :output = []
for l :line in a :lines
let l :match = matchlist ( l :line , l :pattern )
if len ( l :match ) = = 0
continue
endif
2016-12-22 11:39:01 +00:00
let l :type = l :match [3 ] = = # '✖' ? 'E' : 'W'
let l :text = l :match [4 ] . '[' . l :match [5 ] . ']'
2016-12-06 13:14:14 +00:00
" vcol is Needed to indicate that the column is a character.
call add ( l :output , {
\ 'bufnr' : a :buffer ,
\ 'lnum' : l :match [1 ] + 0 ,
\ 'vcol' : 0 ,
\ 'col' : l :match [2 ] + 0 ,
\ 'text' : l :text ,
2016-12-22 11:39:01 +00:00
\ 'type' : l :type ,
2016-12-06 13:14:14 +00:00
\ 'nr' : -1 ,
\})
endfor
return l :output
endfunction
2017-02-14 22:47:53 +00:00
function ! ale #handlers #HandleGhcFormat ( buffer , lines ) abort
" Look for lines like the following.
"
2017-02-14 22:47:53 +00:00
"Appoint/Lib.hs:8:1: warning:
"Appoint/Lib.hs:8:1:
let l :pattern = '^[^:]\+:\(\d\+\):\(\d\+\):\(.*\)\?$'
2017-02-14 22:47:53 +00:00
let l :output = []
let l :corrected_lines = []
for l :line in a :lines
if len ( matchlist ( l :line , l :pattern ) ) > 0
call add ( l :corrected_lines , l :line )
elseif l :line = = # ''
call add ( l :corrected_lines , l :line )
else
if len ( l :corrected_lines ) > 0
let l :line = substitute ( l :line , '\v^\s+' , ' ' , '' )
let l :corrected_lines [-1 ] .= l :line
endif
endif
endfor
for l :line in l :corrected_lines
let l :match = matchlist ( l :line , l :pattern )
if len ( l :match ) = = 0
continue
endif
2017-02-14 22:47:53 +00:00
let l :errors = matchlist ( l :match [3 ], '\(warning:\|error:\)\(.*\)' )
if len ( l :errors ) > 0
let l :type = l :errors [1 ]
let l :text = l :errors [2 ]
else
let l :type = ''
let l :text = l :match [3 ]
2017-02-21 11:50:59 +00:00
endif
2017-02-14 22:47:53 +00:00
let l :type = l :type = = # '' ? 'E' : toupper ( l :type [0 ])
2017-02-14 22:47:53 +00:00
call add ( l :output , {
\ 'bufnr' : a :buffer ,
\ 'lnum' : l :match [1 ] + 0 ,
\ 'vcol' : 0 ,
\ 'col' : l :match [2 ] + 0 ,
2017-02-14 22:47:53 +00:00
\ 'text' : l :text ,
\ 'type' : l :type ,
2017-02-14 22:47:53 +00:00
\ 'nr' : -1 ,
\})
endfor
return l :output
endfunction