jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/383184 )
Change subject: Unwrap types in function docs from {} ...................................................................... Unwrap types in function docs from {} Add sniff for @throws, @param, @return to check for {string} Adds: - NotParenthesisException: Expected parameter type not wrapped in parenthesis; %s and %s found - NotParenthesisParamType: Expected parameter type not wrapped in parenthesis; %s and %s found - NotParenthesisReturnType: Expected parameter type not wrapped in parenthesis; %s and %s found Change-Id: Ib1c7a41c07484f7c3af7f806fbc375df44b543bf --- M MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php M MediaWiki/Tests/files/Commenting/commenting_function.php M MediaWiki/Tests/files/Commenting/commenting_function.php.expect M MediaWiki/Tests/files/Commenting/commenting_function.php.fixed 4 files changed, 129 insertions(+), 52 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php b/MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php index 1e39fcf..b3c7802 100644 --- a/MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php +++ b/MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php @@ -277,6 +277,23 @@ $fixType = true; } } + $matches = []; + if ( preg_match( '/^([{\[]+)(.*)([\]}]+)$/', $type, $matches ) ) { + $error = 'Expected parameter type not wrapped in parenthesis; %s and %s found'; + $data = [ + $matches[1], $matches[3] + ]; + $fix = $phpcsFile->addFixableError( + $error, + $retType, + 'NotParenthesisReturnType', + $data + ); + $type = $matches[2]; + if ( $fix === true ) { + $fixType = true; + } + } // Check the type for short types $explodedType = explode( '|', $type ); foreach ( $explodedType as $index => $singleType ) { @@ -369,6 +386,27 @@ if ( $exception === null ) { $error = 'Exception type missing for @throws tag in function comment'; $phpcsFile->addError( $error, $tag, 'InvalidThrows' ); + } else { + // Check for unneeded parenthesis on exceptions + $matches = []; + if ( preg_match( '/^([{\[]+)(.*)([\]}]+)$/', $exception, $matches ) ) { + $error = 'Expected parameter type not wrapped in parenthesis; %s and %s found'; + $data = [ + $matches[1], $matches[3] + ]; + $fix = $phpcsFile->addFixableError( + $error, + $tag, + 'NotParenthesisException', + $data + ); + if ( $fix === true ) { + $phpcsFile->fixer->replaceToken( + $tag + 2, + $matches[2] . ( $comment === null ? '' : ' ' . $comment ) + ); + } + } } } // end foreach @@ -530,6 +568,27 @@ $phpcsFile->fixer->replaceToken( ( $param['tag'] + 1 ), str_repeat( ' ', $spaces ) ); } } + // Check for unneeded punctation on parameter type + $matches = []; + if ( preg_match( '/^([{\[]+)(.*)([\]}]+)$/', $param['type'], $matches ) ) { + $error = 'Expected parameter type not wrapped in parenthesis; %s and %s found'; + $data = [ + $matches[1], $matches[3] + ]; + $fix = $phpcsFile->addFixableError( + $error, + $param['tag'], + 'NotParenthesisParamType', + $data + ); + if ( $fix === true ) { + $this->replaceParamComment( + $phpcsFile, + $param, + [ 'type' => $matches[2] ] + ); + } + } // Check number of spaces after the type. // $spaces = ( $maxType - strlen( $param['type'] ) + 1 ); $spaces = 1; diff --git a/MediaWiki/Tests/files/Commenting/commenting_function.php b/MediaWiki/Tests/files/Commenting/commenting_function.php index 51dba00..b0a446d 100644 --- a/MediaWiki/Tests/files/Commenting/commenting_function.php +++ b/MediaWiki/Tests/files/Commenting/commenting_function.php @@ -104,11 +104,13 @@ } /** - * @param bool $aBool: A bool - * @param int $anInt: An int - * @return bool: And some text + * @param {bool} $aBool: A bool + * @param [int] $anInt: An int + * @param \float[] $aFloatArray: A float array + * @return {bool}: And some text + * @throws {Exception} */ - public function testVariablePunctation( $aBool, $anInt ) { + public function testVariablePunctation( $aBool, $anInt, $aFloatArray ) { return $aBool; } diff --git a/MediaWiki/Tests/files/Commenting/commenting_function.php.expect b/MediaWiki/Tests/files/Commenting/commenting_function.php.expect index 7fa3bf6..cc41b76 100644 --- a/MediaWiki/Tests/files/Commenting/commenting_function.php.expect +++ b/MediaWiki/Tests/files/Commenting/commenting_function.php.expect @@ -81,86 +81,100 @@ 100 | ERROR | [x] Use @covers tag in function comment instead of | | @cover | | (MediaWiki.Commenting.FunctionComment.SingularCover) + 107 | ERROR | [x] Expected parameter type not wrapped in parenthesis; { + | | and } found + | | (MediaWiki.Commenting.FunctionComment.NotParenthesisParamType) 107 | ERROR | [x] Param name should not end with punctuation ":" | | (MediaWiki.Commenting.FunctionComment.NotPunctuationParam) + 108 | ERROR | [x] Expected parameter type not wrapped in parenthesis; [ + | | and ] found + | | (MediaWiki.Commenting.FunctionComment.NotParenthesisParamType) 108 | ERROR | [x] Param name should not end with punctuation ":" | | (MediaWiki.Commenting.FunctionComment.NotPunctuationParam) - 109 | ERROR | [x] Return type should not end with punctuation ":" + 109 | ERROR | [x] Param name should not end with punctuation ":" + | | (MediaWiki.Commenting.FunctionComment.NotPunctuationParam) + 110 | ERROR | [x] Return type should not end with punctuation ":" | | (MediaWiki.Commenting.FunctionComment.NotPunctuationReturn) - 116 | ERROR | [x] Incorrect capitalization of @inheritDoc + 110 | ERROR | [x] Expected parameter type not wrapped in parenthesis; { + | | and } found + | | (MediaWiki.Commenting.FunctionComment.NotParenthesisReturnType) + 111 | ERROR | [x] Expected parameter type not wrapped in parenthesis; { + | | and } found + | | (MediaWiki.Commenting.FunctionComment.NotParenthesisException) + 118 | ERROR | [x] Incorrect capitalization of @inheritDoc | | (MediaWiki.Commenting.FunctionComment.LowercaseInheritDoc) - 130 | ERROR | [x] Comment star tag not aligned with open tag - | | (MediaWiki.Commenting.FunctionComment.SyntaxAlignedDocStar) - 131 | ERROR | [x] Comment star tag not aligned with open tag - | | (MediaWiki.Commenting.FunctionComment.SyntaxAlignedDocStar) 132 | ERROR | [x] Comment star tag not aligned with open tag | | (MediaWiki.Commenting.FunctionComment.SyntaxAlignedDocStar) - 133 | ERROR | [x] Comment close tag not aligned with open tag + 133 | ERROR | [x] Comment star tag not aligned with open tag + | | (MediaWiki.Commenting.FunctionComment.SyntaxAlignedDocStar) + 134 | ERROR | [x] Comment star tag not aligned with open tag + | | (MediaWiki.Commenting.FunctionComment.SyntaxAlignedDocStar) + 135 | ERROR | [x] Comment close tag not aligned with open tag | | (MediaWiki.Commenting.FunctionComment.SyntaxAlignedDocClose) - 137 | ERROR | [x] Comment open tag must be '/**' + 139 | ERROR | [x] Comment open tag must be '/**' | | (MediaWiki.Commenting.FunctionComment.SyntaxOpenTag) - 137 | ERROR | [x] Expected at least 1 spaces after doc star; 0 found - | | (MediaWiki.Commenting.FunctionComment.SpacingDocStar) - 138 | ERROR | [x] Comment star must be a single '*' - | | (MediaWiki.Commenting.FunctionComment.SyntaxMultiDocStar) - 138 | ERROR | [x] Comment star tag not aligned with open tag - | | (MediaWiki.Commenting.FunctionComment.SyntaxAlignedDocStar) - 138 | ERROR | [x] Expected at least 1 spaces after doc star; 0 found - | | (MediaWiki.Commenting.FunctionComment.SpacingDocStar) - 139 | ERROR | [x] Comment star must be a single '*' - | | (MediaWiki.Commenting.FunctionComment.SyntaxMultiDocStar) - 139 | ERROR | [x] Comment star tag not aligned with open tag - | | (MediaWiki.Commenting.FunctionComment.SyntaxAlignedDocStar) 139 | ERROR | [x] Expected at least 1 spaces after doc star; 0 found | | (MediaWiki.Commenting.FunctionComment.SpacingDocStar) - 140 | ERROR | [x] Comment close tag not aligned with open tag - | | (MediaWiki.Commenting.FunctionComment.SyntaxAlignedDocClose) - 140 | ERROR | [x] Comment close tag must be '*/' - | | (MediaWiki.Commenting.FunctionComment.SyntaxCloseTag) - 144 | ERROR | [x] Comment open tag must be '/**' - | | (MediaWiki.Commenting.FunctionComment.SyntaxOpenTag) - 145 | ERROR | [x] Comment star must be a single '*' + 140 | ERROR | [x] Comment star must be a single '*' | | (MediaWiki.Commenting.FunctionComment.SyntaxMultiDocStar) - 145 | ERROR | [x] Expected at least 1 spaces after doc star; 0 found + 140 | ERROR | [x] Comment star tag not aligned with open tag + | | (MediaWiki.Commenting.FunctionComment.SyntaxAlignedDocStar) + 140 | ERROR | [x] Expected at least 1 spaces after doc star; 0 found | | (MediaWiki.Commenting.FunctionComment.SpacingDocStar) - 146 | ERROR | [x] Comment star must be a single '*' + 141 | ERROR | [x] Comment star must be a single '*' | | (MediaWiki.Commenting.FunctionComment.SyntaxMultiDocStar) - 147 | ERROR | [x] Comment close tag must be '*/' + 141 | ERROR | [x] Comment star tag not aligned with open tag + | | (MediaWiki.Commenting.FunctionComment.SyntaxAlignedDocStar) + 141 | ERROR | [x] Expected at least 1 spaces after doc star; 0 found + | | (MediaWiki.Commenting.FunctionComment.SpacingDocStar) + 142 | ERROR | [x] Comment close tag not aligned with open tag + | | (MediaWiki.Commenting.FunctionComment.SyntaxAlignedDocClose) + 142 | ERROR | [x] Comment close tag must be '*/' | | (MediaWiki.Commenting.FunctionComment.SyntaxCloseTag) - 151 | ERROR | [x] Comment open tag must be '/**' + 146 | ERROR | [x] Comment open tag must be '/**' | | (MediaWiki.Commenting.FunctionComment.SyntaxOpenTag) - 151 | ERROR | [x] Expected 1 spaces after doc star on single line; 0 + 147 | ERROR | [x] Comment star must be a single '*' + | | (MediaWiki.Commenting.FunctionComment.SyntaxMultiDocStar) + 147 | ERROR | [x] Expected at least 1 spaces after doc star; 0 found + | | (MediaWiki.Commenting.FunctionComment.SpacingDocStar) + 148 | ERROR | [x] Comment star must be a single '*' + | | (MediaWiki.Commenting.FunctionComment.SyntaxMultiDocStar) + 149 | ERROR | [x] Comment close tag must be '*/' + | | (MediaWiki.Commenting.FunctionComment.SyntaxCloseTag) + 153 | ERROR | [x] Comment open tag must be '/**' + | | (MediaWiki.Commenting.FunctionComment.SyntaxOpenTag) + 153 | ERROR | [x] Expected 1 spaces after doc star on single line; 0 | | found | | (MediaWiki.Commenting.FunctionComment.SpacingDocStarSingleLine) - 151 | ERROR | [x] Expected 1 spaces before close comment tag on single + 153 | ERROR | [x] Expected 1 spaces before close comment tag on single | | line; 0 found | | (MediaWiki.Commenting.FunctionComment.SpacingSingleLineCloseTag) - 151 | ERROR | [x] Comment close tag must be '*/' + 153 | ERROR | [x] Comment close tag must be '*/' | | (MediaWiki.Commenting.FunctionComment.SyntaxCloseTag) - 155 | ERROR | [x] Expected 1 spaces after doc star on single line; 3 + 157 | ERROR | [x] Expected 1 spaces after doc star on single line; 3 | | found | | (MediaWiki.Commenting.FunctionComment.SpacingDocStarSingleLine) - 155 | ERROR | [x] Expected 1 spaces before close comment tag on single + 157 | ERROR | [x] Expected 1 spaces before close comment tag on single | | line; 2 found | | (MediaWiki.Commenting.FunctionComment.SpacingSingleLineCloseTag) - 159 | ERROR | [x] Comment open tag must be '/**' + 161 | ERROR | [x] Comment open tag must be '/**' | | (MediaWiki.Commenting.FunctionComment.SyntaxOpenTag) - 160 | ERROR | [x] Comment star tag not aligned with open tag + 162 | ERROR | [x] Comment star tag not aligned with open tag | | (MediaWiki.Commenting.FunctionComment.SyntaxAlignedDocStar) - 160 | ERROR | [x] Expected at least 1 spaces after doc star; 0 found + 162 | ERROR | [x] Expected at least 1 spaces after doc star; 0 found | | (MediaWiki.Commenting.FunctionComment.SpacingDocStar) - 160 | ERROR | [x] Comment close tag must be '*/' + 162 | ERROR | [x] Comment close tag must be '*/' | | (MediaWiki.Commenting.FunctionComment.SyntaxCloseTag) - 160 | ERROR | [x] Comment close tag should have own line + 162 | ERROR | [x] Comment close tag should have own line | | (MediaWiki.Commenting.FunctionComment.CloseTagOwnLine) - 165 | ERROR | [x] Expected 1 spaces before @param; 0 found + 167 | ERROR | [x] Expected 1 spaces before @param; 0 found | | (MediaWiki.Commenting.FunctionComment.SpacingDocTag) - 165 | ERROR | [x] Expected at least 1 spaces after doc star; 0 found + 167 | ERROR | [x] Expected at least 1 spaces after doc star; 0 found | | (MediaWiki.Commenting.FunctionComment.SpacingDocStar) - 166 | ERROR | [x] Expected 1 spaces before @return; 2 found + 168 | ERROR | [x] Expected 1 spaces before @return; 2 found | | (MediaWiki.Commenting.FunctionComment.SpacingDocTag) - 173 | ERROR | [ ] Only one class is allowed in a file + 175 | ERROR | [ ] Only one class is allowed in a file | | (MediaWiki.Files.OneClassPerFile.MultipleFound) - 240 | ERROR | [ ] Only one class is allowed in a file + 242 | ERROR | [ ] Only one class is allowed in a file | | (MediaWiki.Files.OneClassPerFile.MultipleFound) -PHPCBF CAN FIX THE 67 MARKED SNIFF VIOLATIONS AUTOMATICALLY +PHPCBF CAN FIX THE 72 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 2f4a517..4b85787 100644 --- a/MediaWiki/Tests/files/Commenting/commenting_function.php.fixed +++ b/MediaWiki/Tests/files/Commenting/commenting_function.php.fixed @@ -106,9 +106,11 @@ /** * @param bool $aBool A bool * @param int $anInt An int + * @param \float[] $aFloatArray A float array * @return bool And some text + * @throws Exception */ - public function testVariablePunctation( $aBool, $anInt ) { + public function testVariablePunctation( $aBool, $anInt, $aFloatArray ) { return $aBool; } -- To view, visit https://gerrit.wikimedia.org/r/383184 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib1c7a41c07484f7c3af7f806fbc375df44b543bf Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/tools/codesniffer Gerrit-Branch: master Gerrit-Owner: Umherirrender <umherirrender_de...@web.de> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: Umherirrender <umherirrender_de...@web.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits