Php_codesniffer: phpcs does not report syntax errors

Created on 4 Feb 2018  路  3Comments  路  Source: squizlabs/PHP_CodeSniffer

I've installed CS as phar (PHP_CodeSniffer version 3.0.2 (stable))
PHP 5.6.30

I'm tesing simple file(test.php) that has syntax error:
vvvvvvvvvvvvvvvvvvvvvvvvvvvv
<?php
echo "foobar"

^^^^^^^^^^^^^^^^^^^^^^^^^^^^

$ phpcs --report=xml --standard=PSR2 test.php

I got:

<?xml version="1.0" encoding="UTF-8"?>
<phpcs version="3.0.2">
</phpcs>

But on $ php -l test.php

I got:

Parse error: syntax error, unexpected end of file, expecting ',' or ';' in ./test.php on line 3
Errors parsing ./test.php

Then I am removing the last empty line of the file and running phpcs again -

<?xml version="1.0" encoding="UTF-8"?>
<phpcs version="3.0.2">
<file name="/home/jigius/Desktop/test.php" errors="1" warnings="0" fixable="1">
<error line="2" column="6" source="PSR2.Files.EndFileNewline.NoneFound" severity="5" fixable="1">Expected 1 newline at end of file; 0 found</error>
</file>
</phpcs>

Most helpful comment

@buttflattery Try adding this snippet to your existing phpcs.xml.dist file:

<rule ref="Generic.PHP.Syntax"/>

All 3 comments

For syntax errors, there is the PHP linter, which you are clearly familiar with. You can call it from within PHPCS by adding the Generic.PHP.Syntax sniff to your (custom) ruleset.

hello @jrfnl i am new to this and was wondering how should i be adding the ruleset for using the Generic.PHP.Syntax sniff in my phpcs.xml.dist? any link to an example might help where it can show me what properties name should be set under the ruleset with what values.

@buttflattery Try adding this snippet to your existing phpcs.xml.dist file:

<rule ref="Generic.PHP.Syntax"/>
Was this page helpful?
0 / 5 - 0 ratings