Skip to content

Commit

Permalink
fix: parameter comment function attribute removal (#2412)
Browse files Browse the repository at this point in the history
* fix: attributes are getting printed now if any (not the last) parameter have a line comment

* chore: add newline

* chore: snapshot generation

---------

Co-authored-by: Simon Schwedes <[email protected]>
  • Loading branch information
LordSalmon and SimonEscola authored Jan 20, 2025
1 parent 718f71d commit c5c56ff
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/printer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ function printFunction(path, options, print) {
const willBreakDeclaration = declaration.some(willBreak);

if (willBreakDeclaration) {
return [printedDeclaration, " ", printedBody];
return [...declAttrs, printedDeclaration, " ", printedBody];
}

return [
Expand Down
42 changes: 42 additions & 0 deletions tests/attributes/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ class Test
}
}
class ParamCommentFunctionAnnotation {
#[Foo]
function bar(
int $a, // parameter comment
int $b,
) {
return $a + $b;
}
#[Foo]
function bar2(
int $a,
int $middle, // parameter comment
int $b,
) {
return $a + $middle + $b;
}
}
=====================================output=====================================
<?php
Expand Down Expand Up @@ -206,5 +228,25 @@ class Test
}
}
class ParamCommentFunctionAnnotation
{
#[Foo]
function bar(
int $a, // parameter comment
int $b
) {
return $a + $b;
}
#[Foo]
function bar2(
int $a,
int $middle, // parameter comment
int $b
) {
return $a + $middle + $b;
}
}
================================================================================
`;
23 changes: 22 additions & 1 deletion tests/attributes/attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,25 @@ public function withAttribute(string $foo): string
return $foo;
}

}
}

class ParamCommentFunctionAnnotation {

#[Foo]
function bar(
int $a, // parameter comment
int $b,
) {
return $a + $b;
}

#[Foo]
function bar2(
int $a,
int $middle, // parameter comment
int $b,
) {
return $a + $middle + $b;
}

}

0 comments on commit c5c56ff

Please sign in to comment.