1
0
mirror of https://github.com/amix/vimrc synced 2025-06-16 09:35:01 +08:00

Removed syntastic and replaced it with ale

Read more here:
https://github.com/w0rp/ale
This commit is contained in:
Amir Salihefendic
2018-03-31 11:55:20 -03:00
parent 37297ddae6
commit 7c643a2d9c
679 changed files with 23508 additions and 27895 deletions

View File

@ -0,0 +1,146 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: flake8 for python files
let g:ale_python_flake8_executable =
\ get(g:, 'ale_python_flake8_executable', 'flake8')
" Support an old setting as a fallback.
let s:default_options = get(g:, 'ale_python_flake8_args', '')
let g:ale_python_flake8_options =
\ get(g:, 'ale_python_flake8_options', s:default_options)
let g:ale_python_flake8_use_global = get(g:, 'ale_python_flake8_use_global', 0)
function! s:UsingModule(buffer) abort
return ale#Var(a:buffer, 'python_flake8_options') =~# ' *-m flake8'
endfunction
function! ale_linters#python#flake8#GetExecutable(buffer) abort
if !s:UsingModule(a:buffer)
return ale#python#FindExecutable(a:buffer, 'python_flake8', ['flake8'])
endif
return ale#Var(a:buffer, 'python_flake8_executable')
endfunction
function! ale_linters#python#flake8#VersionCheck(buffer) abort
let l:executable = ale_linters#python#flake8#GetExecutable(a:buffer)
" If we have previously stored the version number in a cache, then
" don't look it up again.
if ale#semver#HasVersion(l:executable)
" Returning an empty string skips this command.
return ''
endif
let l:executable = ale#Escape(l:executable)
let l:module_string = s:UsingModule(a:buffer) ? ' -m flake8' : ''
return l:executable . l:module_string . ' --version'
endfunction
function! ale_linters#python#flake8#GetCommand(buffer, version_output) abort
let l:executable = ale_linters#python#flake8#GetExecutable(a:buffer)
let l:version = ale#semver#GetVersion(l:executable, a:version_output)
" Only include the --stdin-display-name argument if we can parse the
" flake8 version, and it is recent enough to support it.
let l:display_name_args = ale#semver#GTE(l:version, [3, 0, 0])
\ ? ' --stdin-display-name %s'
\ : ''
let l:options = ale#Var(a:buffer, 'python_flake8_options')
return ale#Escape(l:executable)
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' --format=default'
\ . l:display_name_args . ' -'
endfunction
let s:end_col_pattern_map = {
\ 'F405': '\(.\+\) may be undefined',
\ 'F821': 'undefined name ''\([^'']\+\)''',
\ 'F999': '^''\([^'']\+\)''',
\ 'F841': 'local variable ''\([^'']\+\)''',
\}
function! ale_linters#python#flake8#Handle(buffer, lines) abort
for l:line in a:lines[:10]
if match(l:line, '^Traceback') >= 0
return [{
\ 'lnum': 1,
\ 'text': 'An exception was thrown. See :ALEDetail',
\ 'detail': join(a:lines, "\n"),
\}]
endif
endfor
" Matches patterns line the following:
"
" Matches patterns line the following:
"
" stdin:6:6: E111 indentation is not a multiple of four
let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):?(\d+)?: ([[:alnum:]]+) (.*)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
let l:code = l:match[3]
if (l:code is# 'W291' || l:code is# 'W293')
\ && !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
" Skip warnings for trailing whitespace if the option is off.
continue
endif
if l:code is# 'W391'
\&& !ale#Var(a:buffer, 'warn_about_trailing_blank_lines')
" Skip warnings for trailing blank lines if the option is off
continue
endif
let l:item = {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:match[4],
\ 'code': l:code,
\ 'type': 'W',
\}
if l:code[:0] is# 'F'
if l:code isnot# 'F401'
let l:item.type = 'E'
endif
elseif l:code[:0] is# 'E'
let l:item.type = 'E'
if l:code isnot# 'E999' && l:code isnot# 'E112'
let l:item.sub_type = 'style'
endif
elseif l:code[:0] is# 'W'
let l:item.sub_type = 'style'
endif
let l:end_col_pattern = get(s:end_col_pattern_map, l:code, '')
if !empty(l:end_col_pattern)
let l:end_col_match = matchlist(l:match[4], l:end_col_pattern)
if !empty(l:end_col_match)
let l:item.end_col = l:item.col + len(l:end_col_match[1]) - 1
endif
endif
call add(l:output, l:item)
endfor
return l:output
endfunction
call ale#linter#Define('python', {
\ 'name': 'flake8',
\ 'executable_callback': 'ale_linters#python#flake8#GetExecutable',
\ 'command_chain': [
\ {'callback': 'ale_linters#python#flake8#VersionCheck'},
\ {'callback': 'ale_linters#python#flake8#GetCommand', 'output_stream': 'both'},
\ ],
\ 'callback': 'ale_linters#python#flake8#Handle',
\})

