Umherirrender has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/370232 )
Change subject: Enforce "short" type definitions on @param in comments ...................................................................... Enforce "short" type definitions on @param in comments Bug: T145162 Change-Id: Idbbb8e1c09a6af9732897b6d7495a3f5e2f49cb7 --- M MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php M MediaWiki/Tests/files/Commenting/commenting_function.php.expect M MediaWiki/Tests/files/Commenting/commenting_function.php.fixed M MediaWiki/Tests/files/generic_namespace_pass.php 4 files changed, 44 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/codesniffer refs/changes/32/370232/1 diff --git a/MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php b/MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php index 9fdc490..e228825 100644 --- a/MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php +++ b/MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php @@ -411,6 +411,36 @@ $phpcsFile->addError( $error, $param['tag'], 'ExtraParamComment' ); } // end if + // Check the short type of boolean and integer + if ( $param['type'] === 'boolean' ) { + $fix = $phpcsFile->addFixableError( + 'Short type of "bool" should be used for @param tag', + $param['tag'], + 'NotShortBoolParam' + ); + if ( $fix === true ) { + $content = 'bool'; + $content .= str_repeat( ' ', $param['type_space'] ); + $content .= $param['var']; + $content .= str_repeat( ' ', $param['var_space'] ); + $content .= $param['comment']; + $phpcsFile->fixer->replaceToken( ( $param['tag'] + 2 ), $content ); + } + } elseif ( $param['type'] === 'integer' ) { + $fix = $phpcsFile->addFixableError( + 'Short type of "int" should be used for @param tag', + $param['tag'], + 'NotShortIntParam' + ); + if ( $fix === true ) { + $content = 'int'; + $content .= str_repeat( ' ', $param['type_space'] ); + $content .= $param['var']; + $content .= str_repeat( ' ', $param['var_space'] ); + $content .= $param['comment']; + $phpcsFile->fixer->replaceToken( ( $param['tag'] + 2 ), $content ); + } + } if ( $param['comment'] === '' ) { continue; } diff --git a/MediaWiki/Tests/files/Commenting/commenting_function.php.expect b/MediaWiki/Tests/files/Commenting/commenting_function.php.expect index fe8b805..46f702c 100644 --- a/MediaWiki/Tests/files/Commenting/commenting_function.php.expect +++ b/MediaWiki/Tests/files/Commenting/commenting_function.php.expect @@ -8,6 +8,10 @@ | | (MediaWiki.Commenting.FunctionComment.SpacingAfterParamName) 23 | ERROR | [x] Expected 1 spaces after parameter name; 3 found | | (MediaWiki.Commenting.FunctionComment.SpacingAfterParamName) + 31 | ERROR | [x] Short type of "bool" should be used for @param tag + | | (MediaWiki.Commenting.FunctionComment.NotShortBoolParam) + 32 | ERROR | [x] Short type of "int" should be used for @param tag + | | (MediaWiki.Commenting.FunctionComment.NotShortIntParam) 33 | ERROR | [x] Short type of "bool" should be used for @return tag | | (MediaWiki.Commenting.FunctionComment.NotShortBoolReturn) 40 | ERROR | [x] Short type of "int" should be used for @return tag @@ -16,9 +20,13 @@ | | (MediaWiki.Commenting.FunctionComment.MissingReturn) 59 | ERROR | [ ] Missing parameter comment | | (MediaWiki.Commenting.FunctionComment.MissingParamComment) + 59 | ERROR | [x] Short type of "bool" should be used for @param tag + | | (MediaWiki.Commenting.FunctionComment.NotShortBoolParam) 60 | ERROR | [ ] Missing parameter comment | | (MediaWiki.Commenting.FunctionComment.MissingParamComment) + 60 | ERROR | [x] Short type of "int" should be used for @param tag + | | (MediaWiki.Commenting.FunctionComment.NotShortIntParam) 61 | ERROR | [x] Short type of "bool" should be used for @return tag | | (MediaWiki.Commenting.FunctionComment.NotShortBoolReturn) -PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY +PHPCBF CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY diff --git a/MediaWiki/Tests/files/Commenting/commenting_function.php.fixed b/MediaWiki/Tests/files/Commenting/commenting_function.php.fixed index ebc9665..79ea675 100644 --- a/MediaWiki/Tests/files/Commenting/commenting_function.php.fixed +++ b/MediaWiki/Tests/files/Commenting/commenting_function.php.fixed @@ -28,8 +28,8 @@ } /** - * @param boolean $aBool A bool - * @param integer $anInt An int + * @param bool $aBool A bool + * @param int $anInt An int * @return bool And some text */ public function testLongTypes( $aBool, $anInt ) { @@ -56,8 +56,8 @@ } /** - * @param boolean $aBool - * @param integer $anInt + * @param bool $aBool + * @param int $anInt * @return bool */ public function testLongTypesNoComment( $aBool, $anInt ) { diff --git a/MediaWiki/Tests/files/generic_namespace_pass.php b/MediaWiki/Tests/files/generic_namespace_pass.php index b172ecf..5e897d3 100644 --- a/MediaWiki/Tests/files/generic_namespace_pass.php +++ b/MediaWiki/Tests/files/generic_namespace_pass.php @@ -5,7 +5,7 @@ /** * Some comment in a block :D * - * @param boolean $outputtype The type of output. + * @param bool $outputtype The type of output. * @param int $ts The timestamp. * @return null */ -- To view, visit https://gerrit.wikimedia.org/r/370232 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idbbb8e1c09a6af9732897b6d7495a3f5e2f49cb7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/tools/codesniffer Gerrit-Branch: master Gerrit-Owner: Umherirrender <umherirrender_de...@web.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits