Skip to content
Permalink
Browse files

Fix #1799 - support trailing commas in object-like docblock types

  • Loading branch information...
muglug committed Jun 18, 2019
1 parent 1bdd444 commit b12f05185a76c30c0d42acd79d2d43f2ffaaea2d
Showing with 30 additions and 2 deletions.
  1. +6 −2 src/Psalm/Internal/Analyzer/CommentAnalyzer.php
  2. +24 −0 tests/AnnotationTest.php
@@ -76,7 +76,9 @@ public static function getTypeFromComment(
$type_start = $offset + $comment->getFilePos();
$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] === ''
|| ($line_parts[0][0] === '$'
@@ -308,7 +310,9 @@ public static function extractFunctionDocblockInfo(PhpParser\Comment\Doc $commen
$start = $offset + $comment->getFilePos();
$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] === ''
|| ($line_parts[0][0] === '$'
@@ -1014,6 +1014,30 @@ function f(A $a) : void {
$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" => ""];'
],
];
}

0 comments on commit b12f051

Please sign in to comment.
You can’t perform that action at this time.