Skip to content

Conversation

@redscar
Copy link
Contributor

@redscar redscar commented Aug 2, 2024

This PR focuses on overhauling the PHPCS logic.

While working on projects such as the plugin consolidation, I've noticed a few issues:

Issues Identified

False Positives

  • When the JSON output from PHPCS fails to parse, the test erroneously passes as successful.
  • A large number of files causes PHPCS to fail, leading to incomplete code analysis.
  • File names containing spaces cause PHPCS to fail, interrupting the workflow.

Reviewdog Integration

  • When PHPCS fails, Reviewdog doesn't trigger, leading to missed code quality checks.

Improvements Implemented

To address these issues, the following changes have been made:

  1. Early Failure for Files with Spaces

    • The workflow now checks for files with spaces in their names and fails early with an appropriate message.
  2. Batch Processing

    • Files are processed in batches of 50 to prevent PHPCS from failing due to a large number of files.
  3. Improved JSON Handling

    • Added checks to ensure the JSON output from PHPCS is valid. If the JSON fails to parse, the workflow exits with an error, ensuring no false positives.
  4. Debugging Capability

    • Introduced a DEBUG flag to enable detailed logging and debugging when needed. This helps in troubleshooting issues during the workflow execution.
  5. Consistent Reviewdog Trigger

    • Ensured that Reviewdog is triggered correctly when PHPCS fails, so code quality issues are always reported.

Detailed Changes

  • PHPCS Execution

    • Modified the PHPCS execution logic to handle large sets of files by batching.
    • Added validation for JSON output from PHPCS to avoid false positives.
  • Error Handling

    • Implemented early failure checks for files with spaces in their names.
  • Debugging Enhancements

    • Added a DEBUG flag to provide detailed logging for easier troubleshooting.
  • Reviewdog Integration

    • Ensured Reviewdog triggers correctly on PHPCS failures to maintain code quality checks.

Testing

  • Tested the updated workflow with various scenarios, including files with spaces, large sets of files, and invalid JSON outputs from PHPCS.
  • Verified that Reviewdog correctly reports issues when PHPCS fails.

These changes aim to improve the reliability and accuracy of the PHPCS checks, ensuring better code quality and easier debugging.

Example PR
https://github.com/the-events-calendar/events-community/pull/698

redscar added 3 commits August 2, 2024 13:05
- Fail early if files contain spaces
- Batch files in groups of 50 for processing
- Add debugging capability with a flag
Copy link
Member

@dpanta94 dpanta94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks really good! 🌮 Left some comments

@redscar redscar requested a review from dpanta94 August 2, 2024 18:46
@redscar redscar self-assigned this Aug 2, 2024
@redscar redscar merged commit 04ce296 into main Aug 23, 2024
@redscar redscar deleted the innovation/better_phpcs_handling branch August 23, 2024 15:57
@redscar redscar restored the innovation/better_phpcs_handling branch August 26, 2024 14:51
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.

4 participants