Plugin para vim para utilizar la salida de PhpCodeSniffer en la ventana de errores

phpcodesniffer.vim

" php_check_codesniffer.vim -- Check php syntax when saving or reading a file
" @Author:      Eduardo Magrané , basado en phpchecksyntax de Thomas Link (samul@web.de)
" @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created:     31-Oct-2009.
" @Last Change: .
" @Revision:    0.2.21
" @todo Aceptar parámetro de standard que se desea

if exists("g:php_check_codesniffer")
   finish
endif

let g:php_check_codesniffer = 1

if !exists("g:php_check_codesniffer_cmd")
    let g:php_check_codesniffer_cmd='phpcs --standard=Zend --report=emacs'
endif

function! PhpCodeSniffer()
    if &filetype == 'php'
        let t  = @t
        let mp = &makeprg
        let sp = &shellpipe
        let ef = &errorformat
        try
            let &makeprg = g:php_check_codesniffer_cmd
            set shellpipe=> 				
            " set errorformat=%*[^<]:\ \ %m\ in\ %f\ on\ line\ %l
            "set errorformat=%*[^:]:\ %m\ in\ %f\ on\ line\ %l
            set errorformat=%f:%l:%c:\ %m
            silent make %
            redir @t
            silent clist
            redir END
            if @t =~ 'No se han detectado errores '
                cclose
            else
                copen
            endif
        finally
            let @t = t
            let &makeprg     = mp
            let &shellpipe   = sp
            let &errorformat = ef
        endtry
    endif
endf

noremap   :call PhpCodeSniffer()
inoremap   :call PhpCodeSniffer() 

"autocmd BufRead,BufWritePost *.php call PhpCodeSniffer()

finish
Instalación:
Guardar el fichero en la carpeta ~/.vim/plugins
2 comments
  1. bimatoprost
    bimatoprost
    18 de setembre de 2020 at 2:36

    I really like your blog.. very nice colors & theme. Did you create this website yourself
    or did you hire someone to do it for you? Plz respond as I’m looking to
    create my own blog and would like to find out where u got this from.
    thanks

    Reply
    • edumag
      edumag • Post Author •
      18 de setembre de 2020 at 11:58

      This blog is made with wordpres and its own theme based on wp-bootstrap-4.

      Thanks

      Reply
Leave a Reply

Your email address will not be published. Required fields are marked *

Aquest lloc utilitza Akismet per reduir els comentaris brossa. Apreneu com es processen les dades dels comentaris.