Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Configure the printer to preserve formatting #1051

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions specs/use/use-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Foo {}
class Foo
{
}

use Humbug\Foo;

PHP,
Expand All @@ -56,6 +57,7 @@ class Foo {}
class Foo
{
}

use Humbug\Foo;

PHP,
Expand Down
4 changes: 2 additions & 2 deletions specs/use/use-trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class HTML5DOMDocument {

namespace Humbug\IvoPetkov;

class HTML5DOMDocument
{
class HTML5DOMDocument {
use \Humbug\IvoPetkov\Internal\QuerySelector;
}

Expand All @@ -60,6 +59,7 @@ class HTML5DOMDocument {
namespace Humbug\IvoPetkov;

use Humbug\IvoPetkov\Internal\QuerySelector;

class HTML5DOMDocument
{
use QuerySelector;
Expand Down
6 changes: 5 additions & 1 deletion src/PhpParser/Printer/StandardPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public function __construct(private PrettyPrinter $decoratedPrinter)

public function print(array $newStmts, array $oldStmts, array $oldTokens): string
{
$printedStatements = $this->decoratedPrinter->prettyPrintFile($newStmts);
$printedStatements = $this->decoratedPrinter->printFormatPreserving(
$newStmts,
$oldStmts,
$oldTokens,
);

return $printedStatements."\n";
}
Expand Down
5 changes: 1 addition & 4 deletions tests/Scoper/PhpScoperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ public function test_can_scope_a_php_file(): void
PHP;

$expected = <<<'PHP'
<?php

namespace Humbug;

echo "Humbug!";
Expand Down Expand Up @@ -174,8 +172,6 @@ public function test_can_scope_a_php_file_with_the_wrong_extension(): void
PHP;

$expected = <<<'PHP'
<?php

namespace Humbug;

echo "Humbug!";
Expand All @@ -199,6 +195,7 @@ public function test_can_scope_php_executable_files(): void
PHP;

$expected = <<<'PHP'
?>
#!/usr/bin/env php
<?php
namespace Humbug;
Expand Down
Loading