Skip to content

Commit

Permalink
Merge pull request #7 from webimpress/hotfix/blank-line-before-doc-co…
Browse files Browse the repository at this point in the history
…mment

DocComment sniff - do not require blank line before doc comment when in array or function call
  • Loading branch information
michalbundyra committed May 10, 2019
2 parents d73bece + 16b5d51 commit 25ec405
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
use const T_DOC_COMMENT_WHITESPACE;
use const T_NAMESPACE;
use const T_OPEN_CURLY_BRACKET;
use const T_OPEN_PARENTHESIS;
use const T_OPEN_SHORT_ARRAY;
use const T_OPEN_TAG;
use const T_USE;
use const T_WHITESPACE;
Expand Down Expand Up @@ -182,8 +184,12 @@ private function checkBeforeOpen(File $phpcsFile, int $commentStart) : void
$phpcsFile->fixer->endChangeset();
}
} elseif ($tokens[$previous]['line'] === $tokens[$commentStart]['line'] - 1
&& $tokens[$previous]['code'] !== T_OPEN_TAG
&& $tokens[$previous]['code'] !== T_OPEN_CURLY_BRACKET
&& ! in_array($tokens[$previous]['code'], [
T_OPEN_CURLY_BRACKET,
T_OPEN_PARENTHESIS,
T_OPEN_SHORT_ARRAY,
T_OPEN_TAG,
], true)
) {
$error = 'Missing blank line before doc comment';
$fix = $phpcsFile->addFixableError($error, $commentStart, 'MissingBlankLine');
Expand Down
26 changes: 26 additions & 0 deletions test/Sniffs/Commenting/DocCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,30 @@ class Foo
* bar baz
*/
public function descriptionIndentWithTags() {}

public function docCommentInArray() : array
{
return [
/**
* @param mixed $a
* @return mixed
*/
static function ($a) {
return $a;
},
];
}

public function docCommentInFunctionCall() : callable
{
$this->getName(
/**
* @param mixed $a
* @return mixed
*/
static function ($a) {
return $a;
}
);
}
}
26 changes: 26 additions & 0 deletions test/Sniffs/Commenting/DocCommentUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,30 @@ $c = 'xyz';
* bar baz
*/
public function descriptionIndentWithTags() {}

public function docCommentInArray() : array
{
return [
/**
* @param mixed $a
* @return mixed
*/
static function ($a) {
return $a;
},
];
}

public function docCommentInFunctionCall() : callable
{
$this->getName(
/**
* @param mixed $a
* @return mixed
*/
static function ($a) {
return $a;
}
);
}
}

0 comments on commit 25ec405

Please sign in to comment.