Break shared handlers up into their own files, and fix stylelint error handling

This commit is contained in:
w0rp 2017-04-24 22:27:18 +01:00
parent b4c0335ebc
commit a03121f5b0
44 changed files with 263 additions and 272 deletions

View File

@ -5,5 +5,5 @@ call ale#linter#Define('ansible', {
\ 'name': 'ansible',
\ 'executable': 'ansible',
\ 'command': 'ansible-lint -p %t',
\ 'callback': 'ale#handlers#HandlePEP8Format',
\ 'callback': 'ale#handlers#python#HandlePEP8Format',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('asciidoc', {
\ 'name': 'proselint',
\ 'executable': 'proselint',
\ 'command': 'proselint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -15,5 +15,5 @@ call ale#linter#Define('c', {
\ 'output_stream': 'both',
\ 'executable': 'cppcheck',
\ 'command_callback': 'ale_linters#c#cppcheck#GetCommand',
\ 'callback': 'ale#handlers#HandleCppCheckFormat',
\ 'callback': 'ale#handlers#cppcheck#HandleCppCheckFormat',
\})

View File

@ -20,5 +20,5 @@ call ale#linter#Define('cmake', {
\ 'name': 'cmakelint',
\ 'executable_callback': 'ale_linters#cmake#cmakelint#Executable',
\ 'command_callback': 'ale_linters#cmake#cmakelint#Command',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -15,5 +15,5 @@ call ale#linter#Define('cpp', {
\ 'output_stream': 'both',
\ 'executable': 'cppcheck',
\ 'command_callback': 'ale_linters#cpp#cppcheck#GetCommand',
\ 'callback': 'ale#handlers#HandleCppCheckFormat',
\ 'callback': 'ale#handlers#cppcheck#HandleCppCheckFormat',
\})

View File

@ -14,5 +14,5 @@ call ale#linter#Define('css', {
\ 'name': 'csslint',
\ 'executable': 'csslint',
\ 'command_callback': 'ale_linters#css#csslint#GetCommand',
\ 'callback': 'ale#handlers#HandleCSSLintFormat',
\ 'callback': 'ale#handlers#css#HandleCSSLintFormat',
\})

View File

@ -31,5 +31,5 @@ call ale#linter#Define('css', {
\ 'name': 'stylelint',
\ 'executable_callback': 'ale_linters#css#stylelint#GetExecutable',
\ 'command_callback': 'ale_linters#css#stylelint#GetCommand',
\ 'callback': 'ale#handlers#HandleStyleLintFormat',
\ 'callback': 'ale#handlers#css#HandleStyleLintFormat',
\})

View File

