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

A function or method containing no statements or comments body SHOULD be abbreviated as {} #2400

Open
jdeniau opened this issue Aug 27, 2024 · 0 comments

Comments

@jdeniau
Copy link
Contributor

jdeniau commented Aug 27, 2024

@prettier/plugin-php v0.22.2
Playground link

Input:

<?php

class Foo {
  public function __construct() {}
}

class Bar {
  public function __construct(
    private readonly Foo $foo
  ) {}
}

Output:

<?php

class Foo
{
    public function __construct()
    {
    }
}

class Bar
{
    public function __construct(private readonly Foo $foo)
    {
    }
}

expected behaviour

There should not a blank line between { and } According to PER CS 4.4 Methods and Functions:

If a function or method contains no statements or comments (such as an empty no-op implementation or when using constructor property promotion), then the body SHOULD be abbreviated as {} and placed on the same line as the previous symbol, separated by a space. For example:

class Point
{
    public function __construct(private int $x, private int $y) {}
    
    // ...
}

class Point
{
    public function __construct(
      public readonly int $x,
      public readonly int $y,
    ) {}
}

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant