mirror of
https://github.com/amix/vimrc
synced 2025-06-16 01:25:00 +08:00
Removed syntastic and replaced it with ale
Read more here: https://github.com/w0rp/ale
This commit is contained in:
68
sources_non_forked/ale/ale_linters/perl/perl.vim
Normal file
68
sources_non_forked/ale/ale_linters/perl/perl.vim
Normal file
@ -0,0 +1,68 @@
|
||||
" Author: Vincent Lequertier <https://github.com/SkySymbol>
|
||||
" Description: This file adds support for checking perl syntax
|
||||
|
||||
let g:ale_perl_perl_executable =
|
||||
\ get(g:, 'ale_perl_perl_executable', 'perl')
|
||||
|
||||
let g:ale_perl_perl_options =
|
||||
\ get(g:, 'ale_perl_perl_options', '-c -Mwarnings -Ilib')
|
||||
|
||||
function! ale_linters#perl#perl#GetExecutable(buffer) abort
|
||||
return ale#Var(a:buffer, 'perl_perl_executable')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#perl#perl#GetCommand(buffer) abort
|
||||
return ale#Escape(ale_linters#perl#perl#GetExecutable(a:buffer))
|
||||
\ . ' ' . ale#Var(a:buffer, 'perl_perl_options')
|
||||
\ . ' %t'
|
||||
endfunction
|
||||
|
||||
let s:begin_failed_skip_pattern = '\v' . join([
|
||||
\ '^Compilation failed in require',
|
||||
\ '^Can''t locate',
|
||||
\], '|')
|
||||
|
||||
function! ale_linters#perl#perl#Handle(buffer, lines) abort
|
||||
let l:pattern = '\(.\+\) at \(.\+\) line \(\d\+\)'
|
||||
let l:output = []
|
||||
let l:basename = expand('#' . a:buffer . ':t')
|
||||
|
||||
let l:type = 'E'
|
||||
if a:lines[-1] =~# 'syntax OK'
|
||||
let l:type = 'W'
|
||||
endif
|
||||
|
||||
let l:seen = {}
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
let l:line = l:match[3]
|
||||
let l:file = l:match[2]
|
||||
let l:text = l:match[1]
|
||||
|
||||
if ale#path#IsBufferPath(a:buffer, l:file)
|
||||
\ && !has_key(l:seen,l:line)
|
||||
\ && (
|
||||
\ l:text isnot# 'BEGIN failed--compilation aborted'
|
||||
\ || empty(l:output)
|
||||
\ || match(l:output[-1].text, s:begin_failed_skip_pattern) < 0
|
||||
\ )
|
||||
call add(l:output, {
|
||||
\ 'lnum': l:line,
|
||||
\ 'text': l:text,
|
||||
\ 'type': l:type,
|
||||
\})
|
||||
|
||||
let l:seen[l:line] = 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('perl', {
|
||||
\ 'name': 'perl',
|
||||
\ 'executable_callback': 'ale_linters#perl#perl#GetExecutable',
|
||||
\ 'output_stream': 'both',
|
||||
\ 'command_callback': 'ale_linters#perl#perl#GetCommand',
|
||||
\ 'callback': 'ale_linters#perl#perl#Handle',
|
||||
\})
|
77
sources_non_forked/ale/ale_linters/perl/perlcritic.vim
Normal file
77
sources_non_forked/ale/ale_linters/perl/perlcritic.vim
Normal file
@ -0,0 +1,77 @@
|
||||
" Author: Vincent Lequertier <https://github.com/SkySymbol>, Chris Weyl <cweyl@alumni.drew.edu>
|
||||
" Description: This file adds support for checking perl with perl critic
|
||||
|
||||
let g:ale_perl_perlcritic_executable =
|
||||
\ get(g:, 'ale_perl_perlcritic_executable', 'perlcritic')
|
||||
|
||||
let g:ale_perl_perlcritic_profile =
|
||||
\ get(g:, 'ale_perl_perlcritic_profile', '.perlcriticrc')
|
||||
|
||||
let g:ale_perl_perlcritic_options =
|
||||
\ get(g:, 'ale_perl_perlcritic_options', '')
|
||||
|
||||
let g:ale_perl_perlcritic_showrules =
|
||||
\ get(g:, 'ale_perl_perlcritic_showrules', 0)
|
||||
|
||||
function! ale_linters#perl#perlcritic#GetExecutable(buffer) abort
|
||||
return ale#Var(a:buffer, 'perl_perlcritic_executable')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#perl#perlcritic#GetProfile(buffer) abort
|
||||
|
||||
" first see if we've been overridden
|
||||
let l:profile = ale#Var(a:buffer, 'perl_perlcritic_profile')
|
||||
if l:profile is? ''
|
||||
return ''
|
||||
endif
|
||||
|
||||
" otherwise, iterate upwards to find it
|
||||
return ale#path#FindNearestFile(a:buffer, l:profile)
|
||||
endfunction
|
||||
|
||||
function! ale_linters#perl#perlcritic#GetCommand(buffer) abort
|
||||
let l:critic_verbosity = '%l:%c %m\n'
|
||||
if ale#Var(a:buffer, 'perl_perlcritic_showrules')
|
||||
let l:critic_verbosity = '%l:%c %m [%p]\n'
|
||||
endif
|
||||
|
||||
let l:profile = ale_linters#perl#perlcritic#GetProfile(a:buffer)
|
||||
let l:options = ale#Var(a:buffer, 'perl_perlcritic_options')
|
||||
|
||||
let l:command = ale#Escape(ale_linters#perl#perlcritic#GetExecutable(a:buffer))
|
||||
\ . " --verbose '". l:critic_verbosity . "' --nocolor"
|
||||
|
||||
if l:profile isnot? ''
|
||||
let l:command .= ' --profile ' . ale#Escape(l:profile)
|
||||
endif
|
||||
if l:options isnot? ''
|
||||
let l:command .= ' ' . l:options
|
||||
endif
|
||||
|
||||
return l:command
|
||||
endfunction
|
||||
|
||||
|
||||
function! ale_linters#perl#perlcritic#Handle(buffer, lines) abort
|
||||
let l: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],
|
||||
\ 'col': l:match[2],
|
||||
\ 'text': l:match[3],
|
||||
\ 'type': 'W'
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('perl', {
|
||||
\ 'name': 'perlcritic',
|
||||
\ 'output_stream': 'stdout',
|
||||
\ 'executable_callback': 'ale_linters#perl#perlcritic#GetExecutable',
|
||||
\ 'command_callback': 'ale_linters#perl#perlcritic#GetCommand',
|
||||
\ 'callback': 'ale_linters#perl#perlcritic#Handle',
|
||||
\})
|
Reference in New Issue
Block a user