-
-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Streamline WPCS in file documentation. (#651)
* Update the file and class @Package tag and remove the @category tag. Follow the standard as described in https://www.phpdoc.org/docs/latest/references/phpdoc/tags/package.html The @category tag is considered deprecated. A hierarchical @Package tag should be used instead. Ref: https://www.phpdoc.org/docs/latest/references/phpdoc/tags/category.html * Use correct version number for the newly deprecated classes. * Fix some - unintentional - parse errors in the test files. * Attempt to lead by example comment-wise in the unit tests. Capitalization, punctuation and some spelling. * Proper capitalization and punctuation for class end comments. * Remove `//end` comments for methods and conditionals < 35 lines. * Simplify the test file method doc blocks. * Various documentation fixes, largely based on PHPCS Docs output. * Make sure any function which will be passed the $phpcsFile has the right type hint. But only if it doesn't conflict with upstream function signatures. * Verify and update the docblocks for all files and classes. Based on Git file history: * Add @SInCE tags to all classes. * Add @SInCE tags to properties and methods if they weren't included from the start. * Verify/Fix a number of @author tags. * Remove old/copied over/incorrect PHPCS tags. * Where necessary improved/corrected the class description. Also: * Consistent tag order in class doc blocks. * Fix tag alignment. * Remove redundant explanation in unit test class doc blocks. * Sync the description line of the unit test class doc blocks. * Add handbook links to a number of sniffs. * Add reference to upstream sniff a sniff is based upon. Includes information on when the sniff was last synced with the upstream sniff if applicable and available. * Add @license tag and @link tag to the WPCS GH repo, to all file level doc blocks. License tag as per https://www.phpdoc.org/docs/latest/references/phpdoc/tags/license.html * Add the docs ruleset to the coding standard for WPCS itself. * Add @SInCE class changelogs for PR #647. * Fix minor grammar error. * Updated `@since` tags for `2014-12-11` release to `0.3.0`. * Re-instate previously removed @SInCE tags. * Updated based on feedback. * Adjusted the @Package tags as per discussion in the PR thread * Removed the @link tag to the handbook at the file level doc block * Removed the @author tags
- Loading branch information
Showing
133 changed files
with
1,950 additions
and
2,237 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,20 @@ | |
/** | ||
* WordPress Coding Standard. | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer | ||
* @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ | ||
* @package WPCS\WordPressCodingStandards | ||
* @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards | ||
* @license https://opensource.org/licenses/MIT MIT | ||
*/ | ||
|
||
/** | ||
* WordPress_Sniffs_WP_I18nSniff | ||
* Makes sure WP internationalization functions are used properly. | ||
* | ||
* Makes sure internationalization functions are used properly. | ||
* @link https://make.wordpress.org/core/handbook/best-practices/internationalization/ | ||
* @link https://developer.wordpress.org/plugins/internationalization/ | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer | ||
* @author Shady Sharaf <[email protected]> | ||
* @package WPCS\WordPressCodingStandards | ||
* | ||
* @since 0.10.0 | ||
*/ | ||
class WordPress_Sniffs_WP_I18nSniff extends WordPress_Sniff { | ||
|
||
|
@@ -37,6 +38,11 @@ class WordPress_Sniffs_WP_I18nSniff extends WordPress_Sniff { | |
*/ | ||
static $text_domain_override; | ||
|
||
/** | ||
* The I18N functions in use in WP. | ||
* | ||
* @var array <string function name> => <string function type> | ||
*/ | ||
public $i18n_functions = array( | ||
'translate' => 'simple', | ||
'__' => 'simple', | ||
|
@@ -58,13 +64,17 @@ class WordPress_Sniffs_WP_I18nSniff extends WordPress_Sniff { | |
|
||
/** | ||
* These Regexes copied from http://php.net/manual/en/function.sprintf.php#93552 | ||
* | ||
* @var string | ||
*/ | ||
static $sprintf_placeholder_regex = '/(?:%%|(%(?:[0-9]+\$)?[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFos]))/'; | ||
public static $sprintf_placeholder_regex = '/(?:%%|(%(?:[0-9]+\$)?[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFos]))/'; | ||
|
||
/** | ||
* "Unordered" means there's no position specifier: '%s', not '%2$s'. | ||
* | ||
* @var string | ||
*/ | ||
static $unordered_sprintf_placeholder_regex = '/(?:%%|(?:%[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFosxX]))/'; | ||
public static $unordered_sprintf_placeholder_regex = '/(?:%%|(?:%[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFosxX]))/'; | ||
|
||
/** | ||
* Returns an array of tokens this test wants to listen for. | ||
|
@@ -82,7 +92,7 @@ public function register() { | |
* | ||
* @param PHP_CodeSniffer_File $phpcs_file The file being scanned. | ||
* @param int $stack_ptr The position of the current token | ||
* in the stack passed in $tokens. | ||
* in the stack passed in $tokens. | ||
* | ||
* @return void | ||
*/ | ||
|
@@ -211,7 +221,7 @@ public function process( PHP_CodeSniffer_File $phpcs_file, $stack_ptr ) { | |
* Check if supplied tokens represent a translation text string literal. | ||
* | ||
* @param PHP_CodeSniffer_File $phpcs_file The file being scanned. | ||
* @param array $context | ||
* @param array $context Context (@todo needs better description). | ||
* @return bool | ||
*/ | ||
protected function check_argument_tokens( PHP_CodeSniffer_File $phpcs_file, $context ) { | ||
|
@@ -274,8 +284,10 @@ protected function check_argument_tokens( PHP_CodeSniffer_File $phpcs_file, $con | |
* Check for inconsistencies between single and plural arguments. | ||
* | ||
* @param PHP_CodeSniffer_File $phpcs_file The file being scanned. | ||
* @param array $single_context | ||
* @param array $plural_context | ||
* @param int $stack_ptr The position of the current token | ||
* in the stack passed in $tokens. | ||
* @param array $single_context Single context (@todo needs better description). | ||
* @param array $plural_context Plural context (@todo needs better description). | ||
* @return void | ||
*/ | ||
protected function compare_single_and_plural_arguments( PHP_CodeSniffer_File $phpcs_file, $stack_ptr, $single_context, $plural_context ) { | ||
|
@@ -289,7 +301,7 @@ protected function compare_single_and_plural_arguments( PHP_CodeSniffer_File $ph | |
$plural_placeholders = $plural_placeholders[0]; | ||
|
||
// English conflates "singular" with "only one", described in the codex: | ||
// https://codex.wordpress.org/I18n_for_WordPress_Developers#Plurals | ||
// https://codex.wordpress.org/I18n_for_WordPress_Developers#Plurals . | ||
if ( count( $single_placeholders ) < count( $plural_placeholders ) ) { | ||
$error_string = 'Missing singular placeholder, needed for some languages. See https://codex.wordpress.org/I18n_for_WordPress_Developers#Plurals'; | ||
$single_index = $single_context['tokens'][0]['token_index']; | ||
|
@@ -310,7 +322,7 @@ protected function compare_single_and_plural_arguments( PHP_CodeSniffer_File $ph | |
* Check the string itself for problems. | ||
* | ||
* @param PHP_CodeSniffer_File $phpcs_file The file being scanned. | ||
* @param array $context | ||
* @param array $context Context (@todo needs better description). | ||
* @return void | ||
*/ | ||
protected function check_text( PHP_CodeSniffer_File $phpcs_file, $context ) { | ||
|
@@ -348,9 +360,11 @@ protected function check_text( PHP_CodeSniffer_File $phpcs_file, $context ) { | |
} | ||
} | ||
|
||
// NoEmptyStrings. | ||
|
||
// Strip placeholders and surrounding quotes. | ||
/* | ||
* NoEmptyStrings. | ||
* | ||
* Strip placeholders and surrounding quotes. | ||
*/ | ||
$non_placeholder_content = trim( $content, "'" ); | ||
$non_placeholder_content = preg_replace( self::$sprintf_placeholder_regex, '', $non_placeholder_content ); | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,20 +2,22 @@ | |
/** | ||
* Unit test class for WordPress Coding Standard. | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer | ||
* @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ | ||
* @package WPCS\WordPressCodingStandards | ||
* @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards | ||
* @license https://opensource.org/licenses/MIT MIT | ||
*/ | ||
|
||
/** | ||
* Unit test class for the I18nUnit sniff. | ||
* Unit test class for the I18n sniff. | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer | ||
* @author Shady Sharaf <[email protected]> | ||
* @package WPCS\WordPressCodingStandards | ||
* @since 0.10.0 | ||
*/ | ||
class WordPress_Tests_WP_I18nUnitTest extends AbstractSniffUnitTest { | ||
|
||
/** | ||
* Fill in the $text_domain_override property to test domain check functionality. | ||
*/ | ||
protected function setUp() { | ||
// @todo Should be possible via self::$phpcs->setSniffProperty( 'WordPress_Sniffs_WP_I18nSniff', 'text_domain', 'my-slug' ); | ||
WordPress_Sniffs_WP_I18nSniff::$text_domain_override = 'my-slug'; | ||
|
@@ -25,10 +27,7 @@ protected function setUp() { | |
/** | ||
* Returns the lines where errors should occur. | ||
* | ||
* The key of the array should represent the line number and the value | ||
* should represent the number of errors that should occur on that line. | ||
* | ||
* @return array(int => int) | ||
* @return array <int line number> => <int number of errors> | ||
*/ | ||
public function getErrorList() { | ||
return array( | ||
|
@@ -87,10 +86,7 @@ public function getErrorList() { | |
/** | ||
* Returns the lines where warnings should occur. | ||
* | ||
* The key of the array should represent the line number and the value | ||
* should represent the number of warnings that should occur on that line. | ||
* | ||
* @return array(int => int) | ||
* @return array <int line number> => <int number of warnings> | ||
*/ | ||
public function getWarningList() { | ||
return array( | ||
|
@@ -101,6 +97,6 @@ public function getWarningList() { | |
102 => 1, | ||
103 => 1, | ||
); | ||
} // end getWarningList() | ||
} | ||
|
||
} // end class. | ||
} // End class. |
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 |
---|---|---|
|
@@ -2,17 +2,21 @@ | |
/** | ||
* WordPress Coding Standard. | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer | ||
* @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ | ||
* @package WPCS\WordPressCodingStandards | ||
* @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards | ||
* @license https://opensource.org/licenses/MIT MIT | ||
*/ | ||
|
||
/** | ||
* Restricts array assignment of certain keys. | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer | ||
* @author Shady Sharaf <[email protected]> | ||
* @package WPCS\WordPressCodingStandards | ||
* | ||
* @since 0.3.0 | ||
* @since 0.10.0 Class became a proper abstract class. This was already the behaviour. | ||
* Moved the file and renamed the class from | ||
* `WordPress_Sniffs_Arrays_ArrayAssignmentRestrictionsSniff` to | ||
* `WordPress_AbstractArrayAssignmentRestrictionsSniff`. | ||
*/ | ||
abstract class WordPress_AbstractArrayAssignmentRestrictionsSniff extends WordPress_Sniff { | ||
|
||
|
@@ -47,7 +51,7 @@ public function register() { | |
T_DOUBLE_QUOTED_STRING, | ||
); | ||
|
||
} // end register() | ||
} | ||
|
||
/** | ||
* Groups of variables to restrict. | ||
|
@@ -195,4 +199,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { | |
*/ | ||
abstract public function callback( $key, $val, $line, $group ); | ||
|
||
} // end class | ||
} // End class. |
Oops, something went wrong.