php-code-sniffer-baseliner icon indicating copy to clipboard operation
php-code-sniffer-baseliner copied to clipboard

This package does not work without a phpcs.xml configuration file present

Open livevasiliy opened this issue 3 years ago • 7 comments

Hi, @isaaceindhoven I installed your package, and it doesn't work almost.

I call your package via CLI like that: ./vendor/bin/phpcs-baseliner create-baseline ./app and I got errors

Running PHP_CodeSniffer (this may take a while)...
RuntimeException: ERROR: You must supply at least one file or directory to process. in /var/www/academy/current/vendor/isaac/php-code-sniffer-baseliner/src/PhpCodeSnifferRunner/Runner.php:28
Stack trace:
#0 /var/www/academy/current/vendor/isaac/php-code-sniffer-baseliner/src/BaselineCreator.php(65): ISAAC\CodeSnifferBaseliner\PhpCodeSnifferRunner\Runner->run('/var/www/academ...')
#1 /var/www/academy/current/vendor/isaac/php-code-sniffer-baseliner/src/Application.php(95): ISAAC\CodeSnifferBaseliner\BaselineCreator->create()
#2 /var/www/academy/current/vendor/isaac/php-code-sniffer-baseliner/src/Application.php(57): ISAAC\CodeSnifferBaseliner\Application->runCommand(Object(ISAAC\CodeSnifferBaseliner\Command\CreateBaseline))
#3 /var/www/academy/current/vendor/isaac/php-code-sniffer-baseliner/bin/phpcs-baseliner(18): ISAAC\CodeSnifferBaseliner\Application->run('./vendor/bin/ph...', 'create-baseline', './app')
#4 {main

The problem conclusion is not correct to use of embedded PhpCs command and passes arguments. For me, temp solutions as it changes your source code in vendor folder in file Runner.php:20 passes additional arguments which hold name folders that need to scans. So please fix your package do add a feature pass argument with name folders.

livevasiliy avatar Nov 22 '21 19:11 livevasiliy

Hi @livevasiliy, thanks for reporting your problem.

This tool requires a phpcs.xml configuration file present, see: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file

However, I think your idea of passing command line arguments through to the underlying phpcs process is a good idea, and I will probably implement this feature request soon.

jeroennoten avatar Nov 22 '21 19:11 jeroennoten

OK, from my side, I will try to re-run your package with the phpcs.xml file.

livevasiliy avatar Nov 22 '21 19:11 livevasiliy

I just ran into this too and while you can run phpcs by appending the dir you want to scan to the command line arguments, it doesn't work that way for the baseliner.

So if you run phpcs like this;

vendor/bin/phpcs --standard=./phpcs.xml --extensions=php --report=full dir1 dir2

That will scan dir1 and dir2. But you can't run ./vendor/bin/phpcs-baseliner create-baseline dir1 dir2.

I eventually found out that you need to add that to the phpcs.xml file, and you need to use the <file> parameter, even though it is a directory.

So add

<file>dir1</file>
<file>dir2</file>

to your phpcs.xml and you're good to go. Having to use <file> instead of <directory> (or similar) threw me off.

peterjaap avatar Nov 15 '22 08:11 peterjaap

I found some more issues. We run phcps through grumphp, which takes some configuration. This is the command Grumphp phpcs runs with;

Command: '/data/client/magento2/vendor/bin/phpcs' '--standard=./phpcs.xml' '--extensions=php,phtml' '--report=full' '--report-json' '--file-list=/tmp/phpijaJtq'

But when running the baseliner, it only takes these arguments, see https://github.com/isaaceindhoven/php-code-sniffer-baseliner/blob/master/src/PhpCodeSnifferRunner/Runner.php#L20:

  • -q
  • --report=json
  • --basepath=%s

That means it doesn't take extensions into account, thereby also checking all XML files. However, phpcs doesn't allow setting this option in the phcps file (can't find it in the documentation). Tried these, but don't work;

<extensions>php,phtml</extensions>
<arg name="extensions" value="php,phtml"/>

So I edit the phpcs command;

- $cliCommand = sprintf('vendor/bin/phpcs -q --report=json --basepath=%s', escapeshellarg($basePath));
+ $cliCommand = sprintf('vendor/bin/phpcs --standard=./phpcs.xml --extensions=php,phtml --report-json --basepath=%s', escapeshellarg($basePath));

peterjaap avatar Nov 16 '22 08:11 peterjaap

Mabye it's an idea to pass on arguments given to vendor/bin/phpcs-baseliner create-baseline to the phpcs command in the runner?

peterjaap avatar Nov 16 '22 09:11 peterjaap

@peterjaap, good idea! I have limited time to implement improvements to this package at the moment, so PR's are very welcome.

jeroennoten avatar Nov 16 '22 21:11 jeroennoten

@jeroennoten it's already on my Sunday funday open source list :)

peterjaap avatar Nov 17 '22 07:11 peterjaap