Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocComment sniff - do not require blank line before doc comment when in array or function call #7

Merged
merged 1 commit into from
May 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
);
}
}