1.2.0
版本发布时间: 2018-11-12 18:16:02
WordPress/WordPress-Coding-Standards最新发布版本:3.1.0(2024-03-26 00:44:32)
Added
- New
WordPress.PHP.TypeCasts
sniff to theWordPress-Core
ruleset. This new sniff checks that PHP type casts are:- lowercase;
- short form, i.e.
(bool)
not(boolean)
; - normalized, i.e.
(float)
not(real)
. Additionally, the new sniff discourages the use of the(unset)
and(binary)
type casts.
- New
WordPress.Utils.I18nTextDomainFixer
sniff which can compehensively replace/addtext-domain
s in a plugin or theme. Important notes:- This sniff is disabled by default and intended as a utility tool.
- The sniff will fix the text domains in all I18n function calls as well as in a plugin/theme
Text Domain:
header. - Passing the following properties will activate the sniff:
-
old_text_domain
: an array with one or more (old) text domains which need to be replaced; -
new_text_domain
: the correct (new) text domain as a string.
-
- The
WordPress.NamingConventions.PrefixAllGlobals
sniff will now also verify that namespace names use a valid prefix.- The sniff allows for underscores and (other) non-word characters in a passed prefix to be converted to namespace separators when used in a namespace name.
In other words, if a prefix of
my_plugin
is passed as a value to theprefixes
property, a namespace name of bothMy\Plugin
as well asMy_Plugin\\
, will be accepted automatically. - Passing a prefix property value containing namespace separators will now also be allowed and will no longer trigger a warning.
- The sniff allows for underscores and (other) non-word characters in a passed prefix to be converted to namespace separators when used in a namespace name.
In other words, if a prefix of
-
WordPress
to the prefix blacklist for theWordPress.NamingConventions.PrefixAllGlobals
sniff. While the prefix cannot beWordPress
, a prefix can still start with or containWordPress
. - Additional unit tests covering a change in the tokenizer which will be included in the upcoming
PHP_CodeSniffer
3.4.0 release. - A variety of issue templates for use on GitHub.
Changed
- The
Sniff::valid_direct_scope()
method will now return the$stackPtr
to the valid scope if a valid direct scope has been detected. Previously, it would returntrue
. - Minor hardening and efficiency improvements to the
WordPress.NamingConventions.PrefixAllGlobals
sniff. - The inline documentation of the
WordPress-Core
ruleset has been updated to be in line again with the handbook. - The inline links to documentation about the VIP requirements have been updated.
- Updated the custom ruleset example to recommend using
PHPCompatibilityWP
rather thanPHPCompatibility
. - All sniffs are now also being tested against PHP 7.3 for consistent sniff results.
Note: PHP 7.3 is only supported in combination with PHPCS 3.3.1 or higher as
PHP_CodeSniffer
itself has an incompatibility in earlier versions. - Minor grammar fixes in text strings and documentation.
- Minor consistency improvement for the unit test case files.
- Minor tweaks to the
composer.json
file. - Updated the PHPCompatibility
dev
dependency.
Removed
- The
WordPress.WhiteSpace.CastStructureSpacing.NoSpaceAfterCloseParenthesis
error code as an error for the same issue was already being thrown by an included upstream sniff.
Fixed
- The
WordPress.CodeAnalysis.EmptyStatement
would throw a false positive for an empty condition in afor()
statement. - The
Sniff::is_class_property()
method could, in certain circumstances, incorrectly recognize parameters in a method declaration as class properties. It would also, incorrectly, fail to recognize class properties when the object they are declared in, was nested in parentheses. This affected, amongst others, theGlobalVariablesOverride
sniff. - The
Sniff::get_declared_namespace_name()
method could get confused over whitespace and comments within a namespace name, which could lead to incorrect results (mostly underreporting). This affected, amongst others, theGlobalVariablesOverride
sniff. The return value of the method will now no longer contain any whitespace or comments encountered. - The
Sniff::has_whitelist_comment()
method would sometimes incorrectly regard// phpcs:set
comments as whitelist comments.