Opened 6 years ago
Closed 19 months ago
#43764 closed defect (bug) (fixed)
CS: Fix violations for admin-header.php
Reported by: | marcomartins | Owned by: | |
---|---|---|---|
Milestone: | 5.4 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Administration | Keywords: | |
Focuses: | coding-standards | Cc: |
Description
Fixes the coding standard violations for wp-admin/admin-header.php
Ignores the following sniffs:
- Generic.PHP.NoSilencedErrors.Discouraged
- WordPress.NamingConventions.ValidHookName.UseUnderscores
- WordPress.Variables.GlobalVariables.OverrideProhibited
Attachments (3)
Change History (8)
#1
@
6 years ago
@marcomartins Welcome as a new contributor and thank you for your efforts.
I've reviewed the latest patch (3
).
- Based on your patch I realize there is actually an issue with the ruleset as currently committed to core. The
WordPress.Variables.GlobalVariables
sniff is referenced there, but should not be as that sniff should not be part of the core ruleset. Core overwriting Core global variables should always be fine. So this should be fixed in the ruleset, not by usingphpcs:ignore
comments. - The hook names cannot be ignored for "allow for dash in dynamic hook". The handbook is quite clear that dashes are not allowed in hook names: https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#naming-conventions, including dynamic hook names (see the examples) https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#interpolation-for-naming-dynamic-hooks
So there are two options here:
- Either ignore it for the right reasons, i.e. not to break backwards-compatibility.
- Or deprecated the existing hook and introduce a new hook which complies with the naming conventions.
- The
disable
comments can be combined within the hook documentation blocks, like so:<?php /** * Fires when scripts are printed for a specific admin page based on $hook_suffix. * * @since 2.1.0 * * @phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores -- left as is not to break BC. */ do_action( "admin_print_scripts-{$hook_suffix}" ); //phpcs:enable
which is a "cleaner" solution than having a //
comment above the docblock.
#4
@
2 years ago
I wonder if the has-patch
keyword has to be added to this issue.
There are 3 patches.
#5
@
19 months ago
- Milestone changed from Awaiting Review to 5.4
- Resolution set to fixed
- Status changed from new to closed
Hi there, thanks for the ticket!
This appears to be resolved as part of other coding standards fixes:
- [43013] / #43776 removed the
WordPress.Variables.GlobalVariables
sniff from the core ruleset. - [45599] / #47632 addressed the hook names with hyphens.
- [45611] / #47632 removed the error suppression operator from
header()
. - [47219] / #49222 switched to Yoda conditions.
The wp-admin/admin-header.php
file no longer displays any warnings when running WPCS checks.
Note: See
TracTickets for help on using
tickets.
Inline phpcs:ignore moved to its own line or replaced with phpcs:disable.