-
-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PrefixAllGlobals: verify that namespace names use a prefix
Until now, namespaced classes, functions and constants would be exempt from the "prefix all globals" rule, but the namespace name _itself_ was not examined. As namespace names can, of course, also conflict, the namespace name should be prefixed with a plugin/theme specific prefix. This PR adds that feature to the sniff. The PR builds onto the changes made in PR 1491 and 1492. Notes: * 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 the value of the custom property, a namespace name of `My\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.
- Loading branch information
Showing
4 changed files
with
115 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.4.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes acronym,tgmpa,test_this,test\that | ||
|
||
namespace TGMPA; | ||
|
||
namespace Acronym\B\C; | ||
|
||
namespace AcronymPlugin\B\C; | ||
|
||
namespace Test_This\C; | ||
|
||
namespace Test\This\C; | ||
|
||
namespace Test\That\C; | ||
|
||
namespace Test \ /* comment */ This \ C; | ||
|
||
namespace A\B\C; // Bad. | ||
|
||
use namespace\DEF; // Not our target. | ||
namespace\cname::method(); // Not our target. | ||
$acronym_result = namespace \ blah \ mine(); // Not our target. | ||
|
||
// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes wordpress | ||
namespace wordpress\myplugin; | ||
|
||
// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes wordpress\myplugin | ||
namespace wordpress\myplugin; | ||
|
||
// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters