Skip to content
Open
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
9 changes: 8 additions & 1 deletion src/comments.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,17 @@ function handleFunction(
enclosingNode.body &&
locStart(comment) > argumentsLocEnd &&
locEnd(comment) < locStart(enclosingNode.body);
const nextCharIndex = getNextNonSpaceNonCommentCharacterIndex(
let nextCharIndex = getNextNonSpaceNonCommentCharacterIndex(
text,
locEnd(comment)
);
// skip the trailing comma of the argument list, if any
if (text.charAt(nextCharIndex) === ",") {
nextCharIndex = getNextNonSpaceNonCommentCharacterIndex(
text,
nextCharIndex + 1
);
}
// we additionally need to check if this isn't a trailing argument comment,
// by checking the next character isn't ")"
if (
Expand Down
49 changes: 49 additions & 0 deletions tests/comments/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4763,6 +4763,55 @@ if (
================================================================================
`;

exports[`last-parameter.php 1`] = `
====================================options=====================================
parsers: ["php"]
printWidth: 80
| printWidth
=====================================input======================================
<?php
class Ulid
{
public static function isValid(string $ulid /* , int $format = self::FORMAT_BASE_32 */): bool
{
return true;
}

public static function isValidAgain(
string $ulid /* , int $format = self::FORMAT_BASE_32 */,
): bool {
return true;
}

public function progressStart(int $max = 0 /* , ?string $format = null */,): void
{
}
}

=====================================output=====================================
<?php
class Ulid
{
public static function isValid(
string $ulid /* , int $format = self::FORMAT_BASE_32 */,
): bool {
return true;
}

public static function isValidAgain(
string $ulid /* , int $format = self::FORMAT_BASE_32 */,
): bool {
return true;
}

public function progressStart(
int $max = 0 /* , ?string $format = null */,
): void {}
}

================================================================================
`;

exports[`list.php 1`] = `
====================================options=====================================
parsers: ["php"]
Expand Down
18 changes: 18 additions & 0 deletions tests/comments/last-parameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
class Ulid
{
public static function isValid(string $ulid /* , int $format = self::FORMAT_BASE_32 */): bool
{
return true;
}

public static function isValidAgain(
string $ulid /* , int $format = self::FORMAT_BASE_32 */,
): bool {
return true;
}

public function progressStart(int $max = 0 /* , ?string $format = null */,): void
{
}
}