Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

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

Open
livevasiliy opened this issue Nov 22, 2021 · 7 comments

Comments

@livevasiliy
Copy link

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.

@jeroennoten
Copy link
Member

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 jeroennoten changed the title This package NOT WORK This package does not work without a phpcs.xml configuration file present Nov 22, 2021
@livevasiliy
Copy link
Author

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

@peterjaap
Copy link

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
Copy link

peterjaap commented Nov 16, 2022

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
Copy link

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

@jeroennoten
Copy link
Member

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

@peterjaap
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants