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

Threshold report: add new YOASTCS_THRESHOLD_EXACT_MATCH constant #375

Merged

Conversation

jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented Apr 4, 2024

The threshold report is used in the YoastCS repos in combination with a (Composer) script which overrules the exit code from PHPCS to only exit with a non-zero exit code when the actual total number of errors/warnings exceeds the expected number of errors/warnings.

This could lead to situations where issues are being fixed in PR A, but the threshold has not been updated (i.e. errors/warnings below threshold). This would not fail a build, which means this could go unnoticed and get merged. This, in turn, then allows for a subsequent PR B to introduce new issues into a codebase without those new issues failing the PHPCS build, as long as the number of new issues being introduced in PR B did not exceed the number of previously fixed issues from PR A.

This is undesired.

This commit adds a new global YOASTCS_THRESHOLD_EXACT_MATCH constant which can be used by the calling script to fail a build with a non-zero exit code when the actual total number of errors/warnings doesn't exactly match the expected number of errors/warnings.

Notes:

  • The old constant is not being removed as that would be a breaking change and would require a major release.
  • I considered deprecating the old YOASTCS_ABOVE_THRESHOLD constant, but having both available provides the calling scripts flexibility to choose which logic to apply. If so desired, the old constant can still be deprecated in a later minor.

Includes a minor tweak to make the values of the constants testable.

The threshold report is used in the YoastCS repos in combination with a (Composer) script which overrules the exit code from PHPCS to only exit with a non-zero exit code when the _actual_ total number of errors/warnings exceeds the _expected_ number of errors/warnings.

This could lead to situations where issues are being fixed in PR A, but the threshold has not been updated (i.e. errors/warnings _below_ threshold). This would not fail a build, which means this could go unnoticed and get merged. This, in turn, then allows for a subsequent PR B to introduce _new issues_ into a codebase without those new issues failing the PHPCS build, as long as the number of new issues being introduced in PR B did not exceed the number of previously _fixed_ issues from PR A.

This is undesired.

This commit adds a new global `YOASTCS_THRESHOLD_EXACT_MATCH` constant which can be used by the calling script to fail a build with a non-zero exit code when the _actual_ total number of errors/warnings doesn't **_exactly_** match the _expected_ number of errors/warnings.

Notes:
* The old constant is not being removed as that would be a breaking change and would require a major release.
* I considered deprecating the old `YOASTCS_ABOVE_THRESHOLD` constant, but having both available provides the calling scripts flexibility to choose which logic to apply.
    If so desired, the old constant can still be deprecated in a later minor.

Includes a minor tweak to make the values of the constants testable.
@jrfnl jrfnl added this to the 3.x Next milestone Apr 4, 2024
@jrfnl jrfnl merged commit ccc28df into develop Apr 4, 2024
29 checks passed
@jrfnl jrfnl deleted the feature/threshold-no-zero-exit-code-on-below-threshold branch April 4, 2024 15:49
@coveralls
Copy link

Coverage Status

coverage: 99.248% (-0.2%) from 99.411%
when pulling 7bed8ba on feature/threshold-no-zero-exit-code-on-below-threshold
into 081c3f5 on develop.

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

Successfully merging this pull request may close these issues.

2 participants