@ -6,5 +6,5 @@ call ale#linter#Define('go', {
\ 'output_stream': 'stderr',
\ 'executable': 'gofmt',
\ 'command': 'gofmt -e %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\ 'callback': 'ale#handlers#unix#HandleAsError',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('go', {
\ 'name': 'golint',
\ 'executable': 'golint',
\ 'command': 'golint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('go', {
\ 'name': 'gosimple',
\ 'executable': 'gosimple',
\ 'command': 'gosimple %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -6,5 +6,5 @@ call ale#linter#Define('go', {
\ 'output_stream': 'stderr',
\ 'executable': 'go',
\ 'command': 'go vet %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\ 'callback': 'ale#handlers#unix#HandleAsError',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('go', {
\ 'name': 'staticcheck',
\ 'executable': 'staticcheck',
\ 'command': 'staticcheck %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -6,7 +6,7 @@ call ale#linter#Define('haskell', {
\ 'output_stream': 'stderr',
\ 'executable': 'ghc',
\ 'command': 'ghc -fno-code -v0 %t',
\ 'callback': 'ale#handlers#HandleGhcFormat',
\ 'callback': 'ale#handlers#haskell#HandleGHCFormat',
\})
call ale#linter#Define('haskell', {
@ -14,5 +14,5 @@ call ale#linter#Define('haskell', {
\ 'output_stream': 'stderr',
\ 'executable': 'stack',
\ 'command': 'stack ghc -- -fno-code -v0 %t',
\ 'callback': 'ale#handlers#HandleGhcFormat',
\ 'callback': 'ale#handlers#haskell#HandleGHCFormat',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('haskell', {
\ 'name': 'hdevtools',
\ 'executable': 'hdevtools',
\ 'command': 'hdevtools check -g -Wall -p %s %t',
\ 'callback': 'ale#handlers#HandleGhcFormat',
\ 'callback': 'ale#handlers#haskell#HandleGHCFormat',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('help', {
\ 'name': 'proselint',
\ 'executable': 'proselint',
\ 'command': 'proselint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -28,5 +28,5 @@ call ale#linter#Define('html', {
\ 'name': 'htmlhint',
\ 'executable_callback': 'ale_linters#html#htmlhint#GetExecutable',
\ 'command_callback': 'ale_linters#html#htmlhint#GetCommand',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\ 'callback': 'ale#handlers#unix#HandleAsError',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('html', {
\ 'name': 'proselint',
\ 'executable': 'proselint',
\ 'command': 'proselint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('javascript', {
\ 'name': 'jscs',
\ 'executable': 'jscs',
\ 'command': 'jscs -r unix -n -',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\ 'callback': 'ale#handlers#unix#HandleAsError',
\})

View File

@ -43,5 +43,5 @@ call ale#linter#Define('javascript', {
\ 'name': 'jshint',
\ 'executable_callback': 'ale_linters#javascript#jshint#GetExecutable',
\ 'command_callback': 'ale_linters#javascript#jshint#GetCommand',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\ 'callback': 'ale#handlers#unix#HandleAsError',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('markdown', {
\ 'name': 'proselint',
\ 'executable': 'proselint',
\ 'command': 'proselint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('nroff', {
\ 'name': 'proselint',
\ 'executable': 'proselint',
\ 'command': 'proselint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('pod', {
\ 'name': 'proselint',
\ 'executable': 'proselint',
\ 'command': 'proselint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -6,5 +6,5 @@ call ale#linter#Define('pug', {
\ 'executable': 'pug-lint',
\ 'output_stream': 'stderr',
\ 'command': 'pug-lint -r inline %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\ 'callback': 'ale#handlers#unix#HandleAsError',
\})

View File

@ -6,5 +6,5 @@ call ale#linter#Define('pyrex', {
\ 'output_stream': 'stderr',
\ 'executable': 'cython',
\ 'command': 'cython --warning-extra -o ' . g:ale#util#nul_file . ' %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\ 'callback': 'ale#handlers#unix#HandleAsError',
\})

View File

@ -75,5 +75,5 @@ call ale#linter#Define('python', {
\ {'callback': 'ale_linters#python#flake8#VersionCheck'},
\ {'callback': 'ale_linters#python#flake8#GetCommand'},
\ ],
\ 'callback': 'ale#handlers#HandlePEP8Format',
\ 'callback': 'ale#handlers#python#HandlePEP8Format',
\})

View File

@ -22,5 +22,5 @@ call ale#linter#Define('python', {
\ 'name': 'pylint',
\ 'executable_callback': 'ale_linters#python#pylint#GetExecutable',
\ 'command_callback': 'ale_linters#python#pylint#GetCommand',
\ 'callback': 'ale#handlers#HandlePEP8Format',
\ 'callback': 'ale#handlers#python#HandlePEP8Format',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('rst', {
\ 'name': 'proselint',
\ 'executable': 'proselint',
\ 'command': 'proselint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -4,5 +4,5 @@ call ale#linter#Define('sass', {
\ 'name': 'sasslint',
\ 'executable': 'sass-lint',
\ 'command': 'sass-lint -v -q -f compact %t',
\ 'callback': 'ale#handlers#HandleCSSLintFormat',
\ 'callback': 'ale#handlers#css#HandleCSSLintFormat',
\})

View File

@ -27,5 +27,5 @@ call ale#linter#Define('sass', {
\ 'name': 'stylelint',
\ 'executable_callback': 'ale_linters#sass#stylelint#GetExecutable',
\ 'command_callback': 'ale_linters#sass#stylelint#GetCommand',
\ 'callback': 'ale#handlers#HandleStyleLintFormat',
\ 'callback': 'ale#handlers#css#HandleStyleLintFormat',
\})

View File

