Skip to content

PHPCS: Color changed-lines output and annotate violations on the PR diff - #780

Closed
obenland wants to merge 2 commits into
WordPress:trunkfrom
obenland:add/phpcs-colors-annotations
Closed

PHPCS: Color changed-lines output and annotate violations on the PR diff#780
obenland wants to merge 2 commits into
WordPress:trunkfrom
obenland:add/phpcs-colors-annotations

Conversation

@obenland

Copy link
Copy Markdown
Member

The phpcs check renders its two sections differently: new files are reported by phpcs itself, which honors the colors arg in phpcs.xml.dist, while modified files are reported by phpcs-changed, whose reporter has no color support at all — so the changed-lines section prints plain.

  • Colorize the phpcs-changed output in phpcs-branch.php to match phpcs's look: red/yellow ERROR/WARNING labels, bold FILE:/FOUND header lines.
  • Emit inline PR annotations from both sections. Every violation is also printed as a ::error/::warning workflow command with file, line, and column, so it shows up directly on the PR diff view. Modified files annotate under their real path (the report itself is keyed by the temporary scan copy). Outside of GitHub Actions the annotations are skipped, so local runs are unchanged.

Verified locally against seeded violations in a new and a modified file: changed-lines output now carries the same ANSI styling as the phpcs section, and both sections emit correctly escaped workflow commands with accurate paths/lines/columns. Note GitHub caps inline annotations at 10 per type per step; overflow violations still appear in the log output.

🤖 Generated with Claude Code

…iff.

New files are scanned by phpcs itself, whose report honors the colors
arg in phpcs.xml.dist — but modified files get their report rendered by
phpcs-changed, which has no color support at all, leaving that section
of the log plain. Colorize it in the script to match phpcs's look:
red/yellow ERROR/WARNING labels and bold FILE/FOUND headers.

Additionally emit every violation from both paths as a GitHub workflow
command (::error/::warning with file, line, and column), so violations
show up as inline annotations on the PR diff. Modified files report
under their real path rather than the temporary scan copy. Outside of
Actions the annotations are skipped and local output stays unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 10, 2026 21:44
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props obenland.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates the PHPCS PR-check helper script to improve readability and reviewer ergonomics by (1) re-adding ANSI color styling to phpcs-changed output and (2) emitting GitHub Actions inline annotations so violations appear directly on the PR diff.

Changes:

  • Adds ANSI colorization for phpcs-changed log output to match phpcs styling.
  • Adds GitHub Actions workflow-command annotations for PHPCS violations (new files via phpcs JSON, modified files via phpcs-changed JSON).
  • Documents inline annotations behavior in .github/README.md.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
.github/README.md Documents that the PHPCS check emits inline PR annotations in GitHub Actions.
.github/bin/phpcs-branch.php Adds colorized phpcs-changed output and emits GitHub Actions annotations from PHPCS JSON reports.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .github/bin/phpcs-branch.php Outdated
@obenland
obenland force-pushed the add/phpcs-colors-annotations branch from bb7cb0b to bbd23c9 Compare August 10, 2026 21:47
The JSON reports and the second phpcs-changed pass exist solely to feed
GitHub's inline annotations, which are skipped outside of Actions —
gate the report generation the same way so local runs (composer run
phpcs-changed) don't pay for output nothing consumes. Remove the
report file with unlink() instead of shelling out.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 2 changed files in this pull request and generated no new comments.

@bazza bazza closed this in 91b36a6 Aug 10, 2026
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.

2 participants