Loading coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php +3 −3 Original line number Diff line number Diff line Loading @@ -138,9 +138,9 @@ class InlineCommentSniff implements Sniff // Inline doc blocks are allowed in JSDoc. if ($tokens[$stackPtr]['content'] === '/**' && $phpcsFile->tokenizerType !== 'JS') { // The only exception to inline doc blocks is the /** @var */ // declaration. $content = $phpcsFile->getTokensAsString($stackPtr, ($tokens[$stackPtr]['comment_closer'] - $stackPtr + 1)); if (preg_match('#^/\*\* @var [a-zA-Z0-9_\\\\\[\]|]+ \$[a-zA-Z0-9_]+ \*/$#', $content) !== 1) { // declaration. Allow that in any form. $varTag = $phpcsFile->findNext([T_DOC_COMMENT_TAG], ($stackPtr + 1), $tokens[$stackPtr]['comment_closer'], false, '@var'); if ($varTag === false) { $error = 'Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead'; $phpcsFile->addError($error, $stackPtr, 'DocBlock'); } Loading coder_sniffer/Drupal/Test/Commenting/InlineCommentUnitTest.inc +27 −0 Original line number Diff line number Diff line Loading @@ -86,3 +86,30 @@ class Test { // 4. No indentation on the next line is also fine as I'm going to demonstrate // here. test(); /** * Allow various weird inline var doc comments people want to use. */ function test2() { /** * @var string $x * @var string $y */ list($x, $y) = something(); $date_format = ''; $time_format = ''; // Date formats cannot be loaded during install or update. if (!defined('MAINTENANCE_MODE')) { if ($date_format_entity = DateFormat::load('html_date')) { /** @var $date_format_entity \Drupal\Core\Datetime\DateFormatInterface */ $date_format = $date_format_entity->getPattern(); } if ($time_format_entity = DateFormat::load('html_time')) { /** @var $time_format_entity \Drupal\Core\Datetime\DateFormatInterface */ $time_format = $time_format_entity->getPattern(); } } return $x; } coder_sniffer/Drupal/Test/Commenting/InlineCommentUnitTest.inc.fixed +27 −0 Original line number Diff line number Diff line Loading @@ -85,3 +85,30 @@ class Test { // 4. No indentation on the next line is also fine as I'm going to demonstrate // here. test(); /** * Allow various weird inline var doc comments people want to use. */ function test2() { /** * @var string $x * @var string $y */ list($x, $y) = something(); $date_format = ''; $time_format = ''; // Date formats cannot be loaded during install or update. if (!defined('MAINTENANCE_MODE')) { if ($date_format_entity = DateFormat::load('html_date')) { /** @var $date_format_entity \Drupal\Core\Datetime\DateFormatInterface */ $date_format = $date_format_entity->getPattern(); } if ($time_format_entity = DateFormat::load('html_time')) { /** @var $time_format_entity \Drupal\Core\Datetime\DateFormatInterface */ $time_format = $time_format_entity->getPattern(); } } return $x; } Loading
coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php +3 −3 Original line number Diff line number Diff line Loading @@ -138,9 +138,9 @@ class InlineCommentSniff implements Sniff // Inline doc blocks are allowed in JSDoc. if ($tokens[$stackPtr]['content'] === '/**' && $phpcsFile->tokenizerType !== 'JS') { // The only exception to inline doc blocks is the /** @var */ // declaration. $content = $phpcsFile->getTokensAsString($stackPtr, ($tokens[$stackPtr]['comment_closer'] - $stackPtr + 1)); if (preg_match('#^/\*\* @var [a-zA-Z0-9_\\\\\[\]|]+ \$[a-zA-Z0-9_]+ \*/$#', $content) !== 1) { // declaration. Allow that in any form. $varTag = $phpcsFile->findNext([T_DOC_COMMENT_TAG], ($stackPtr + 1), $tokens[$stackPtr]['comment_closer'], false, '@var'); if ($varTag === false) { $error = 'Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead'; $phpcsFile->addError($error, $stackPtr, 'DocBlock'); } Loading
coder_sniffer/Drupal/Test/Commenting/InlineCommentUnitTest.inc +27 −0 Original line number Diff line number Diff line Loading @@ -86,3 +86,30 @@ class Test { // 4. No indentation on the next line is also fine as I'm going to demonstrate // here. test(); /** * Allow various weird inline var doc comments people want to use. */ function test2() { /** * @var string $x * @var string $y */ list($x, $y) = something(); $date_format = ''; $time_format = ''; // Date formats cannot be loaded during install or update. if (!defined('MAINTENANCE_MODE')) { if ($date_format_entity = DateFormat::load('html_date')) { /** @var $date_format_entity \Drupal\Core\Datetime\DateFormatInterface */ $date_format = $date_format_entity->getPattern(); } if ($time_format_entity = DateFormat::load('html_time')) { /** @var $time_format_entity \Drupal\Core\Datetime\DateFormatInterface */ $time_format = $time_format_entity->getPattern(); } } return $x; }
coder_sniffer/Drupal/Test/Commenting/InlineCommentUnitTest.inc.fixed +27 −0 Original line number Diff line number Diff line Loading @@ -85,3 +85,30 @@ class Test { // 4. No indentation on the next line is also fine as I'm going to demonstrate // here. test(); /** * Allow various weird inline var doc comments people want to use. */ function test2() { /** * @var string $x * @var string $y */ list($x, $y) = something(); $date_format = ''; $time_format = ''; // Date formats cannot be loaded during install or update. if (!defined('MAINTENANCE_MODE')) { if ($date_format_entity = DateFormat::load('html_date')) { /** @var $date_format_entity \Drupal\Core\Datetime\DateFormatInterface */ $date_format = $date_format_entity->getPattern(); } if ($time_format_entity = DateFormat::load('html_time')) { /** @var $time_format_entity \Drupal\Core\Datetime\DateFormatInterface */ $time_format = $time_format_entity->getPattern(); } } return $x; }