View File

@ -0,0 +1,71 @@
" Author: Keith Smiley <k@keith.so>, w0rp <devw0rp@gmail.com>
" Description: mypy support for optional python typechecking
call ale#Set('python_mypy_executable', 'mypy')
call ale#Set('python_mypy_ignore_invalid_syntax', 0)
call ale#Set('python_mypy_options', '')
call ale#Set('python_mypy_use_global', 0)
function! ale_linters#python#mypy#GetExecutable(buffer) abort
return ale#python#FindExecutable(a:buffer, 'python_mypy', ['mypy'])
endfunction
" The directory to change to before running mypy
function! s:GetDir(buffer) abort
let l:project_root = ale#python#FindProjectRoot(a:buffer)
return !empty(l:project_root)
\ ? l:project_root
\ : expand('#' . a:buffer . ':p:h')
endfunction
function! ale_linters#python#mypy#GetCommand(buffer) abort
let l:dir = s:GetDir(a:buffer)
let l:executable = ale_linters#python#mypy#GetExecutable(a:buffer)
" We have to always switch to an explicit directory for a command so
" we can know with certainty the base path for the 'filename' keys below.
return ale#path#CdString(l:dir)
\ . ale#Escape(l:executable)
\ . ' --show-column-numbers '
\ . ale#Var(a:buffer, 'python_mypy_options')
\ . ' --shadow-file %s %t %s'
endfunction
function! ale_linters#python#mypy#Handle(buffer, lines) abort
let l:dir = s:GetDir(a:buffer)
" Look for lines like the following:
"
" file.py:4: error: No library stub file for module 'django.db'
"
" Lines like these should be ignored below:
"
" file.py:4: note: (Stub files are from https://github.com/python/typeshed)
let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):?(\d+)?: (error|warning): (.+)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
" Skip invalid syntax errors if the option is on.
if l:match[5] is# 'invalid syntax'
\&& ale#Var(a:buffer, 'python_mypy_ignore_invalid_syntax')
continue
endif
call add(l:output, {
\ 'filename': ale#path#GetAbsPath(l:dir, l:match[1]),
\ 'lnum': l:match[2] + 0,
\ 'col': l:match[3] + 0,
\ 'type': l:match[4] is# 'error' ? 'E' : 'W',
\ 'text': l:match[5],
\})
endfor
return l:output
endfunction
call ale#linter#Define('python', {
\ 'name': 'mypy',
\ 'executable_callback': 'ale_linters#python#mypy#GetExecutable',
\ 'command_callback': 'ale_linters#python#mypy#GetCommand',
\ 'callback': 'ale_linters#python#mypy#Handle',
\})

View File

