Skip to content

Suppress PHPCS auto_detect_line_endings deprecation notice#1371

Open
GeorgeWebDevCy wants to merge 1 commit into
WordPress:trunkfrom
GeorgeWebDevCy:fix/phpcs-auto-detect-line-endings-deprecation
Open

Suppress PHPCS auto_detect_line_endings deprecation notice#1371
GeorgeWebDevCy wants to merge 1 commit into
WordPress:trunkfrom
GeorgeWebDevCy:fix/phpcs-auto-detect-line-endings-deprecation

Conversation

@GeorgeWebDevCy

@GeorgeWebDevCy GeorgeWebDevCy commented Jun 21, 2026

Copy link
Copy Markdown

Summary

  • Suppress the known PHPCS auto_detect_line_endings is deprecated notice while PHPCS runs.
  • Delegate all other errors to the previously registered error handler.
  • Add a regression test with a custom error handler that would throw if the PHPCS deprecation leaks through.

Fixes #1368.

Testing

  • php -l includes/Checker/Checks/Abstract_PHP_CodeSniffer_Check.php
  • php -l tests/phpunit/tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.php
  • vendor/bin/phpcs --standard=phpcs.xml.dist includes/Checker/Checks/Abstract_PHP_CodeSniffer_Check.php tests/phpunit/tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.php
  • PHP 8.4 Docker harness running the PHPCS-backed check with an outer handler that throws on auto_detect_line_endings is deprecated: errors=0 warnings=0
Open WordPress Playground Preview

@github-actions

github-actions Bot commented Jun 21, 2026

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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: GeorgeWebDevCy <orionaselite@git.wordpress.org>
Co-authored-by: ernilambar <nilambar@git.wordpress.org>
Co-authored-by: Tsjippy <tsjippy@git.wordpress.org>

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

@ernilambar

Copy link
Copy Markdown
Member

Instead of suppressing may be we should explore why it is coming.

@GeorgeWebDevCy

Copy link
Copy Markdown
Author

Thanks, I explored that path.

What I found:

  • The notice comes from PHPCS itself: vendor/squizlabs/php_codesniffer/src/Runner.php calls @ini_set( "auto_detect_line_endings", true ) during Runner::init().
  • The repo is already on the latest PHPCS 3.x release, squizlabs/php_codesniffer 3.13.5, and that call is still present there.
  • I checked whether moving to PHPCS 4 would avoid needing this, but it is currently blocked by the dependency graph: automattic/vipwpcs, wp-coding-standards/wpcs, plugin-check/phpcs-sniffs, and slevomat/coding-standard all constrain PHPCS to 3.x in the installed versions.
  • The deprecation leaks when a site/plugin has a custom error handler that still receives suppressed @ini_set() deprecations, which matches the stack trace in error: auto_detect_line_endings is deprecated #1368.

So this PR keeps the workaround narrowly scoped to the PHPCS runner call and only swallows this exact PHPCS deprecation from Runner.php; everything else is delegated back to the previously registered error handler.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request addresses a PHP 8.4+ deprecation notice (auto_detect_line_endings is deprecated) emitted by PHP_CodeSniffer during Plugin Check’s PHPCS-backed checks, by temporarily intercepting that specific deprecation while PHPCS runs and validating the behavior via a regression test.

Changes:

  • Register a temporary error handler around PHPCS execution to suppress the specific auto_detect_line_endings deprecation originating from PHPCS’s Runner.php.
  • Restore the prior error handler after PHPCS completes.
  • Add a PHPUnit regression test that installs an outer error handler which would throw if the deprecation leaks through.

Reviewed changes

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

File Description
includes/Checker/Checks/Abstract_PHP_CodeSniffer_Check.php Adds a scoped error handler around PHPCS execution to suppress the targeted deprecation and restore prior handling afterward.
tests/phpunit/tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.php Adds a regression test to ensure the PHPCS deprecation does not leak through an outer error handler.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 113 to 125
@@ -118,6 +120,8 @@ final public function run( Check_Result $result ) {
} catch ( Exception $e ) {
$_SERVER['argv'] = $orig_cmd_args;
throw $e;
} finally {
restore_error_handler();
}
Comment on lines +170 to +178
set_error_handler(
static function ( $errno, $errstr, $errfile, $errline ) {
if ( E_DEPRECATED === $errno && false !== strpos( $errstr, 'auto_detect_line_endings is deprecated' ) ) {
throw new ErrorException( $errstr, 0, $errno, $errfile, $errline );
}

return false;
}
);
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.

error: auto_detect_line_endings is deprecated

3 participants