Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpcs ignoreWarnings does not work in CLI mode #119

Closed
Moosh-be opened this issue Feb 28, 2018 · 7 comments
Closed

phpcs ignoreWarnings does not work in CLI mode #119

Moosh-be opened this issue Feb 28, 2018 · 7 comments

Comments

@Moosh-be
Copy link

Moosh-be commented Feb 28, 2018

composer info | grep phpqa
edgedesign/phpqa                      v1.18.0 Analyze PHP code with one command.
composer info | grep php_code
squizlabs/php_codesniffer             3.2.3   PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards

ignoreWarnings: in my .phpqa.yml seems ignored.

1° set true the output cli show warnings
2° final repport too

+---------------+-------------------+-----------+--------+--+
| Tool          | Allowed exit code | Exit code | Is OK? |  |
+---------------+-------------------+-----------+--------+--+
| phpcs         | 0                 | 1         | x      |  |
| parallel-lint | 0                 | 0         | ✓      |  |
+---------------+-------------------+-----------+--------+--+
| phpqa         |                   | 1         | x      |  |
+---------------+-------------------+-----------+--------+--+

I've solve it

.../vendor/edgedesign/phpqa/src/Tools/Analyzer/Phpcs.php

I've added

        if ($this->tool->errorsType) {
            $args[] = '-n';
        }

