Skip to content

enhancement(checks): add check for changing error reporting configuration#1321

Open
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:enhancement/1272-error-reporting-check
Open

enhancement(checks): add check for changing error reporting configuration#1321
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:enhancement/1272-error-reporting-check

Conversation

@faisalahammad
Copy link
Copy Markdown
Contributor

@faisalahammad faisalahammad commented May 25, 2026

Summary

Adds a new static check to identify cases where plugin code changes PHP error reporting or WordPress debug configuration at runtime. This prevents plugins from disrupting global debug configurations or hiding critical errors in production environments.

Fixes #1272

Changes

phpcs-sniffs/PluginCheck/Sniffs/CodeAnalysis/ErrorReportingSniff.php

Before:
(New file)

After:

final class ErrorReportingSniff extends Sniff {
	public function register() {
		return array( T_STRING );
	}
	public function process_token( $stackPtr ) {
		// ...
	}
}

Why: Employs precise AST token analysis to safely detect error_reporting(), ini_set(), ini_alter(), and define() modifying runtime debugging configuration while completely avoiding false positives from string literals or comments.

includes/Checker/Checks/General/Error_Reporting_Check.php

Before:
(New file)

After:

class Error_Reporting_Check extends Abstract_PHP_CodeSniffer_Check {
	protected function get_args( Check_Result $result ) {
		return array(
			'extensions' => 'php',
			'standard'   => 'PluginCheck',
			'sniffs'     => 'PluginCheck.CodeAnalysis.ErrorReporting',
		);
	}
}

Why: Exposes the new CodeAnalysis sniff as a high-priority notice/warning under the General and Plugin Repo categories.

includes/Checker/Default_Check_Repository.php

Before:

				'i18n_usage'                 => new Checks\General\I18n_Usage_Check(),
				'enqueued_scripts_size'      => new Checks\Performance\Enqueued_Scripts_Size_Check(),

After:

				'i18n_usage'                 => new Checks\General\I18n_Usage_Check(),
				'error_reporting'            => new Checks\General\Error_Reporting_Check(),
				'enqueued_scripts_size'      => new Checks\Performance\Enqueued_Scripts_Size_Check(),

Why: Registers the new check within the default check repository.

Testing

Test 1: Run Unit Tests

  1. Run npm run test-php -- --filter Error_Reporting_Check_Tests

Result: Works as expected (2 tests, 7 assertions passed)

- Add ErrorReportingSniff to phpcs-sniffs
- Add Error_Reporting_Check to core checks
- Add PHPUnit unit tests and dummy plugins for verification

Fixes WordPress#1272
@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.

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: faisalahammad <faisalahammad@git.wordpress.org>
Co-authored-by: davidperezgar <davidperez@git.wordpress.org>

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

@davidperezgar
Copy link
Copy Markdown
Member

Wow Faisal, thanks for the quick response. I'll check the PR.

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.

Add check for changing error reporting configuration in plugin code

2 participants