From c03cdf3f30b91252bed5274b310f6c62e8049d3a Mon Sep 17 00:00:00 2001 From: Simon Schwedes Date: Wed, 8 Jan 2025 11:45:47 +0100 Subject: [PATCH 1/3] fix: attributes are getting printed now if any (not the last) parameter have a line comment --- src/printer.mjs | 2 +- .../__snapshots__/jsfmt.spec.mjs.snap | 41 +++++++++++++++++++ tests/attributes/attributes.php | 21 ++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/printer.mjs b/src/printer.mjs index 066b68f71..cec72d0f7 100644 --- a/src/printer.mjs +++ b/src/printer.mjs @@ -1410,7 +1410,7 @@ function printFunction(path, options, print) { const willBreakDeclaration = declaration.some(willBreak); if (willBreakDeclaration) { - return [printedDeclaration, " ", printedBody]; + return [...declAttrs, printedDeclaration, " ", printedBody]; } return [ diff --git a/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap b/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap index 16622e7c1..a8b434f34 100644 --- a/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap @@ -89,6 +89,27 @@ class Test 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; + } + } =====================================output===================================== Date: Wed, 8 Jan 2025 11:46:28 +0100 Subject: [PATCH 2/3] chore: add newline --- tests/attributes/attributes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/attributes/attributes.php b/tests/attributes/attributes.php index c5848db16..bb93d757a 100644 --- a/tests/attributes/attributes.php +++ b/tests/attributes/attributes.php @@ -102,4 +102,4 @@ function bar2( return $a + $middle + $b; } -} \ No newline at end of file +} From 8950351131333d6373f820dc364c8a8da1a338d7 Mon Sep 17 00:00:00 2001 From: Simon Schwedes Date: Wed, 8 Jan 2025 11:47:06 +0100 Subject: [PATCH 3/3] chore: snapshot generation --- tests/attributes/__snapshots__/jsfmt.spec.mjs.snap | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap b/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap index a8b434f34..7d30d00a9 100644 --- a/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap @@ -111,6 +111,7 @@ class ParamCommentFunctionAnnotation { } } + =====================================output=====================================