in

    protected function buildPhpcs(array $installedStandards)
    {
        $this->tool->errorsType = $this->config->value('phpcs.ignoreWarnings') === true;
        $standard = $this->config->value('phpcs.standard');
        if (!in_array($standard, $installedStandards)) {
            $standard = \Edge\QA\escapePath($this->config->path('phpcs.standard'));
        }
        $args = array(
            '-p',
            'standard' => $standard,
            $this->options->ignore->phpcs(),
            $this->options->getAnalyzedDirs(' '),
            'extensions' => $this->config->csv('extensions')
        );
        if ($this->tool->errorsType) {
            $args[] = '-n';
        }
        if ($this->options->isSavedToFiles) {

https://patch-diff.githubusercontent.com/raw/EdgedesignCZ/phpqa/pull/120.patch

@zdenekdrahos
Copy link
Member

Can't reproduce it.

$ phpqa tools | grep phpcs
| phpcs            | 3.2.3         | Greg Sherwood
# add some long line to one file

$ cat .phpqa.yml | grep ignoreWarnings
    ignoreWarnings: true
$ bin/ci.sh 2>/dev/null | grep "| phpcs"
| phpcs | 0              | 0            || build//phpcs.html |

$ 
$ cat .phpqa.yml | grep ignoreWarnings
    ignoreWarnings: false
$ bin/ci.sh 2>/dev/null | grep "| phpcs"
| phpcs | 0              | 1            | x      | build//phpcs.html |

Anyway I don't like using -n because warnings are not included in html report. I want to see them in report, but ignore them for evaluating exit code. Take a look at original issue #53.

@Moosh-be
Copy link
Author

Moosh-be commented Mar 2, 2018

hum ok, I retry. I search where I make a mistake

@Moosh-be Moosh-be closed this as completed Mar 2, 2018
@Moosh-be
Copy link
Author

Moosh-be commented Mar 3, 2018

Ok
Locally

[phpqa]
+------------------+-------------------+-----------+--------+--+
| Tool | Allowed exit code | Exit code | Is OK? | |
+------------------+-------------------+-----------+--------+--+
| phpcs | 0 | 0 | ✓ | |
| parallel-lint | 0 | 0 | ✓ | |
| security-checker | | 0 | ✓ | |
+------------------+-------------------+-----------+--------+--+
| phpqa | | 0 | ✓ | |
+------------------+-------------------+-----------+--------+--+

[phpqa] No failed tools

Same run in travis

"/home/travis/build/RTBF/cryo-radio-classic21/vendor/edgedesign/phpqa/../../../vendor/bin/phpcs" -p --standard="/home/travis/build/RTBF/cryo-radio-classic21/phpcs.xml.dist" --ignore=/vendor/ "./" --extensions=php --report-full --report-gitblame

[phpqa]
+------------------+-------------------+-----------+--------+--+
| Tool | Allowed exit code | Exit code | Is OK? | |
+------------------+-------------------+-----------+--------+--+
| phpcs | 0 | 1 | x | |
| parallel-lint | 0 | 0 | ✓ | |
| security-checker | | 0 | ✓ | |
+------------------+-------------------+-----------+--------+--+
| phpqa | | 1 | x | |
+------------------+-------------------+-----------+--------+--+
[phpqa] Failed tools: phpcs

@Moosh-be Moosh-be reopened this Mar 3, 2018
@Moosh-be
Copy link
Author

Moosh-be commented Mar 3, 2018

I've try to run cs standalone and in qa in same travis run.

ocramius/package-versions: ...done generating version class
before_script.1
$ vendor/bin/phpqa --version
Robo 1.2.2
before_script.2
$ vendor/bin/phpqa tools
+------------------+---------------+----------------------------------------------+
| Tool             | Version       | Authors / Info                               |
+------------------+---------------+----------------------------------------------+
| phpqa            | 1.18          | Zdeněk Drahoš                                |
| phpmetrics       | 2.3.2         | Jean-François Lépine                         |
| phploc           | 4.0.1         | Sebastian Bergmann                           |
| phpcs            | 3.2.3         | Greg Sherwood                                |
| php-cs-fixer     | 2.10.3        | Dariusz Rumiński,Fabien Potencier            |
| phpmd            | 2.6.0         | Manuel Pichler,Other contributors,Marc Würth |
| pdepend          | 2.5.2         |                                              |
| phpcpd           | 3.0.1         | Sebastian Bergmann                           |
| parallel-lint    | 0.9.2         | Jakub Onderka                                |
| phpstan          | 0.9.2         |                                              |
| phpunit          | not installed | composer require phpunit/phpunit             |
| psalm            | 0.3.93        | Matthew Brown                                |
| security-checker | 4.1.8         | Fabien Potencier                             |
+------------------+---------------+----------------------------------------------+
before_script.3
$ vendor/bin/parallel-lint --help | head -n 1
PHP Parallel Lint version 0.9.1
before_script.4
$ vendor/bin/phpcs --version
PHP_CodeSniffer version 3.2.3 (stable) by Squiz (http://www.squiz.net)
before_script.5
$ vendor/bin/security-checker -V
SensioLabs Security Checker 4
$ vendor/bin/phpqa --output=cli --tools parallel-lint:0,phpcs:0,security-checker
 [Edge\QA\Task\ParallelExec] "/home/travis/build/RTBF/cryo-radio-classic21/vendor/edgedesign/phpqa/../../../vendor/bin/phpcs" -p --standard="/home/travis/build/RTBF/cryo-radio-classic21/phpcs.xml.dist"  --ignore=*/vendor/* "./" --extensions=php --report-full --report-gitblame
 [Edge\QA\Task\ParallelExec] "/home/travis/build/RTBF/cryo-radio-classic21/vendor/edgedesign/phpqa/../../../vendor/bin/parallel-lint"  --exclude vendor -e php "./"
 [Edge\QA\Task\ParallelExec] "/home/travis/build/RTBF/cryo-radio-classic21/vendor/edgedesign/phpqa/../../../vendor/bin/security-checker" security:check ./composer.lock --end-point=http://security.sensiolabs.org/check_lock
 [Edge\QA\Task\ParallelExec] Output for "/home/travis/build/RTBF/cryo-radio-classic21/vendor/edgedesign/phpqa/../../../vendor/bin/security-checker" security:check ./composer.lock --end-point=http://security.sensiolabs.org/check_lock:

(...)

 [Edge\QA\Task\ParallelExec] Output for "/home/travis/build/RTBF/cryo-radio-classic21/vendor/edgedesign/phpqa/../../../vendor/bin/phpcs" -p --standard="/home/travis/build/RTBF/cryo-radio-classic21/phpcs.xml.dist"  --ignore=*/vendor/* "./" --extensions=php --report-full --report-gitblame:
..............W...................W.... 39 / 39 (100%)

(...)

[phpqa] 
+------------------+-------------------+-----------+--------+--+
| Tool             | Allowed exit code | Exit code | Is OK? |  |
+------------------+-------------------+-----------+--------+--+
| phpcs            | 0                 | 1         | x      |  |
| parallel-lint    | 0                 | 0         | ✓      |  |
| security-checker |                   | 0         | ✓      |  |
+------------------+-------------------+-----------+--------+--+
| phpqa            |                   | 1         | x      |  |
+------------------+-------------------+-----------+--------+--+
[phpqa] Failed tools: phpcs
The command "vendor/bin/phpqa --output=cli --tools parallel-lint:0,phpcs:0,security-checker" exited with 1.
$ vendor/bin/phpcs --warning-severity=0 .
....................................... 39 / 39 (100%)
Time: 436ms; Memory: 4Mb

@Moosh-be
Copy link
Author

Moosh-be commented Mar 3, 2018

OK I've found "WHY"

because I add --output=cli, the check fail.

but only on travis run.
I can't reproduce this locally.


travis@travis-job-rtbf-cryo-radio-cla-113024964:~/build/RTBF/cryo-radio-classic21$ vendor/bin/phpqa --output=cli --tools phpcs:0                                                                                  
 [Edge\QA\Task\ParallelExec] "/home/travis/build/RTBF/cryo-radio-classic21/vendor/edgedesign/phpqa/../../../vendor/bin/phpcs" -p --standard="/home/travis/build/RTBF/cryo-radio-classic21/phpcs.xml.dist"  --ignore=*/vendor/* "./" --extensions=php --report-full --report-gitblame
 [Edge\QA\Task\ParallelExec] Output for "/home/travis/build/RTBF/cryo-radio-classic21/vendor/edgedesign/phpqa/../../../vendor/bin/phpcs" -p --standard="/home/travis/build/RTBF/cryo-radio-classic21/phpcs.xml.dist"  --ignore=*/vendor/* "./" --extensions=php --report-full --report-gitblame:

..............W...................W.... 39 / 39 (100%)

(...)


 [Edge\QA\Task\ParallelExec]  Exit code 1  Time 0.853s

[phpqa] 
+-------+-------------------+-----------+--------+--+
| Tool  | Allowed exit code | Exit code | Is OK? |  |
+-------+-------------------+-----------+--------+--+
| phpcs | 0                 | 1         | x      |  |
+-------+-------------------+-----------+--------+--+
| phpqa |                   | 1         | x      |  |
+-------+-------------------+-----------+--------+--+

[phpqa] Failed tools: phpcs
travis@travis-job-rtbf-cryo-radio-cla-113024964:~/build/RTBF/cryo-radio-classic21$ vendor/bin/phpqa --tools phpcs:0                                                                                               
 [Filesystem\CleanDir] Cleaned build/
 [Filesystem\FilesystemStack] mkdir ["build/"]
 [Edge\QA\Task\ParallelExec] "/home/travis/build/RTBF/cryo-radio-classic21/vendor/edgedesign/phpqa/../../../vendor/bin/phpcs" -p --standard="/home/travis/build/RTBF/cryo-radio-classic21/phpcs.xml.dist"  --ignore=*/vendor/* "./" --extensions=php --report-checkstyle="build//checkstyle.xml"
 [Edge\QA\Task\ParallelExec]  '"/home/travis/build/RTBF/cryo-radio-classic21/vendor/edgedesign/phpqa/../../../vendor/bin/phpcs" -p --standard="/home/travis/build/RTBF/cryo-radio-classic21/phpcs.xml.dist"  --ignore=*/vendor/* "./" --extensions=php --report-checkstyle="build//checkstyle.xml"' exited with code 1 
  Time 0.504s
 [Edge\QA\Task\ParallelExec]  Exit code 1  Time 0.504s

[phpqa] 
+-------+----------------+--------------+--------+-------------------+
| Tool  | Allowed Errors | Errors count | Is OK? | HTML report       |
+-------+----------------+--------------+--------+-------------------+
| phpcs | 0              | 0            | ✓      |                   |
+-------+----------------+--------------+--------+-------------------+
| phpqa |                | 0            | ✓      | build//phpqa.html |
+-------+----------------+--------------+--------+-------------------+

[phpqa] No failed tools

@zdenekdrahos
Copy link
Member

You are right, ignoreWarnings works only in html mode.

@zdenekdrahos zdenekdrahos changed the title ignoreWarnings: in my .phpqa.yml seems ignored. phpcs ignoreWarnings does not work in CLI mode Mar 17, 2018
@Moosh-be
Copy link
Author

oh thanks thanks thanks

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

No branches or pull requests

2 participants