isaaceindhoven / php-code-sniffer-baseliner

Baseline tool for PHP_CodeSniffer
https://isaac.nl
MIT License
16 stars 5 forks source link

Baseliner does not add ignore lines for warnings when there are 0 errors #12

Open peterjaap opened 1 year ago

peterjaap commented 1 year ago

Our CI fails when phpcs returns warnings, however, this package does not add warnings to the baseline, only errors.

So when I run the baseliner I get;

Running PHP_CodeSniffer (this may take a while)...
PHP_CodeSniffer did not report any errors.

But when I run phpcs;

$ vendor/bin/grumphp run --tasks phpcs -n

GrumPHP is sniffing your code!                                                                                                               

Running tasks with priority 0!                                                                                                               
==============================                                                                                                               

Running task 1/1: phpcs... ✘                                                                                                                 

phpcs                                                                                                                                        
=====                                                                                                                                        

....

And it finds a lot of warnings and exits with non-zero error code, making our pipeline fail.

I could add <config name="ignore_warnings_on_exit" value="1" /> to phpcs.xml, but then there's no record of these errors in the baseline, which is what I prefer.

Is it possible to add a flag to also create a baseline for phpcs warnings, not just errors?

peterjaap commented 1 year ago

Wait, I think I found a bug. This line should read 'warnings', not 'errors'. And the next one should read 'fixable', not 'errors';

https://github.com/isaaceindhoven/php-code-sniffer-baseliner/blob/b6a3c1e4f64d9cb2d7d0ba676697c6ac1b3c9982/src/PhpCodeSnifferRunner/ReportDeserializer.php#L40

This causes the baseliner to skip warnings when there are 0 errors.

peterjaap commented 1 year ago

LOL there already is a PR made SIX DAYS ago while this bug has been in here since January 2020!

https://github.com/isaaceindhoven/php-code-sniffer-baseliner/pull/11

jeroennoten commented 1 year ago

PR is merged now and part of v2.3.1. Please let me now if this issue can be closed.