@ -4,5 +4,5 @@ call ale#linter#Define('scss', {
\ 'name': 'sasslint',
\ 'executable': 'sass-lint',
\ 'command': 'sass-lint -v -q -f compact %t',
\ 'callback': 'ale#handlers#HandleCSSLintFormat',
\ 'callback': 'ale#handlers#css#HandleCSSLintFormat',
\})

View File

@ -27,5 +27,5 @@ call ale#linter#Define('scss', {
\ 'name': 'stylelint',
\ 'executable_callback': 'ale_linters#scss#stylelint#GetExecutable',
\ 'command_callback': 'ale_linters#scss#stylelint#GetCommand',
\ 'callback': 'ale#handlers#HandleStyleLintFormat',
\ 'callback': 'ale#handlers#css#HandleStyleLintFormat',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('tex', {
\ 'name': 'proselint',
\ 'executable': 'proselint',
\ 'command': 'proselint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('texinfo', {
\ 'name': 'proselint',
\ 'executable': 'proselint',
\ 'command': 'proselint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('text', {
\ 'name': 'proselint',
\ 'executable': 'proselint',
\ 'command': 'proselint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -5,5 +5,5 @@ call ale#linter#Define('xhtml', {
\ 'name': 'proselint',
\ 'executable': 'proselint',
\ 'command': 'proselint %t',
\ 'callback': 'ale#handlers#HandleUnixFormatAsWarning',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -1,226 +0,0 @@
scriptencoding utf-8
" 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.
let s:path_pattern = '[a-zA-Z]\?\\\?:\?[[:alnum:]/\.\-_]\+'
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"
let l:pattern = '^' . s:path_pattern . ':\(\d\+\):\?\(\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, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:match[3],
\ 'type': a:type,
\})
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
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, {
\ 'lnum': l:match[1] + 0,
\ 'col': 0,
\ 'text': l:match[3] . ' (' . l:match[2] . ')',
\ 'type': l:match[2] ==# 'error' ? 'E' : 'W',
\})
endfor
return l:output
endfunction
function! ale#handlers#HandlePEP8Format(buffer, lines) abort
" 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
if l:code ==# 'I0011'
" Skip 'Locally disabling' message
continue
endif
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:code . ': ' . l:match[5],
\ 'type': l:match[4] ==# 'E' ? 'E' : 'W',
\})
endfor
return l:output
endfunction
function! ale#handlers#HandleCSSLintFormat(buffer, lines) abort
" 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.
let l:pattern = '^.*: line \(\d\+\), col \(\d\+\), \(Error\|Warning\) - \(.\+\) (\([^)]\+\))$'
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:text = l:match[4]
let l:type = l:match[3]
let l:errorGroup = l:match[5]
" Put the error group at the front, so we can see what kind of error
" it is on small echo lines.
let l:text = '(' . l:errorGroup . ') ' . l:text
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:text,
\ 'type': l:type ==# 'Warning' ? 'W' : 'E',
\})
endfor
return l:output
endfunction
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
let l:type = l:match[3] ==# '✖' ? 'E' : 'W'
let l:text = l:match[4] . '[' . l:match[5] . ']'
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:text,
\ 'type': l:type,
\})
endfor
return l:output
endfunction
function! ale#handlers#HandleGhcFormat(buffer, lines) abort
" Look for lines like the following.
"
"Appoint/Lib.hs:8:1: warning:
"Appoint/Lib.hs:8:1:
let l:pattern = '^[^:]\+:\(\d\+\):\(\d\+\):\(.*\)\?$'
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
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]
endif
let l:type = l:type ==# '' ? 'E' : toupper(l:type[0])
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:text,
\ 'type': l:type,
\})
endfor
return l:output
endfunction

View File

@ -0,0 +1,20 @@
" Description: Handle errors for cppcheck.
function! ale#handlers#cppcheck#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:match in ale#util#GetMatches(a:lines, l:pattern)
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': 0,
\ 'text': l:match[3] . ' (' . l:match[2] . ')',
\ 'type': l:match[2] ==# 'error' ? 'E' : 'W',
\})
endfor
return l:output
endfunction

View File

