Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jul 10 2018 21:39
    @SpacePossum banned @jewome62_gitlab
SpacePossum
@SpacePossum
Hi!
Currently we don't have such feature for the PHP-CS-Fixer
Dev_NIX
@devnix
@SpacePossum Thank you so much!
ThelsK
@ThelsK
Hello there. I'm using PHP-CS-Fixer with junstyle's php cs fixer addon for VS Code. I was wondering, is there a way to preserve newlines?
HenkPoley
@HenkPoley
Afaik there is only an option to set the end of line character sequence
Not to keep it.
eg ->setLineEnding("\r\n")
It seems like the AST does not contain the line ending. So there is nothing to "keep".
ThelsK
@ThelsK
AST?
Dave van der Brugge
@dmvdbrugge
What do you mean with "preserve newlines"? What is the ruleset you use? My guess is you enabled no_extra_blank_lines
HenkPoley
@HenkPoley
Abstract Syntax Tree, when you read code, and put it in a sensible data structure to manipulate the source code.
ThelsK
@ThelsK
@dmvdbrugge I basically want to prevent any newlines I add manually from being deleted.
Dave van der Brugge
@dmvdbrugge
@HenkPoley PHP-CS-Fixer doesn't use the AST
HenkPoley
@HenkPoley
Ah, I see, "preserve newlines" could just mean vertical white space
Dave van der Brugge
@dmvdbrugge
@ThelsK Then answer my question, what is the ruleset you use?
Or what is your config?
ThelsK
@ThelsK
"php-cs-fixer.executablePath": "${extensionPath}/php-cs-fixer.phar",
"php-cs-fixer.lastDownload": 1583234166772,
"php-cs-fixer.autoFixBySemicolon": true,
"php-cs-fixer.formatHtml": true,
"php-cs-fixer.rules": "@Symfony",
those are all the php-cs settings in my settings.json
Dave van der Brugge
@dmvdbrugge
Those are not php-cs-fixer's settings, but the plugin's. I have no idea how to correctly configure that, but I can see that it uses the Symfony ruleset which (like I predicted) has no_extra_blank_lines enabled.
ThelsK
@ThelsK
hmm, I'll try setting that parameter to false. I'll have to make a config for that
However, it's not just blank lines
HenkPoley
@HenkPoley
Maybe: "php-cs-fixer.rules": "@Symfony,-no_extra_blank_lines",
ThelsK
@ThelsK
But it's also stuff like this:
        value="<?php echo $view->escape($option); ?>" <?php if (!empty($campaignSources[$option])) {
                echo 'disabled';
            } ?>
I'd personally want to start the second php tag on it's own line, since it's its own parameter
But it keeps adding it back to the same line
Dave van der Brugge
@dmvdbrugge
Yeah don't try to fix "mixed" code
ThelsK
@ThelsK
hmm?
Dave van der Brugge
@dmvdbrugge
PHP-CS-Fixer is mainly for "pure" php
ThelsK
@ThelsK
So you recommend I just use a HTML formatter instead?
Dave van der Brugge
@dmvdbrugge
Yeah, and use "proper" templating syntax, f.e.
        value="<?= $view->escape($option); ?>"<?php if (!empty($campaignSources[$option])): ?> disabled<?php endif ?>
ThelsK
@ThelsK
I didn't write this code. It's an open source product that I need to tweak a little
Either way, thanks for the help
ThelsK
@ThelsK
Hmm, actually, it seems PHP-CS-Fixer wasn't even responsible for the issue. The Extention apparently only uses it for the actual PHP blocks, and uses the built-in HTML formatter for the rest of the document.
I managed to configure that to use the right HTML formatting settings, and that fixed it.
Dave van der Brugge
@dmvdbrugge
:tada:
Charles Senard
@charlyox
Hi there,
I'm trying to install php cs fixer on php storm on windows 10. Impossible to achieve. When I click validate it says can not run php cs fixer. Took care of linking the goog .bat of course.
good *
HenkPoley
@HenkPoley
@charlyox why not put php.exe in your PATH ? https://docs.alfresco.com/4.2/tasks/fot-addpath.html
@charlyox then you can just run it as vendor/bin/php-cs-fixer.bat
HenkPoley
@HenkPoley
@charlyox ..if you have it installed with composer composer require friendsofphp/php-cs-fixer
Charles Senard
@charlyox
@HenkPoley PATH was already updated, but thanks for your answer.
Turns out that I was trying to setup PHP CS Fixer on a blank PHPStorm; Once I had created my first project, this setting would be working...
Ghost
@ghost~529c6d36ed5ab0b3bf04db19
Hi 👋 I like to take a stab at this issue FriendsOfPHP/PHP-CS-Fixer#4755
one question: if I get the discussion correctly, I need to change the config format for class_attributes_separation. The elements should be a key/value map with options none or single_line instead of a list. How would I do that? I see there is a FixerConfigurationResolverRootless but it is deprecated
I can use something like this (using bool instead of none or single_line). However then I miss the elements key.
return new FixerConfigurationResolver([
            (new FixerOptionBuilder('const', 'Separate line between const statements.'))
                ->setAllowedTypes(['bool', 'null'])
                ->setDefault(true)
                ->getOption(),
            (new FixerOptionBuilder('method', 'Separate line between method statements.'))
                ->setAllowedTypes(['bool', 'null'])
                ->setDefault(true)
                ->getOption(),
            (new FixerOptionBuilder('property', 'Separate line between property statements.'))
                ->setAllowedTypes(['bool', 'null'])
                ->setDefault(null)
                ->getOption(),
        ]);
Ghost
@ghost~529c6d36ed5ab0b3bf04db19
@SpacePossum do you maybe have a hint? :)
Ghost
@ghost~529c6d36ed5ab0b3bf04db19
finally found a way 👍
Ghost
@ghost~529c6d36ed5ab0b3bf04db19
ww9
@ww9
image.png
Hi all. I'm trying to format some legacy PHP code using php-cs-fixer but it is leaving many semicolons on the same line like this
I ran ./php-cs-fixer fix html/index.php. Any ideas?