-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
ClassAttributesSeparationFixer - Introduce only_if_meta
spacing option
#5704
ClassAttributesSeparationFixer - Introduce only_if_meta
spacing option
#5704
Conversation
666e2b9
to
344a9c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php
Outdated
Show resolved
Hide resolved
tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php
Outdated
Show resolved
Hide resolved
e150f5e
to
ed955bb
Compare
hybrid
spacing optionone_if_phpdoc
spacing option
cc8c114
to
39f4f71
Compare
🙌 Amazing! Thanks for tackling this @paulbalandan I tried this in the past but couldn't get it to work. Instead of calling the option Because properties can be annotated with only an attribute, with an attribute and phpdoc, only a phpdoc, or nothing at all. |
@ruudk Good point! I agree PHP 8 attributes should be supported. Maybe a name like |
@julienfalque sure, I'll look into that. Just to confirm, |
Thanks! Yep, |
Does it matter if it's a phpdoc or regular comment? I think as a user you expect the same behavior:
? |
IMO we can start with PHPDocs and attributes only and see if the option needs adjustements afterwards. |
7f6888d
to
f8d408c
Compare
one_if_phpdoc
spacing optiononly_if_meta
spacing option
I was looking at the example in the OP: // Before
class Sample
{
/** @var int */
const FOO = 1;
/** @var int */
const BAR = 2;
#[Foo\Baz]
const BAZ = 3;
const OTHER = 4;
}
// After
class Sample
{
/** @var int */
const FOO = 1;
/** @var int */
const BAR = 2;
#[Foo\Baz]
const BAZ = 3;
const OTHER = 4;
} Shouldn't there also be a newline between Like this: // Before
class Sample
{
/** @var int */
const FOO = 1;
/** @var int */
const BAR = 2;
#[Foo\Baz]
const BAZ = 3;
const OTHER = 4;
const OTHER2 = 5;
}
// After
class Sample
{
/** @var int */
const FOO = 1;
/** @var int */
const BAR = 2;
#[Foo\Baz]
const BAZ = 3;
const OTHER = 4;
const OTHER2 = 5;
} |
The rule adds a new line if the element itself has a meta above it. It will not be affected if the element above it has the meta instead. |
f8d408c
to
e42afb7
Compare
e42afb7
to
2d424cd
Compare
closes #5800 as well |
I like this PR a lot and know it is a feature request for a lot for some time 👍 Left a minor and kicked the CI, so lets see on that. |
f176aad
to
0f16c73
Compare
0f16c73
to
79bfe09
Compare
Thank you @paulbalandan. |
Thank you @paulbalandan for this amazing contribution ❤️ 🙌 |
…SpacePossum, keradus) This PR was squashed before being merged into the 3.0 branch. Discussion ---------- ClassAttributesSeparationFixer - fixes & enhancements closes #5852 closes #5854 closes #5843 (including #5843 (comment)) fixes #5704 (comment) (cc `@ruudk` for option `none`) replaces #5869 replaces #5868 I haven't found BC breaks, however there is a minor change in how comments that are not related at all to a class element are handled. This is of no concern as people shouldn't just drop comments all over the place and expect these to end up somewhere. Additionally fixes a bunch of issues with comments, include cases where the fixer had to be run multiple times before done with fixing. Have to check how `only_if_meta` comes into play on `master` as I suspect this act near the same as `none` now. Commits ------- ac1a41d ClassAttributesSeparationFixer - fixes & enhancements
Closes #4014 .
This PR introduces a new spacing option
only_if_meta
toclass_attributes_separation
fixer. The behavior of this option is technically the same withnone
except that when there is aT_DOC_COMMENT
orT_ATTRIBUTE
(or both) above the class element the option will now behave asone
.Examples:
['elements' => ['const' => 'only_if_meta']]
['elements' => ['property' => 'only_if_meta']]