JustBlackBird / gulp-phpcs

Gulp plugin for running PHP Code Sniffer
MIT License
47 stars 12 forks source link

support for the built-in phpcs reports #26

Closed danalloway closed 8 years ago

danalloway commented 8 years ago

this PR adds another option to the plugin allowing for passing through parameters to generate the built-in reports that PHPCS offers.

to use it, try running

phpcs({
    bin: /path/to/phpcs,
    standard: 'PSR2',
    reports: {
        'checkstyle': '/path/to/output/report.xml',
        'gitblame': '/path/to/output/gitblame.txt'
    }
});

you can read more on this from the PHPCS docs https://github.com/squizlabs/PHP_CodeSniffer/wiki/Reporting

JustBlackBird commented 8 years ago

There are several problems with your PR.

  1. gulp-phpcs runs PHPCS once for each file from the stream. Options like --report-json makes PHPCS to write all reports in one file overwriting its contents.
  2. I don't like the idea of writing something by PHPCS means. You see, gulp-phpcs encapsulates i/o streams and uses reporters to deal with PHPCS results. There is file reporter that is used to dump results to file. Using both file reporter and PHPCS means to write reports ends with a mess.

At the same we should have a way to change reports format. The only way I see right now it to use a parse-able format like JSON inside of a plugin and introduce a bunch of formatters that will be applied to raw data.

JustBlackBird commented 8 years ago

Another way is to use file reporter with --report option. The only drawback is that we cannot use more than one format.

danalloway commented 8 years ago

wow, totally missed that, did not realize it was running it for every file. thanks for getting me up to speed.

using the --report option with file reporter would be nice, even if it's just one type, that would get me half way to where I need to be with this.

regardless, closing this PR thank you!

JustBlackBird commented 8 years ago

wow, totally missed that, did not realize it was running it for every file. thanks for getting me up to speed.

Actually I just don't see another option of how pass files trough stdin to PHPCS (gulp way) and make it deal with more than one file.

using the --report option with file reporter would be nice, even if it's just one type, that would get me half way to where I need to be with this.

There is still a problem. Some formats (like JSON) becomes corrupted if reports for several files (several JSON objects) are just concatenated. The only way to overcome it is in implementing of all the formatters inside of gulp-phpcs. I don't like this idea much though.

Am I miss something? Don't you see any other way of how formatting can be done?