@ -0,0 +1,82 @@
" Author: chocoelho <carlospecter@gmail.com>
" Description: prospector linter python files
let g:ale_python_prospector_executable =
\ get(g:, 'ale_python_prospector_executable', 'prospector')
let g:ale_python_prospector_options =
\ get(g:, 'ale_python_prospector_options', '')
let g:ale_python_prospector_use_global = get(g:, 'ale_python_prospector_use_global', 0)
function! ale_linters#python#prospector#GetExecutable(buffer) abort
return ale#python#FindExecutable(a:buffer, 'python_prospector', ['prospector'])
endfunction
function! ale_linters#python#prospector#GetCommand(buffer) abort
return ale#Escape(ale_linters#python#prospector#GetExecutable(a:buffer))
\ . ' ' . ale#Var(a:buffer, 'python_prospector_options')
\ . ' --messages-only --absolute-paths --zero-exit --output-format json'
\ . ' %s'
endfunction
function! ale_linters#python#prospector#Handle(buffer, lines) abort
let l:output = []
let l:prospector_error = json_decode(join(a:lines, ''))
for l:error in l:prospector_error.messages
if (l:error.code is# 'W291' || l:error.code is# 'W293' || l:error.code is# 'trailing-whitespace')
\ && !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
" Skip warnings for trailing whitespace if the option is off.
continue
endif
if l:error.code is# 'W391'
\&& !ale#Var(a:buffer, 'warn_about_trailing_blank_lines')
" Skip warnings for trailing blank lines if the option is off
continue
endif
if l:error.source =~# '\v\[%(dodgy|mccabe|pep8|pep257|pyroma)\]$'
let l:sub_type = 'style'
else
let l:sub_type = ''
endif
if l:error.source =~# '\v\[pylint\]$'
let l:type = l:error.code =~? '\m^[CRW]' ? 'W' : 'E'
elseif l:error.source =~# '\v\[%(frosted|pep8)\]$'
let l:type = l:error.code =~? '\m^W' ? 'W' : 'E'
elseif l:error.source =~# '\v\[%(dodgy|pyroma|vulture)\]$'
let l:type = 'W'
else
let l:type = 'E'
endif
let l:item = {
\ 'lnum': l:error.location.line,
\ 'col': l:error.location.character + 1,
\ 'text': l:error.message,
\ 'code': printf('(%s) %s', l:error.source, l:error.code),
\ 'type': l:type,
\ 'sub_type': l:sub_type,
\}
if l:sub_type is# ''
unlet l:item.sub_type
endif
call add(l:output, l:item)
endfor
return l:output
endfunction
call ale#linter#Define('python', {
\ 'name': 'prospector',
\ 'executable_callback': 'ale_linters#python#prospector#GetExecutable',
\ 'command_callback': 'ale_linters#python#prospector#GetCommand',
\ 'callback': 'ale_linters#python#prospector#Handle',
\ 'lint_file': 1,
\})

View File

@ -0,0 +1,63 @@
" Author: Michael Thiesen <micthiesen@gmail.com>
" Description: pycodestyle linting for python files
call ale#Set('python_pycodestyle_executable', 'pycodestyle')
call ale#Set('python_pycodestyle_options', '')
call ale#Set('python_pycodestyle_use_global', 0)
function! ale_linters#python#pycodestyle#GetExecutable(buffer) abort
return ale#python#FindExecutable(a:buffer, 'python_pycodestyle', ['pycodestyle'])
endfunction
function! ale_linters#python#pycodestyle#GetCommand(buffer) abort
return ale#Escape(ale_linters#python#pycodestyle#GetExecutable(a:buffer))
\ . ' '
\ . ale#Var(a:buffer, 'python_pycodestyle_options')
\ . ' -'
endfunction
function! ale_linters#python#pycodestyle#Handle(buffer, lines) abort
let l:pattern = '\v^(\S*):(\d*):(\d*): ([EW]\d+) (.*)$'
let l:output = []
" lines are formatted as follows:
" file.py:21:26: W291 trailing whitespace
for l:match in ale#util#GetMatches(a:lines, l:pattern)
if(l:match[4] is# 'W291' || l:match[4] is# 'W293')
\&& !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
" Skip warnings for trailing whitespace if the option is off.
continue
endif
if l:match[4] is# 'W391'
\&& !ale#Var(a:buffer, 'warn_about_trailing_blank_lines')
" Skip warnings for trailing blank lines if the option is off
continue
endif
let l:item = {
\ 'lnum': l:match[2] + 0,
\ 'col': l:match[3] + 0,
\ 'type': l:match[4][0],
\ 'sub_type': 'style',
\ 'text': l:match[5],
\ 'code': l:match[4],
\}
" E999 and E112 are syntax errors.
if l:match[4] is# 'E999' || l:match[4] is# 'E112'
unlet l:item.sub_type
endif
call add(l:output, l:item)
endfor
return l:output
endfunction
call ale#linter#Define('python', {
\ 'name': 'pycodestyle',
\ 'executable_callback': 'ale_linters#python#pycodestyle#GetExecutable',
\ 'command_callback': 'ale_linters#python#pycodestyle#GetCommand',
\ 'callback': 'ale_linters#python#pycodestyle#Handle',
\})

View File