@ -0,0 +1,55 @@
scriptencoding utf-8
" Author: w0rp <devw0rp@gmail.com>
" Description: Error handling for CSS linters.
function! ale#handlers#css#HandleCSSLintFormat(buffer, lines) abort
" 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.
let l:pattern = '^.*: line \(\d\+\), col \(\d\+\), \(Error\|Warning\) - \(.\+\) (\([^)]\+\))$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
let l:text = l:match[4]
let l:type = l:match[3]
let l:errorGroup = l:match[5]
" Put the error group at the front, so we can see what kind of error
" it is on small echo lines.
let l:text = '(' . l:errorGroup . ') ' . l:text
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:text,
\ 'type': l:type ==# 'Warning' ? 'W' : 'E',
\})
endfor
return l:output
endfunction
function! ale#handlers#css#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 = '\v^.* (\d+):(\d+) \s+(\S+)\s+ (.*[^ ])\s+([^ ]+)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'type': l:match[3] ==# '✖' ? 'E' : 'W',
\ 'text': l:match[4] . ' [' . l:match[5] . ']',
\})
endfor
return l:output
endfunction

View File

@ -0,0 +1,54 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Error handling for the format GHC outputs.
function! ale#handlers#haskell#HandleGHCFormat(buffer, lines) abort
" Look for lines like the following.
"
"Appoint/Lib.hs:8:1: warning:
"Appoint/Lib.hs:8:1:
let l:pattern = '^[^:]\+:\(\d\+\):\(\d\+\):\(.*\)\?$'
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
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]
endif
let l:type = l:type ==# '' ? 'E' : toupper(l:type[0])
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:text,
\ 'type': l:type,
\})
endfor
return l:output
endfunction

View File

@ -0,0 +1,39 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Error handling for flake8, etc.
let s:path_pattern = '[a-zA-Z]\?\\\?:\?[[:alnum:]/\.\-_]\+'
function! ale#handlers#python#HandlePEP8Format(buffer, lines) abort
" 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:match in ale#util#GetMatches(a:lines, l:pattern)
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
if l:code ==# 'I0011'
" Skip 'Locally disabling' message
continue
endif
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:code . ': ' . l:match[5],
\ 'type': l:match[4] ==# 'E' ? 'E' : 'W',
\})
endfor
return l:output
endfunction

View File

@ -0,0 +1,28 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Error handling for errors in a Unix format.
let s:path_pattern = '[a-zA-Z]\?\\\?:\?[[:alnum:]/\.\-_]\+'
function! s:HandleUnixFormat(buffer, lines, type) abort
let l:pattern = '^' . s:path_pattern . ':\(\d\+\):\?\(\d\+\)\?:\? \?\(.\+\)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:match[3],
\ 'type': a:type,
\})
endfor
return l:output
endfunction
function! ale#handlers#unix#HandleAsError(buffer, lines) abort
return s:HandleUnixFormat(a:buffer, a:lines, 'E')
endfunction
function! ale#handlers#unix#HandleAsWarning(buffer, lines) abort
return s:HandleUnixFormat(a:buffer, a:lines, 'W')
endfunction

View File

