[MediaWiki-commits] [Gerrit] mediawiki...codesniffer[master]: Unwrap types in function docs from {}
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] + ]; +
[MediaWiki-commits] [Gerrit] mediawiki...codesniffer[master]: Unwrap types in function docs from {}
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 +