Skip to content

Commit

Permalink
Fix #1799 - support trailing commas in object-like docblock types
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jun 18, 2019
1 parent 1bdd444 commit b12f051
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Psalm/Internal/Analyzer/CommentAnalyzer.php
Expand Up @@ -76,7 +76,9 @@ public static function getTypeFromComment(
$type_start = $offset + $comment->getFilePos(); $type_start = $offset + $comment->getFilePos();
$type_end = $type_start + strlen($line_parts[0]); $type_end = $type_start + strlen($line_parts[0]);


$line_parts[0] = str_replace("\n", '', preg_replace('@^[ \t]*\*@m', '', $line_parts[0])); $line_parts[0] = preg_replace('@^[ \t]*\*@m', '', $line_parts[0]);
$line_parts[0] = preg_replace('/,\n\s+\}/', '}', $line_parts[0]);
$line_parts[0] = str_replace("\n", '', $line_parts[0]);


if ($line_parts[0] === '' if ($line_parts[0] === ''
|| ($line_parts[0][0] === '$' || ($line_parts[0][0] === '$'
Expand Down Expand Up @@ -308,7 +310,9 @@ public static function extractFunctionDocblockInfo(PhpParser\Comment\Doc $commen
$start = $offset + $comment->getFilePos(); $start = $offset + $comment->getFilePos();
$end = $start + strlen($line_parts[0]); $end = $start + strlen($line_parts[0]);


$line_parts[0] = str_replace("\n", '', preg_replace('@^[ \t]*\*@m', '', $line_parts[0])); $line_parts[0] = preg_replace('@^[ \t]*\*@m', '', $line_parts[0]);
$line_parts[0] = preg_replace('/,\n\s+\}/', '}', $line_parts[0]);
$line_parts[0] = str_replace("\n", '', $line_parts[0]);


if ($line_parts[0] === '' if ($line_parts[0] === ''
|| ($line_parts[0][0] === '$' || ($line_parts[0][0] === '$'
Expand Down
24 changes: 24 additions & 0 deletions tests/AnnotationTest.php
Expand Up @@ -1014,6 +1014,30 @@ function f(A $a) : void {
$a->bar(); $a->bar();
}' }'
], ],
'allowClosingComma' => [
'<?php
/**
* @param array{
* foo: string,
* bar: string,
* baz: array{
* a: int,
* },
* } $foo
*/
function foo(array $foo) : int {
return count($foo);
}
/**
* @var array{
* foo:string,
* bar:string,
* baz:string,
* } $foo
*/
$foo = ["foo" => "", "bar" => "", "baz" => ""];'
],
]; ];
} }


Expand Down

0 comments on commit b12f051

Please sign in to comment.