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

Whitespace around re-ordered class properties and constants is incorrect #49

Open
bakerkretzmar opened this issue Jan 4, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@bakerkretzmar
Copy link

Anecdotally I'm noticing that this:

class Foo
{
    protected $foo = 'bar';
    public $bar = 'baz';
    public const FOO = 'bar';
    protected $bar = 'baz';
}

Is formatted to this:

class Foo
{
    public const FOO = 'bar';
    public $bar = 'baz';

    protected $foo = 'bar';
    protected $bar = 'baz';
}

The whitespace around/between properties and constants that get reordered isn't always consistent. Happy to work on this myself when I have time next week.

@driftingly
Copy link
Member

The spacing is from TLint's OneLineBetweenClassVisibilityChanges

Class members of differing visibility must be separated by a blank line

@bakerkretzmar
Copy link
Author

Sorry I should have been more specific—what's weird to me is that there isn't whitespace added after the public CONST. I would have expected either of these instead:

class Foo
{
    public const FOO = 'bar';
    public $bar = 'baz';
    protected $foo = 'bar';
    protected $bar = 'baz';
}
class Foo
{
    public const FOO = 'bar';

    public $bar = 'baz';

    protected $foo = 'bar';
    protected $bar = 'baz';
}

@bakerkretzmar
Copy link
Author

Basically I want the formatter to fix all the whitespace for me, including in between consts and properties 😂

@driftingly
Copy link
Member

Right now, OneLineBetweenClassVisibilityChanges doesn't distinguish between const/properties, it only looks at visibility changes. I think we would need an additional linter/formatter for class attribute groups, something like OneLineBetweenClassAttributeGroups.

Pint's Laravel preset uses class_attributes_separation to add a blank line between most:

'class_attributes_separation' => [
    'elements' => [
        'const' => 'one',
        'method' => 'one',
        'property' => 'one',
        'trait_import' => 'none',
    ],
],

We overwrite this to only require a blank line between method. I'm wondering if we should follow the laravel convention on this as well.

class Foo
{
    public const FOO = 'bar';

    public $bar = 'baz';

    protected $foo = 'bar';

    protected $bar = 'baz';
}

@driftingly driftingly added the enhancement New feature or request label Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants