tomtom / checksyntax_vim

Check a file's syntax when saving a file (php, ruby, tex ...) with vim
http://www.vim.org/scripts/script.php?script_id=1431
GNU General Public License v3.0
94 stars 9 forks source link

Adding PHPCS checker for PHP #28

Closed Craige closed 9 years ago

Craige commented 9 years ago

I've added a PHPCS checker locally, but I'm not exactly sure I'm doing it correctly. In order to get it to work, I had to add the following to my .vimrc file

call checksyntax#Alternative('php', {
               \ 'name': 'phpcs',
               \ 'cmd': 'bin/phpcs --report=emacs',
               \ 'efm': '%f:%l:%*[^:]: %*[^-]- %m'
               \ })
call checksyntax#Alternative('php', {
               \     'name': 'php',
               \     'cmd': 'php -l -d display_errors=0 -d error_log= -d error_reporting=E_PARSE',
               \     'efm': '%*[^:]: %m in %f on line %l',
               \ })
let g:checksyntax.php.auto = 1

I just wanted to add the first phpcs checker, but when I added this, the contents of php.vim no longer execute due to the if !exists('g:checksyntax.php') check. Is there another way I should be adding this checker to build on top of the existing php.vim file?

Worth noting- I added this to a project specific .vimrc in my project directory, and checksyntax is loaded via Pathogen. I'm not sure if that matters

tomtom commented 9 years ago

|let g:checksyntax.php.auto = 1 | In a recent version of checksyntax, it's preferable to use

 let g:checksyntax#auto_enable_rx = '^php$'

or add an auto field to the definition (see :h checksyntax#AddChecker).

|if !exists('g:checksyntax.php')|

Which version of checksyntax do you use? Where is this check? Do you use the current version from https://github.com/tomtom/checksyntax_vim/?

Why do you re-add the "php"-checker? Is it because php.vim doesn't seem to get loaded or to reverse the order of type checkers? In the latter case, you might want to set g:checksyntax#preferred.php instead.

Craige commented 9 years ago

I'll check my checksyntax version in the morning, but I haven't updated it in a year, so I'm sure it could stand to be updated.

As for why I re-added the "php" checker, it was because it no longer got added to the alternatives list when I added the "phpcs" checker. I added those lines in a local .vimrc file in my project directory (loaded with the exrc setting).

I'll update my checksyntax in the morning and make the amendments you suggested. I'll report back with the status afterwords.

On April 11, 2015 1:28:32 AM EDT, Tom Link notifications@github.com wrote:

|let g:checksyntax.php.auto = 1 | In a recent version of checksyntax, it's preferable to use

let g:checksyntax#auto_enable_rx = '^php$'

or add an auto field to the definition (see :h checksyntax#AddChecker).

|if !exists('g:checksyntax.php')|

Which version of checksyntax do you use? Where is this check? Do you use the current version from https://github.com/tomtom/checksyntax_vim/?

Why do you re-add the "php"-checker? Is it because php.vim doesn't seem

to get loaded or to reverse the order of type checkers? In the latter case, you might want to set g:checksyntax#preferred.php instead.


Reply to this email directly or view it on GitHub: https://github.com/tomtom/checksyntax_vim/issues/28#issuecomment-91765458

Sent from my Android device with K-9 Mail. Please excuse my brevity.

Craige commented 9 years ago

Okay. I'm up to date with the most recent version on master (0db7298), and I've changed my .vimrc to reflect the following

call checksyntax#AddChecker('php?',
            \   {
            \     'name': 'phpcs',
            \     'auto': 1,
            \     'cmd': 'bin/phpcs --report=emacs',
            \     'if_executable': 'bin/phpcs',
            \     'efm': '%f:%l:%*[^:]: %*[^-]- %m',
            \   }
            \ )

However now it appears that the phpcs checker isn't running at all. The file I'm running it on does indeed have violations, and I've verified so at the command line. This checker doesn't run on save, nor does it run when I run the :CheckSyntax command manually.

I don't think this is related, but when I start vim now I get:

Error detected while processing function pathogen#helptags:
line    4:
E154: Duplicate tag "g:checksyntax#async_runner" in file /Users/craigeleeder/.vim/bundle/checksyntax_vim/doc/checksyntax.txt
E154: Duplicate tag "g:checksyntax#async_runner" in file /Users/craigeleeder/.vim/bundle/checksyntax_vim/doc/checksyntax.txt
CheckSyntax: Run vim with the --servername NAME command line option to enable use of AsyncCommand
tomtom commented 9 years ago

|call checksyntax#AddChecker('php?',| Try "php" without the "?" -- define only if it doesn't exist yet. The questionmark should only be used in the default syntax checker definitions.

If you still have problems, I'll look into it when I find some time.

Craige commented 9 years ago

Problem still persists. Is there any way to get debug output from checkSyntax?

Craige commented 9 years ago

I think I see the problem. When I set the CheckSyntax to use the global phpcs, I get a proper response. However, when I try to use the bin/phpcs (which is in my to my current directory. i.e. the projects directory), I don't get any output. So my guess is that checksyntax can't find bin/phpcs in the current working directory. ~Any thoughts on that?~

Using ./bin/phpcs worked.

Would you be interested in taking a PR that adds phpcs to php.vim, along with some new configuration variables for setting the phpcs path and parameters?

tomtom commented 9 years ago

So my guess is that checksyntax can't find |bin/phpcs| in the current working directory.

Is "bin/" in $PATH? It seems the argument to executable() should be the executable name without arguments. See also :h executable(). You could remove the if_executable field, since you know it is installed.

Craige commented 9 years ago

bin/ was in my current directory, so yes.. In any case, using ./bin/phpcs works, so I'm happy.