Umherirrender has uploaded a new change for review. ( 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} 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, 80 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/codesniffer refs/changes/84/383184/1 diff --git a/MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php b/MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php index 8bd2db2..d2b1cc4 100644 --- a/MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php +++ b/MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php @@ -274,6 +274,23 @@ $fixType = true; } } + $matches = []; + if ( preg_match( '/^(\p{P}+)(.*)(\p{P}+)$/', $type, $matches ) ) { + $error = 'Expected parameter type not wrapped in punctuation; %s and %s found'; + $data = [ + $matches[1], $matches[3] + ]; + $fix = $phpcsFile->addFixableError( + $error, + $retType, + 'NotPunctuationReturnType', + $data + ); + $type = $matches[2]; + if ( $fix === true ) { + $fixType = true; + } + } // Check the type for short types $explodedType = explode( '|', $type ); foreach ( $explodedType as $index => $singleType ) { @@ -366,6 +383,27 @@ if ( $exception === null ) { $error = 'Exception type missing for @throws tag in function comment'; $phpcsFile->addError( $error, $tag, 'InvalidThrows' ); + } else { + // Check for unneeded punctation on exceptions + $matches = []; + if ( preg_match( '/^(\p{P}+)(.*)(\p{P}+)$/', $exception, $matches ) ) { + $error = 'Expected parameter type not wrapped in punctuation; %s and %s found'; + $data = [ + $matches[1], $matches[3] + ]; + $fix = $phpcsFile->addFixableError( + $error, + $tag, + 'NotPunctuationException', + $data + ); + if ( $fix === true ) { + $phpcsFile->fixer->replaceToken( + $tag + 2, + $matches[2] . ( $comment === null ? '' : ' ' . $comment ) + ); + } + } } } // end foreach @@ -517,6 +555,27 @@ $phpcsFile->fixer->replaceToken( ( $param['tag'] + 1 ), str_repeat( ' ', $spaces ) ); } } + // Check for unneeded punctation on parameter type + $matches = []; + if ( preg_match( '/^(\p{P}+)(.*)(\p{P}+)$/', $param['type'], $matches ) ) { + $error = 'Expected parameter type not wrapped in punctuation; %s and %s found'; + $data = [ + $matches[1], $matches[3] + ]; + $fix = $phpcsFile->addFixableError( + $error, + $param['tag'], + 'NotPunctuationParamType', + $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 ffa889a..75d3fd4 100644 --- a/MediaWiki/Tests/files/Commenting/commenting_function.php +++ b/MediaWiki/Tests/files/Commenting/commenting_function.php @@ -104,9 +104,10 @@ } /** - * @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 + * @return {bool}: And some text + * @throws {Exception} */ public function testVariablePunctation( $aBool, $anInt ) { return $aBool; diff --git a/MediaWiki/Tests/files/Commenting/commenting_function.php.expect b/MediaWiki/Tests/files/Commenting/commenting_function.php.expect index a140814..348eba3 100644 --- a/MediaWiki/Tests/files/Commenting/commenting_function.php.expect +++ b/MediaWiki/Tests/files/Commenting/commenting_function.php.expect @@ -75,16 +75,28 @@ 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 punctuation; { + | | and } found + | | (MediaWiki.Commenting.FunctionComment.NotPunctuationParamType) 107 | ERROR | [x] Param name should not end with punctuation ":" | | (MediaWiki.Commenting.FunctionComment.NotPunctuationParam) + 108 | ERROR | [x] Expected parameter type not wrapped in punctuation; [ + | | and ] found + | | (MediaWiki.Commenting.FunctionComment.NotPunctuationParamType) 108 | ERROR | [x] Param name should not end with punctuation ":" | | (MediaWiki.Commenting.FunctionComment.NotPunctuationParam) 109 | ERROR | [x] Return type should not end with punctuation ":" | | (MediaWiki.Commenting.FunctionComment.NotPunctuationReturn) - 116 | ERROR | [x] Incorrect capitalization of @inheritDoc + 109 | ERROR | [x] Expected parameter type not wrapped in punctuation; { + | | and } found + | | (MediaWiki.Commenting.FunctionComment.NotPunctuationReturnType) + 110 | ERROR | [x] Expected parameter type not wrapped in punctuation; { + | | and } found + | | (MediaWiki.Commenting.FunctionComment.NotPunctuationException) + 117 | ERROR | [x] Incorrect capitalization of @inheritDoc | | (MediaWiki.Commenting.FunctionComment.LowercaseInheritDoc) - 130 | ERROR | [ ] Only one class is allowed in a file + 131 | ERROR | [ ] Only one class is allowed in a file | | (MediaWiki.Files.OneClassPerFile.MultipleFound) - 197 | ERROR | [ ] Only one class is allowed in a file + 198 | ERROR | [ ] Only one class is allowed in a file | | (MediaWiki.Files.OneClassPerFile.MultipleFound) -PHPCBF CAN FIX THE 32 MARKED SNIFF VIOLATIONS AUTOMATICALLY +PHPCBF CAN FIX THE 36 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 cdd105c..1fc5369 100644 --- a/MediaWiki/Tests/files/Commenting/commenting_function.php.fixed +++ b/MediaWiki/Tests/files/Commenting/commenting_function.php.fixed @@ -107,6 +107,7 @@ * @param bool $aBool A bool * @param int $anInt An int * @return bool And some text + * @throws Exception */ public function testVariablePunctation( $aBool, $anInt ) { return $aBool; -- To view, visit https://gerrit.wikimedia.org/r/383184 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib1c7a41c07484f7c3af7f806fbc375df44b543bf 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