forked from bpearson/vim-phpcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpcs.vim
More file actions
68 lines (61 loc) · 2.05 KB
/
Copy pathphpcs.vim
File metadata and controls
68 lines (61 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
" File: phpcs.vim
" Author: Benjamin Pearson (bpearson AT squiz DOT com DOT au)
" Version: 0.3
" Last Modified: July 3, 2014
" Copyright: Copyright (C) 2014 Benjamin Pearson
" See LICENSE for more information
"
" The "Vim PhpCs" plugin runs PHP_CodeSniffer and displays the results
" in Vim.
"
" Installation
" ------------
" 1. Obtain a copy of this plugin and place phpcs.vim in your Vim plugin
" directory and vim-phpcs.txt in the docs/ directory.
" 2. Add let Vimphpcs_Standard='STANDARDNAME' to your .vimrc file.
" 3. Restart Vim.
" 4. You can now use the ":CodeSniff" command to run PHP_CodeSniffer
" and display the results.
"
" ****************** Do not modify after this line ************************
if exists("g:loaded_Vimphpcs") || &cp
finish
endif
let g:loaded_Vimphpcs = 0.3
let s:keepcpo = &cpo
set cpo&vim
" Test for CodeSniffer
if !exists('Vimphpcs_Phpcscmd')
if executable('phpcs')
let Vimphpcs_Phpcscmd='phpcs '
else
" Unable to find the CodeSniffer executable
echomsg 'Unable to find phpcs in the current PATH.'
echomsg 'Plugin not loaded.'
let &cpo = s:keepcpo
finish
endif
endif
" Options
if !exists('Vimphpcs_Standard')
let Vimphpcs_Standard='PEAR'
endif
if !exists('Vimphpcs_ExtraArgs')
let Vimphpcs_ExtraArgs=''
endif
function! s:CodeSniff(extraarg)
set errorformat+=\"%f\"\\,%l\\,%c\\,%t%*[a-zA-Z]\\,\"%m\"\\,%*[a-zA-Z0-9_.-\\,]
let l:extraarg = a:extraarg.' '.g:Vimphpcs_ExtraArgs
let l:filename = @%
let l:phpcs_cmd = g:Vimphpcs_Phpcscmd
let l:phpcs_standard = g:Vimphpcs_Standard
let l:phpcs_opts = ' '.l:extraarg.' --report=csv --standard='.l:phpcs_standard
let l:phpcs_output = system(l:phpcs_cmd.l:phpcs_opts.' '.l:filename)
let l:phpcs_output = substitute(l:phpcs_output, '\\"', "'", 'g')
let l:phpcs_results = split(l:phpcs_output, "\n")
unlet l:phpcs_results[0]
cexpr l:phpcs_results
copen
endfunction
command! CodeSniff :call <SID>CodeSniff('')
command! CodeSniffErrorOnly :call <SID>CodeSniff('-n')