Giter VIP home page Giter VIP logo

phpcs.vim's Introduction

This is a mirror of http://www.vim.org/scripts/script.php?script_id=3928

This plugin relies on PHP_CodeSniffer package.It parse the result of phpcs and redirect it into vim's quickfix buffer.
So users can navigate the codding rule error place use ':cnext' and ':cprev'.
PHP_CodeSniffer is a utility developed for checking codding rules for PHP scripts.
For more information about PHP_CodeSniffer, see http://pear.php.net/package/PHP_CodeSniffer/

To use this plugin, you must have these global variables set:
 1. The list of coding rule standards to follow, with each one seperated by comma.                                                        
     let g:phpcs_std_list="Zend, PEAR"
 
 2. Your VCS type(Only needed when running 'Phpcs commit')
     let g:phpcs_vcs_type = 'svn'

     Currently only support 'svn' or  'cvs'.

 3. Set the max allowed output lines. 
     This is useful in case there are too many errors and memory is running out.
    
      let g:phpcs_max_output = 0 " Unlimited output.
      or
      let g:phpcs_max_output = 2000 " Output limited to 2000 line

Following command are provided:

 :Phpcs          " Check the current file, if not in DIFF mode.
                       "  Check the modified lines only, if in DIFF mode. And in DIFF mode, call  :Phpcs twice, it will switch back and update the DIFF view.
 :Phpcs commit   " Checking PHP  files to be commited in the directory recursively
 :Phpcs all           " Checking PHP files in the current directory recursively

You can map shortcuts for your convenience. For example, in my working environment, we do following mappings:
" input mode map
inoremap <F5>  <ESC>:Phpcs<CR>
inoremap <F7> <ESC>:cprev<CR>
inoremap <F8> <ESC>:cnext<CR>

"normal mode map
noremap <F5>  <ESC>:Phpcs<CR>
noremap <F7> <Esc>:cprev<CR>
noremap <F8> <ESC>:cnext<CR>

Note for the Phpcs in DIFF mode:
1. Why support Phpcs in DIFF mode?
Due to historical reasons, there exist a lot of old codes not following the new coding standards. Our policy is that, for the new codes added, must following the coding standards; but keep the old codes as it is.
So we only need to check the new codes to be committed. 

2. Which scenario does this mode work?
In this scenario, we use vimdiff for the extra diff command of svn diff. Before we commit the codes, we run svn diff, which in turn will call vimdiff to show what has been changed in codes.
Here we call :Phpcs command, to do the checking, and that will only output errors/warning in the lines modified in this commit.

3. The Phpcs in DIFF mode is not flexible!
You should make sure that:  ONLY TWO WINDOWS EXIST IN DIFF VIEW, THE 1ST ONE IS THE ORIGINAL FILE, THE 2ND ONE IS THE MODIFIED FILE.
If you use other plugins and they open windows automatically in vimdiff mode, you should close it first manually or add codes to do this in phpcs.vim.
In the 1.1 version, I added codes to detect MiniBufExpl plugin, and close it automatically. Just for your reference.

phpcs.vim's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.