PHPCompatibility / PHPCompatibilityWP

PHPCompatibility ruleset for WordPress projects
GNU Lesser General Public License v3.0
174 stars 10 forks source link

Project xml file not overwriting the defined testVersion in the upstream ruleset? #7

Closed dingo-d closed 5 years ago

dingo-d commented 5 years ago

Hi!

I updated the companies ruleset to check the code against PHP 7.0 code and up, with

<!-- Check code for cross-version PHP compatibility. -->
<config name="testVersion" value="7.0-"/>
<rule ref="PHPCompatibilityWP"/>

So in my project's phpcs.xml.dist I added

<?xml version="1.0"?>
<ruleset name="My Project">

  <rule ref="Infinum" />

  <config name="testVersion" value="7.2-"/>
  <rule ref="PHPCompatibilityWP"/>

</ruleset>

because I'm actually working on PHP 7.2, and I'm using things like typehinting a void return value of a method.

The problem is that the config set in my project's ruleset is not overwritten and I'm getting errors like

error - void return type is not present in PHP version 7.0 or earlier (PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.voidFound)

Am I doing something wrong? This should be like any other rule for PHPCS.

jrfnl commented 5 years ago

This is a known issue in PHPCS - see: https://github.com/squizlabs/PHP_CodeSniffer/issues/1821 and https://github.com/squizlabs/PHP_CodeSniffer/issues/2197

Since PHPCS 3.3.0, you can, at least, overrule the testVersion set in a ruleset by using the command line, which for now is the only solution (or use the hack described in 2197 above). See: https://github.com/PHPCompatibility/PHPCompatibility#testversion-in-the-ruleset-versus-command-line

dingo-d commented 5 years ago

Oh, that's a shame. I'll wait for the fix then, thanks!