@ -14,7 +14,7 @@ Execute(HandleCSSLintFormat should handle CSS errors):
\ 'text': "(known-properties) Expected ... but found 'wat'.",
\ },
\ ],
\ ale#handlers#HandleCSSLintFormat(42, [
\ ale#handlers#css#HandleCSSLintFormat(42, [
\ 'something.css: line 2, col 1, Error - Expected RBRACE at line 2, col 1. (errors)',
\ "something.css: line 2, col 5, Warning - Expected ... but found 'wat'. (known-properties)",
\ ])
@ -35,7 +35,7 @@ Execute (HandlePEP8Format should handle the correct lines of output):
\ 'text': "EANSIBLE0002: Trailing whitespace",
\ },
\ ],
\ ale#handlers#HandlePEP8Format(42, [
\ ale#handlers#python#HandlePEP8Format(42, [
\ "stdin:6:6: E111 indentation is not a multiple of four",
\ "test.yml:35: [EANSIBLE0002] Trailing whitespace",
\ ])
@ -83,7 +83,7 @@ Execute (HandleUnixFormatAsError should handle some example lines of output):
\ 'text': '".b" is not a valid class name. Class names must begin with "-", "_" or a letter and can only contain "_", "-", a-z and 0-9.',
\ },
\ ],
\ ale#handlers#HandleUnixFormatAsError(42, [
\ ale#handlers#unix#HandleAsError(42, [
\ '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)',
\ 'test.pug:1:1 ".b" is not a valid class name. Class names must begin with "-", "_" or a letter and can only contain "_", "-", a-z and 0-9.',
@ -105,7 +105,7 @@ Execute (HandleUnixFormatAsError should handle lines with no space after the col
\ 'text': 'bar',
\ },
\ ],
\ ale#handlers#HandleUnixFormatAsError(42, [
\ ale#handlers#unix#HandleAsError(42, [
\ 'some_file.xyz:27:foo',
\ 'some_file.xyz:53:10:bar',
\ ])
@ -126,7 +126,7 @@ Execute (HandleUnixFormatAsWarning should handle some example lines of output):
\ 'text': '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)',
\ },
\ ],
\ ale#handlers#HandleUnixFormatAsWarning(42, [
\ ale#handlers#unix#HandleAsWarning(42, [
\ '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)',
\ ])
@ -147,7 +147,7 @@ Execute (Unix format functions should handle Windows paths):
\ 'text': 'foo',
\ },
\ ],
\ ale#handlers#HandleUnixFormatAsError(42, [
\ ale#handlers#unix#HandleAsError(42, [
\ 'C:\Users\w0rp\AppData\Local\Temp\Xyz123.go:27: foo',
\ 'C:\Users\w0rp\AppData\Local\Temp\Xyz123.go:53:10: foo',
\ ])
@ -168,7 +168,7 @@ Execute (HandleCppCheckFormat should handle some example lines of output):
\ 'text': 'Array a[10] accessed at index 10, which is out of bounds. (error)',
\ },
\ ],
\ ale#handlers#HandleCppCheckFormat(42, [
\ ale#handlers#cppcheck#HandleCppCheckFormat(42, [
\ '[/tmp/test.c:5]: (style) Variable a is assigned a value that is never used.',
\ '[/tmp/test.c:12]: (error) Array a[10] accessed at index 10, which is out of bounds.'
\ ])

View File

@ -8,7 +8,7 @@ Execute(The ghc handler should handle hdevtools output):
\ 'text': '• Couldnt match type a -> T.Text with T.Text Expected type: [T.Text]',
\ },
\ ],
\ ale#handlers#HandleGhcFormat(12, [
\ ale#handlers#haskell#HandleGHCFormat(12, [
\ '/path/to/foo.hs:147:62: warning:',
\ '• Couldnt match type a -> T.Text with T.Text',
\ ' Expected type: [T.Text]',
@ -30,7 +30,7 @@ Execute(The ghc handler should handle ghc 8 output):
\ 'text': ' Failed to load interface for GitHub.Endpoints.PullRequests Use -v to see a list of the files searched for.',
\ },
\ ],
\ ale#handlers#HandleGhcFormat(47, [
\ ale#handlers#haskell#HandleGHCFormat(47, [
\ '',
\ 'src/Appoint/Lib.hs:6:1: error:',
\ ' Failed to load interface for GitHub.Data',
@ -51,7 +51,7 @@ Execute(The ghc handler should handle ghc 7 output):
\ 'text': ' parse error (possibly incorrect indentation or mismatched brackets)',
\ },
\ ],
\ ale#handlers#HandleGhcFormat(47, [
\ ale#handlers#haskell#HandleGHCFormat(47, [
\ 'src/Main.hs:168:1:',
\ ' parse error (possibly incorrect indentation or mismatched brackets)',
\ ])

View File

@ -0,0 +1,21 @@
Execute (stylelint errors should be handled correctly):
AssertEqual
\ [
\ {
\ 'lnum': 108,
\ 'col': 10,
\ 'type': 'E',
\ 'text': 'Unexpected leading zero [number-leading-zero]',
\ },
\ {
\ 'lnum': 116,
\ 'col': 20,
\ 'type': 'E',
\ 'text': 'Expected a trailing semicolon [declaration-block-trailing-semicolon]',
\ },
\ ],
\ ale#handlers#css#HandleStyleLintFormat(42, [
\ 'src/main.css',
\ ' 108:10 ✖ Unexpected leading zero number-leading-zero',
\ ' 116:20 ✖ Expected a trailing semicolon declaration-block-trailing-semicolon',
\ ])