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

ClassAttributesSeparationFixer - add option for no new lines between properties #4875

Merged

Conversation

adri
Copy link
Contributor

@adri adri commented Mar 6, 2020

Implementation for #4755

Changes the class_attributes_separation option to take options for each type (const, method or property. The options can be either one or none, indicating one or no spaces between the types.

Example

A configuration like this:

'class_attributes_separation' => ['elements' => ['property' => 'none']],

Would change this example code:

<?php
class A
{
    private $a = null;

    public $b = 1;

    function A() {}
}

to this:

<?php
class A
{
    private $a = null;
    public $b = 1;

    function A() {}
}

@julienfalque
Copy link
Member

I get this error when running the new test I added. What does it mean?

This is because the unit tests for fixers first check that the input code is changed to the expected code then it checks that the expected code is not changed again when used as input. It means the fixer changes code that is not expected to change.

adri and others added 4 commits March 20, 2020 08:47

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@adri adri force-pushed the feature-no-newlines-between-props branch from 6228f39 to 8769cc4 Compare March 20, 2020 07:48
@adri
Copy link
Contributor Author

adri commented Mar 20, 2020

@juliendufresne @kubawerlos Thanks for checking this PR, with the help of @ruudk this PR is now ready for review.

@adri adri force-pushed the feature-no-newlines-between-props branch from a8aed0e to 951fb16 Compare March 20, 2020 17:10
@adri
Copy link
Contributor Author

adri commented Mar 20, 2020

@kubawerlos Thanks! Fixed

@adri adri force-pushed the feature-no-newlines-between-props branch from 951fb16 to aa08cc5 Compare March 20, 2020 17:17
Copy link
Contributor

@kubawerlos kubawerlos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@julienfalque julienfalque linked an issue Mar 21, 2020 that may be closed by this pull request
@adri adri force-pushed the feature-no-newlines-between-props branch from f4c2ae5 to 117e617 Compare March 27, 2020 17:22
@adri adri force-pushed the feature-no-newlines-between-props branch from 117e617 to 6236ce2 Compare March 27, 2020 17:26
Copy link
Contributor

@ruudk ruudk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing this PR 🙌
@SpacePossum What do you think? You also replied in #4755 to provide a solution.

@ruudk
Copy link
Contributor

ruudk commented Apr 1, 2020

@keradus @GrahamCampbell What do you think of this? Would love to be able to remove all those empty newlines from our project 🙏

@SpacePossum SpacePossum added the RTM Ready To Merge label Apr 5, 2020
@SpacePossum SpacePossum added this to the 2.17.0 milestone Apr 5, 2020
@julienfalque
Copy link
Member

@adri Before we merge this PR, could you please rebase and squash commits to keep one commit per authorship?

@SpacePossum SpacePossum changed the title New Feature: No new lines between properties ClassAttributesSeparationFixer - add option for no new lines between properties Apr 5, 2020
@SpacePossum SpacePossum merged commit 8ac11ce into PHP-CS-Fixer:master Apr 5, 2020
@SpacePossum
Copy link
Contributor

Thanks @adri and @ruudk , great to have this in :)

Hope you guys @ TicketSwap are holding up and get through the lockdown in NL, love the service you provide!

@SpacePossum SpacePossum removed the RTM Ready To Merge label Apr 5, 2020
@SpacePossum
Copy link
Contributor

Sorry missed your comment @julienfalque and already compiled the list of PR te merge. Sadly the merge script didn't squash the commit, but we can do without it.

@adri adri deleted the feature-no-newlines-between-props branch April 5, 2020 11:03
@ruudk
Copy link
Contributor

ruudk commented Apr 6, 2020

Thanks for merging this. I see this is merged to master. Will this be released as 2.17.x?

Hope you guys @ TicketSwap are holding up and get through the lockdown in NL, love the service you provide!

@SpacePossum Thanks, hope it too 😊

@SpacePossum
Copy link
Contributor

yeah this will be in 2.17.0 :)

@ruudk
Copy link
Contributor

ruudk commented May 14, 2020

@SpacePossum What's the ETA for 2.17.0?

@SpacePossum
Copy link
Contributor

My hope is within two months, however it depends on what we find during regression testing it and the time the maintainer has, maybe not ideal but we shouldn't rush it. People can help out a lot by using the master version for now and report any bugs they find on their repo's, as I think 2.17 is mostly feature-complete by this point.

@ruudk
Copy link
Contributor

ruudk commented May 29, 2020

When properties have comments, the newlines are also removed. I don't think it should behave like that.

'class_attributes_separation' => ['elements' => ['property' => 'none']],
class Entity
{
    /**
     * @ORM\Column(name="id", type="uuid")
     * @ORM\Id
     */
    private UuidInterface $id;

    /**
     * @ORM\Column(name="description", type="text")
     */
    private string $description = '';
}

gets converted to

class Entity
{
    /**
     * @ORM\Column(name="id", type="uuid")
     * @ORM\Id
     */
    private UuidInterface $id;
    /**
     * @ORM\Column(name="description", type="text")
     */
    private string $description = '';
}

What do you think? How should this behave?

@julienfalque
Copy link
Member

I would prefer keeping the empty line when there is a DocBlock comment. Same with constants and methods.

@ruudk
Copy link
Contributor

ruudk commented May 29, 2020

Indeed, that's also what I expected, so maybe it's a bug in this PR? I don't know enough from the internals to know where this responsibility resides.

@kubawerlos
Copy link
Contributor

I would expect it to be removed as the configuration chosen is none - maybe we need new config option like none_where_there_is_no_phpdoc_before_and_one_where_is_phpdoc_before.

@SpacePossum
Copy link
Contributor

I agree with @kubawerlos here, for none I expect no exceptions. The new option is fine by me, although maybe a shorter name for it can be found.

@ruudk
Copy link
Contributor

ruudk commented Jul 20, 2020

@SpacePossum @kubawerlos @julienfalque Implemented in #5060. What do you think?

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

Successfully merging this pull request may close these issues.

Idea: NoNewlinesBetweenPropertiesFixer
6 participants