Skip to content

fix: phpcs error parse issue by running phpcs in quiet mode#385

Open
mi5t4n wants to merge 1 commit intoAutomattic:trunkfrom
mi5t4n:fix/384
Open

fix: phpcs error parse issue by running phpcs in quiet mode#385
mi5t4n wants to merge 1 commit intoAutomattic:trunkfrom
mi5t4n:fix/384

Conversation

@mi5t4n
Copy link

@mi5t4n mi5t4n commented Feb 22, 2024

This PR fixes when the phpcs reports the errors but fails to parse the generated JSON errors, by adding -q argument to the phpcs command.

Details

Currently, vip-go-ci is being used in the project's workflow. The workflow was succeeding even though phpcs was reporting errors and the workflow was also failing to add PR comments as well.

Log

[ 2024-02-20T17:59:30+00:00 GMT -- 0 ]  "Running PHPCS now"; {
    "cmd": "php -d memory_limit=500M -d max_execution_time=300 \/home\/samplebot\/vip-go-ci-tools\/phpcs\/bin\/phpcs --severity='1' --report='json' --standard='\/home\/samplebot\/workspace\/phpcs.xml' --exclude='WordPress.Files.FileName' '\/tmp\/vipgoci-phpcs-scan-aaqkfY.php'"
}
[ 2024-02-20T17:59:31+00:00 GMT -- 0 ]  "Error when running PHPCS"; {
    "filename": "plugins\/sample-plugin\/inc\/classes\/class-plugin.php",
    "file_issues_str": "\u001b[31mE\u001b[0m 1 \/ 1 (100%)\n\n\n{\"totals\":{\"errors\":1,\"warnings\":0,\"fixable\":0},\"files\":{\"\\\/tmp\\\/vipgoci-phpcs-scan-aaqkfY.php\":{\"errors\":1,\"warnings\":0,\"messages\":[{\"message\":\"Mismatched text domain. Expected 'example' or 'example-plugin' but got 'johndoe'.\",\"source\":\"WordPress.WP.I18n.TextDomainMismatch\",\"severity\":5,\"fixable\":false,\"type\":\"ERROR\",\"line\":45,\"column\":26}]}}}",
    "issues_stats": null
}
[ 2024-02-20T17:59:31+00:00 GMT -- 0 ]  "Fetching file-contents from local Git repository"; {
    "repo_owner": "janedoe",
    "repo_name": "example",
    "commit_id": "<commit-id-1>",
    "filename": "plugins\/sample-plugin\/inc\/classes\/class-plugin.php",
    "local_git_repo": "\/home\/samplebot\/workspace"
}
[ 2024-02-20T17:59:31+00:00 GMT -- 0 ]  "Failed parsing output from PHPCS"; {
    "repo_owner": "janedoe",
    "repo_name": "example",
    "commit_id": "<commit-id-2>",
    "file_name": "plugins\/sample-plugin\/inc\/classes\/class-plugin.php",
    "file_issues_arr_master": null,
    "file_issues_str": "\u001b[31mE\u001b[0m 1 \/ 1 (100%)\n\n\n{\"totals\":{\"errors\":1,\"warnings\":0,\"fixable\":0},\"files\":{\"\\\/tmp\\\/vipgoci-phpcs-scan-aaqkfY.php\":{\"errors\":1,\"warnings\":0,\"messages\":[{\"message\":\"Mismatched text domain. Expected 'example' or 'example-plugin' but got 'johndoe'.\",\"source\":\"WordPress.WP.I18n.TextDomainMismatch\",\"severity\":5,\"fixable\":false,\"type\":\"ERROR\",\"line\":45,\"column\":26}]}}}"
}

As you can see, the phpcs is reporting errors but the errors parsing is failing, which resulted in no errors being reported.

Cause

The phpcs.xml configuration file has a configuration which show the progress of the phpcs scan.

<arg value="sp"/>

Solution

By adding -q to the phpcs command, we can override the behaviors and suppress the progress report, and fix the error parsing issue.

TODO:

  • Added patch for [describe issue]
  • Add/update tests -- unit/integrated/E2E (if needed)
    • Ensure only one function/functionality is tested per test file.
  • New/updated software requirements?
    • Update README.md
    • Update defines.php
  • Add to, or update, Scan run detail report as applicable
  • Check status of automated tests
  • Ensure PHPDoc comments are up to date for functions added or altered
  • Assign appropriate priority and type of change labels.
  • Changelog entry (for VIP)

Closes: #384

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Workflow was succeeding even though phpcs has reported errors.

2 participants