@ -0,0 +1,38 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: pyflakes for python files
call ale#Set('python_pyflakes_executable', 'pyflakes')
call ale#Set('python_pyflakes_use_global', 0)
function! ale_linters#python#pyflakes#GetExecutable(buffer) abort
return ale#python#FindExecutable(a:buffer, 'python_pyflakes', ['pyflakes'])
endfunction
function! ale_linters#python#pyflakes#GetCommand(buffer) abort
let l:executable = ale_linters#python#pyflakes#GetExecutable(a:buffer)
return ale#Escape(l:executable) . ' %t'
endfunction
function! ale_linters#python#pyflakes#Handle(buffer, lines) abort
let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\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],
\})
endfor
return l:output
endfunction
call ale#linter#Define('python', {
\ 'name': 'pyflakes',
\ 'executable_callback': 'ale_linters#python#pyflakes#GetExecutable',
\ 'command_callback': 'ale_linters#python#pyflakes#GetCommand',
\ 'callback': 'ale_linters#python#pyflakes#Handle',
\ 'output_stream': 'both',
\})

View File

@ -0,0 +1,63 @@
" Author: keith <k@keith.so>
" Description: pylint for python files
let g:ale_python_pylint_executable =
\ get(g:, 'ale_python_pylint_executable', 'pylint')
let g:ale_python_pylint_options =
\ get(g:, 'ale_python_pylint_options', '')
let g:ale_python_pylint_use_global = get(g:, 'ale_python_pylint_use_global', 0)
function! ale_linters#python#pylint#GetExecutable(buffer) abort
return ale#python#FindExecutable(a:buffer, 'python_pylint', ['pylint'])
endfunction
function! ale_linters#python#pylint#GetCommand(buffer) abort
return ale#Escape(ale_linters#python#pylint#GetExecutable(a:buffer))
\ . ' ' . ale#Var(a:buffer, 'python_pylint_options')
\ . ' --output-format text --msg-template="{path}:{line}:{column}: {msg_id} ({symbol}) {msg}" --reports n'
\ . ' %s'
endfunction
function! ale_linters#python#pylint#Handle(buffer, lines) abort
" Matches patterns like the following:
"
" test.py:4:4: W0101 (unreachable) Unreachable code
let l:pattern = '\v^[^:]+:(\d+):(\d+): ([[:alnum:]]+) \(([^(]*)\) (.*)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
"let l:failed = append(0, l:match)
let l:code = l:match[3]
if (l:code is# 'C0303')
\ && !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
" Skip warnings for trailing whitespace if the option is off.
continue
endif
if l:code is# 'I0011'
" Skip 'Locally disabling' message
continue
endif
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 1,
\ 'text': l:match[5],
\ 'code': l:match[4],
\ 'type': l:code[:0] is# 'E' ? 'E' : 'W',
\})
endfor
return l:output
endfunction
call ale#linter#Define('python', {
\ 'name': 'pylint',
\ 'executable_callback': 'ale_linters#python#pylint#GetExecutable',
\ 'command_callback': 'ale_linters#python#pylint#GetCommand',
\ 'callback': 'ale_linters#python#pylint#Handle',
\ 'lint_file': 1,
\})

View File

@ -0,0 +1,28 @@
" Author: aurieh <me@aurieh.me>
" Description: A language server for Python
call ale#Set('python_pyls_executable', 'pyls')
call ale#Set('python_pyls_use_global', 0)
function! ale_linters#python#pyls#GetExecutable(buffer) abort
return ale#python#FindExecutable(a:buffer, 'python_pyls', ['pyls'])
endfunction
function! ale_linters#python#pyls#GetCommand(buffer) abort
let l:executable = ale_linters#python#pyls#GetExecutable(a:buffer)
return ale#Escape(l:executable)
endfunction
function! ale_linters#python#pyls#GetLanguage(buffer) abort
return 'python'
endfunction
call ale#linter#Define('python', {
\ 'name': 'pyls',
\ 'lsp': 'stdio',
\ 'executable_callback': 'ale_linters#python#pyls#GetExecutable',
\ 'command_callback': 'ale_linters#python#pyls#GetCommand',
\ 'language_callback': 'ale_linters#python#pyls#GetLanguage',
\ 'project_root_callback': 'ale#python#FindProjectRoot',
\})