squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

--report-junit XML output also appears on stdout #3681

Closed bantu closed 2 years ago

bantu commented 2 years ago

Describe the bug

I run version 3.7.1 installed via composer as follows:

vendor/bin/phpcs
        -v
        --extensions=php
        --report-junit=phpcs-report.xml
        --standard=PSR2
        src/
        tests/

Expected behavior I expect progress information on stdout due to -v and an xml report in a phpcs-report.xml file.

Actual behavior I am seeing progress information, but the xml report is also output on stdout.

Versions (please complete the following information):

bantu commented 2 years ago

I see https://github.com/squizlabs/PHP_CodeSniffer/commit/d4f33dbf45aa5bb78e077b0e73306746c8bd98cf which allows to discard the unwanted report output by redirecting stdout accordingly. However, this commit does not seem to be in 3.7.

jrfnl commented 2 years ago

@bantu Try running PHPCS like so:

vendor/bin/phpcs
        -v
        --extensions=php
        --report=junit
        --report-file=phpcs-report.xml
        --standard=PSR2
        src/
        tests/

Ref: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Reporting#writing-a-report-to-a-file

bantu commented 2 years ago

@jrfnl Thanks for the suggestion. The behavior is the same for me.

jrfnl commented 2 years ago

@bantu Okay, so there are two things going on here:

  1. The report file gets written correctly.
  2. The report is also written to stdout.

This second part is due to your use of the -v option, which is a debugging option. If you want to see progress (without the debugging info), use the -p option instead and you will only get the report in the file and no longer on the screen.

bantu commented 2 years ago

@jrfnl Interesting. The documentation in --help does not mention that -v is a debug option, but says "Print processed files", which seems to be exactly what I want.