Skip to content

Commit

Permalink
Merge pull request #19 from webimpress/hotfix/doc-block-after-colon
Browse files Browse the repository at this point in the history
DocComment sniff - do not require empty line before doc-block when first after colon
  • Loading branch information
michalbundyra committed May 14, 2019
2 parents 816209b + c4dd26a commit 9774041
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use function substr;
use function trim;

use const T_COLON;
use const T_DOC_COMMENT_CLOSE_TAG;
use const T_DOC_COMMENT_OPEN_TAG;
use const T_DOC_COMMENT_STAR;
Expand Down Expand Up @@ -189,6 +190,7 @@ private function checkBeforeOpen(File $phpcsFile, int $commentStart) : void
T_OPEN_PARENTHESIS,
T_OPEN_SHORT_ARRAY,
T_OPEN_TAG,
T_COLON,
], true)
) {
$error = 'Missing blank line before doc comment';
Expand Down
21 changes: 20 additions & 1 deletion test/Sniffs/Commenting/DocCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class Foo
];
}

public function docCommentInFunctionCall() : callable
public function docCommentInFunctionCall() : void
{
$this->getName(
/**
Expand All @@ -287,6 +287,25 @@ class Foo
);
}

public function docCommentInSwitch(string $a)
{
switch ($a) {
case 'foo':
/** @var string $var */
$var = $this->getName();

return $var[0];
default:
/**
* @param int[] $a
* @return int
*/
return static function (array $a) {
return PHP_INT_MAX;
};
}
}

/**
* FIRST DOC-BLOCK COMMENT
*/
Expand Down
21 changes: 20 additions & 1 deletion test/Sniffs/Commenting/DocCommentUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ $c = 'xyz';
];
}

public function docCommentInFunctionCall() : callable
public function docCommentInFunctionCall() : void
{
$this->getName(
/**
Expand All @@ -289,6 +289,25 @@ $c = 'xyz';
);
}

public function docCommentInSwitch(string $a)
{
switch ($a) {
case 'foo':
/** @var string $var */
$var = $this->getName();

return $var[0];
default:
/**
* @param int[] $a
* @return int
*/
return static function (array $a) {
return PHP_INT_MAX;
};
}
}

/**
* FIRST DOC-BLOCK COMMENT
*/
Expand Down

0 comments on commit 9774041

Please sign in to comment.