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
BlankLineBeforeStatementFixer - can now add blank lines before doc-comments #4571
BlankLineBeforeStatementFixer - can now add blank lines before doc-comments #4571
Conversation
Is there currently some issue with the CI?
|
Hi and thanks for the PR! Looking at the code I'm afraid the approach of using the fixer might not work because of how the tool /software was designed. I really like to have the functionality in, however we need to get it in in a different way. In this case, we like to have empty like above a PHPDoc, however there are some exceptions.
In this case we don't want to have the empty line (there are a few more exceptions). So in order to get the fixing we want, I think it would be best to create a new one and not re-utilize the current one. WDYT? |
I just tested it for exactly this use-case. It did not add a blank line on the first doc-comment of the class. Before: final class CombineConsecutiveIssetsFixer extends AbstractFixer{
/**
* {@inheritdoc}
*/
public function getDefinition()
{
}
/** @var def */
protected $asd;
/** @var abc */
protected $qwe;
} After: final class CombineConsecutiveIssetsFixer extends AbstractFixer{
/**
* {@inheritdoc}
*/
public function getDefinition()
{
}
/** @var def */
protected $asd;
/** @var abc */
protected $qwe;
} The same behavior appears when the opening curly-brackets are on it's own line. |
Looking into this a bit more, this fixer will only insert the empty line if the previous line ends with |
Honestly i don't know if this is the best solution or not. I do not have enough experience with this project to judge that. Currently i like it because it creates a feature i want just by adding one very simple line. That seems elegant to me. Maybe i am more motivated to write a new fixer for this when someone more experienced crushes my hopes by showing how this simple solution fails in some situation i do not yet see. ;-) In the meantime i write one or two actual new fixers for other features that i would like and explore the project that way... |
I try to keep an eye out on the overall responsibilities for each fixer because we have/had a lot of issues with fixer doing to much, making these less flexible for later extension and adding configuration, causing priority issues we can't resolve and the only way out are BC changes on a next major which no one like because these ship rarely, causing issues and PR's to stale for months. So...no, I didn't spot an issue with your code and I don't want to crush your hopes, sorry if it feels that |
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.
Reading the discussion I think this fixer is the right place to update.
If saying handling doc_comment
is too much responsibility for the fixer then the same can be said about any member of $tokenMap
, right?
With the small change from the other comment, it looks to me like something we can think about merging.
@@ -40,6 +40,7 @@ final class BlankLineBeforeStatementFixer extends AbstractFixer implements Confi | |||
'continue' => T_CONTINUE, | |||
'declare' => T_DECLARE, | |||
'default' => T_DEFAULT, | |||
'doccomment' => T_DOC_COMMENT, |
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.
Let's have the key named doc_comment
(as there is already require_once
).
Can you take another look, and ideally resolve conflicts? |
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.
Please revert your changes on logo.png
.
I have now reverted the changes to |
7ac2c41
to
ec70efb
Compare
ec70efb
to
ef752ba
Compare
Thank you @addiks. |
This PR adds the "doccomment" token to the blank-line-before-statement-fixer.
Now the php-cs-fixer can automatically turn this:
... into this: