As title say, this is not an issue, is just a suggestion for this option header_comment, with which we can add, replace or remove header comments, but, how about of "change"?, actually there is no way to keep the original header comment changing only the blank line in the top or bottom, or I'm missing out on some other option?
Hi @Rolige and thanks for your suggestion.
What you describe about not being able to change the spacing around existing headers sounds like a bug to me. Can you give a minimal sample of what you would like to change and the expected result?
Hi @SpacePossum, is not a bug, it's just a combination that can not be achieved, or at least I could not. Let me give you an example...
Original code:
<?php
/**
* My header text
*
* @author Me
*/
$x = 1;
class MyClass
{
/**
* My method
* @param string $var [My variable]
*/
public function __construct($var)
{
return $var;
}
}
Command applied:
php-cs-fixer fix /path/my-file.php --rules=-@PSR2,@Symfony
Result:
<?php
/**
* My header text.
*
* @author Me
*/
$x = 1;
class MyClass
{
/**
* My method.
*
* @param string $var [My variable]
*/
public function __construct($var)
{
return $var;
}
}
So, how I can keep my original header message with the blank line (or add custom blank lines) between this and the next code?, resulting something like this...
<?php
/**
* My header text.
*
* @author Me
*/
$x = 1;
class MyClass
{
/**
* My method.
*
* @param string $var [My variable]
*/
public function __construct($var)
{
return $var;
}
}
Thanks for the sample!
So I tried to create a configuration setup for you to support you case.
<?php
$header = <<<'EOF'
My header text.
@author Me
EOF;
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
;
return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'header_comment' => [
'header' => $header,
'location' => 'after_open',
'separate' => 'bottom',
'comment_type' => 'PHPDoc',
],
])
->setFinder($finder)
;
(note @PSR2 is not needed as @Symfony already contains the set)
However this will still remove the line after the comment, even while we set 'separate' => 'bottom', for the header configuration.
The line is removed by no_blank_lines_after_phpdoc which I think should be modified to not touch header comments.
-- edit
just saw https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/3987
Thanks @SpacePossum, but that鈥檚 exactly the point, of course I could achieve it by using my custom message in the header_comment, but I'm creating my custom config file for a general use, not for a single project, as most developers do (I think).
ah right, so you want a rule to fix the spacing around a header only and not the header itself?
Exactly!
Most helpful comment
Exactly!