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 @fotonmoton , currently we've no rule for the max length of a line, there is a FR open it FriendsOfPHP/PHP-CS-Fixer#2790
the other one (return) is being made here FriendsOfPHP/PHP-CS-Fixer#4435 I think, so if you've time please review and test that one : )
@dmvdbrugge we do not have such a wiki ATM, it is one of these things we never found time for ...
@mr-troll sorry to say but we have no fixer to remove that space. The rules we got are based on some of the bigger standards "out there" and non of these use the spaceless code style you want. You can code your own rule to do it based on one of the ones in the project if you really need this done.
mr-troll
@mr-troll

Hello @SpacePossum , Thank you for answer. Btw, I fixed this behaviour in "./src/Fixer/Basic/BracesFixer.php" and "src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php"
I completely dont know how to write custom fixers (I found some examples, and they are too complecated). I can give you my diffs, if you write some code to do this as some "preferences" it will be great. I know about PSR-2 and other "bigger standarts", but other formatters and linters based on just PSR have not many options. Like strictly use spaces instead of tabs, or "\n" ending instead of "\r\n", which I use for indenting, or the option "binary_operator_spaces" where I can set "no_space" for any operator I like. I like "php-cs-fixer" for its flexibility. Its not much code to add new indenting features "out of the box".

The code to remove spaces between method arguments was in:
"src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php"

+ 455:3:         $nextToken->override(array('', ''));
+ 456:3:         return;
- 475:3:             $tokens->insertAt($index + 1, new Token([T_WHITESPACE, ' ']));
+ 475:3:             //$tokens->insertAt($index + 1, new Token([T_WHITESPACE, ' ']));

Some my fixes for Spaces around Braces and Parentheses. in
"src/Fixer/Basic/BracesFixer.php"
There are actually 3 different features in this diff:
1) add the new line before T_ELSE, T_ELSEIF, I knew many people asked for it, its actually easy to separate getControlContinuationTokens, for those who asked
2) remove space around parentheses in control structures like "function () {", or "if (...) {"
3) fix indentation bug which i found in auto-added braces where
"else some();" transformed to
"else { some();}" - there should be line ending and $indent before closing brace;

+ 336:4:                 if (' ' === $tokens[$parenthesisEndIndex + 1]->getContent()) {
+ 337:4:                     $tokens[$parenthesisEndIndex + 1]->override(['', '']);
+ 338:4:                 }
+ 596:4:                 // fix for space after function parenthesis
+ 597:4:                 $tokens->removeTrailingWhitespace($closingParenthesisIndex);
- 638:4:             $tokens->insertAt($statementEndIndex + 1, [new Token([T_WHITESPACE, ' ']), new Token('}')]);
+ 638:4:             // Fix for wrong Indentation after autoinserted braces
+ 639:4:             $indent = $this->detectIndent($tokens, $index);
+ 640:4:             $tokens->insertAt($statementEndIndex + 1, [new Token($this->whitespacesConfig->getLineEnding().$indent), new Token('}')]);
+ 666:4:                     if (' ' === $tokens[$nextNonWhitespaceIndex - 1]->getContent()) {
+ 667:4:                         $tokens[$nextNonWhitespaceIndex - 1]->override(['', '']);
+ 668:4:                     }
+ 669:4:                     /*
+ 677:4:                     */
- 838:4:             T_ELSE,
+ 838:4:             //T_ELSE,
- 839:4:             T_ELSEIF,
+ 839:4:             //T_ELSEIF,
- 850:4:                 T_ELSE,
+ 850:4:                 //T_ELSE,
- 851:4:                 T_ELSEIF,
+ 851:4:                 //T_ELSEIF,
+ 891:4:         $tokens->removeLeadingWhitespace($startParenthesisIndex);
+ 896:4:         $tokens->removeTrailingWhitespace($endParenthesisIndex);

I never contibuted code to opensource, so if you can add this as a optional feature, I will be very grateful.

It would be nice if someone could review and give some feedback
We badly need this :(
Pol Dellaiera
@drupol
@mr-troll I can help you into writing your own custom Fixers. I've made a bunch of them.
@fotonmoton There is a PR written by @localheinz for this, see: FriendsOfPHP/PHP-CS-Fixer#4435 Looks like it needs some work.
@fotonmoton Regarding the max line length, I started to make one here: https://github.com/drupol/phpcsfixer-configs-drupal/blob/master/src/Fixer/LineLengthFixer.php
Pol Dellaiera
@drupol
@SpacePossum++
Pol Dellaiera
@drupol
Thanks for merging all these PR mate!
SpacePossum
@SpacePossum
you're all welcome :) sorry for the wait, I'm trying to catch up with all the great work the community did while I was out :+1:
Emil Godsk
@emg-amsiq
Good day. I was wondering if there is configuration for keeping indentations on empty lines? Cannot seem to find it myself.
Emil Godsk
@emg-amsiq
Can find the no_whitespace_in_blank_line - which removes whitespaces on empty lines. But cannot find one that adds to keep the indentation level
Dave van der Brugge
@dmvdbrugge
@emg-amsiq there probably is none because most of the community probably considers it bad practise.
SpacePossum
@SpacePossum
hi @emg-amsiq , as @dmvdbrugge described accurately we've no such rule :+1: we probable won't accept a FR for it either because it is not considered good practice within a bigger PHP community that uses the tool
Amir hossein Hossein Zadeh Karimi
@AmirHosseinKarimi
Hi, I'm looking a good config file to use in WordPress Theme and Plugin project, but I can not find this configuration file...
Is there anyone to help me get one config file or create a good config file that does not have conflict with WordPress coding standard?
Pol Dellaiera
@drupol
@AmirHosseinKarimi I don't know such config yet sorry. There is no such config for Drupal either.... and I did the configuration myself: https://github.com/drupol/phpcsfixer-configs-drupal
Maybe you can use that package as an inspiration :-)
Andi Rückauer
@arueckauer
Hello, is there a way to check/fix against PSR-12? (Could not find any doc, issue or PR.)
Dave van der Brugge
@dmvdbrugge
Select PSR-2 to begin with, and check all available rules. Enable the ones that match, create PRs adding new fixers for rules that are missing, and then add a PR adding PSR-12 as ruleset. (Warning: this might get declined if the maintainers are against it because it's not an official PSR (yet).)
Andi Rückauer
@arueckauer
Thanks for the information. It's currently being voted on. Fingers crossed, it will be accepted.
SpacePossum
@SpacePossum
interesting, please keep us informed @arueckauer ! : )
Pol Dellaiera
@drupol
I just submitted a PR to fix Travis builds: FriendsOfPHP/PHP-CS-Fixer#4494
It's based on 2.12, let me know if I should rebase it on master or not.
@SpacePossum ^^
Pol Dellaiera
@drupol
And this become green again! \o/ FriendsOfPHP/PHP-CS-Fixer#4275
Karácsony Kolos
@Koli14
Hi!
I'm totally new to PHP-CS-Fixer, but I already enjoy it a lot.
I use it in Sublime, and I get a lot of errors on my comments from my linter like:
phpcs: error error - Tag value for @since tag indented incorrectly; expected 2 spaces but found 4
I tried to use the docs of CS-Fixer, and tried out a lot of setting, but could not made it fix it automatically.
My .phpcsfixer file looks like this at the moment:
<?php
return PhpCsFixer\Config::create()
    ->setRules([
        '@PSR2' => true,
        'array_syntax' => ['syntax' => 'short'],
        'align_multiline_comment' => ['comment_type' => 'phpdocs_like'] ,
        'doctrine_annotation_indentation' => [ 'indent_mixed_lines' => true ]
    ]);
Pol Dellaiera
@drupol
PHPCS is not PHP CS Fixer
Try with more configuration option
Take example on this package that provides already made PHP configuration for you: `
Karácsony Kolos
@Koli14
I tried every options, what I find somehow related, but nothing worked:
<?php
return PhpCsFixer\Config::create()
    ->setRules([
        '@PSR2' => true,
        'array_syntax' => ['syntax' => 'short'],
        'align_multiline_comment' => ['comment_type' => 'all_multiline'] ,
        'heredoc_indentation' => true,
        'doctrine_annotation_indentation' => true,
        'doctrine_annotation_spaces' => [
            'after_argument_assignments' => true,
            'after_array_assignments_colon' => true,
            'after_array_assignments_equals' => true,
            'around_parentheses' => true,
            'before_argument_assignments' => true,
            'before_array_assignments_colon' => true,
            'before_array_assignments_equals' => true,
        ]
        'phpdoc_align' => true,
        'phpdoc_indent' => true,
        'phpdoc_order' => true,
        'phpdoc_separation' => true,
        'phpdoc_single_line_var_spacing' => true,
        'phpdoc_var_annotation_correct_order' => true,
        'psr4' => true,
        'psr0' => true,
        'no_unused_imports' => true,
    ]);
Pol Dellaiera
@drupol
Maybe this is just not supported?
João D. Ferreira
@jdferreira
Hi. I'm not sure this is the right venue to ask, but is there a way to fix code that exists solely in memory (as a string) without the need to store it somewhere in the file system?
Karácsony Kolos
@Koli14
@drupol Yes, that can be. Or I'm lame and don't find the right config.
SpacePossum
@SpacePossum
@jdferreira we support stdin from the command line, so no file is required (your string must make up valid PHP code/file)., is that something that could be of use?
@Koli14 can you provide a sample of the code that needs fixing?
Karácsony Kolos
@Koli14

@SpacePossum

    /**
     * The ID of this plugin.
     *
     * @since    1.0.0
     * @access   private
     * @var      string    $_plugin_name    The ID of this plugin.
     */
    private $_plugin_name;

And the error, what my linter says:

phpcs: error
error - Tag value for @since tag indented incorrectly; expected 2 spaces but found 4
error - Tag value for @access tag indented incorrectly; expected 1 spaces but found 3
error - Tag value for @var tag indented incorrectly; expected 4 spaces but found 6
João D. Ferreira
@jdferreira
@SpacePossum Thanks, that helps. However, I'm generating a file in PHP, and still need to spin up a new process to fix it, and if I could bypass the new process and ask my own PHP process to run the appropriate PHP-CS-Fixer code to fix the string it would be much quicker.
Jay Bienvenu
@jbnv
Also, is there a way to run CS-Fixer directly from code without having a configuration file?
acharris22306
@acharris22306
Is there a way to automatically generate a basic DockBlock for a method or a class if it does not exist already? I am currently developing a system to automatically do that and am wondering if that project is redundant
Chris McGee
@SturmB
Good afternoon. Can anyone please tell me how to get php-cs-fixer working in PhpStorm? Every set of instructions I've found online have failed.
Dave van der Brugge
@dmvdbrugge
What option are you trying? My favourite is the file watcher, but that requires (only slightly) more work than the quality tool.
(File watcher is automatically fixing, quality tool is only warnings)
Kevin Auvinet
@ke20
Hi all,
Why in the README file for the option we can read b_mode (bool): the b flag must be used (true) or omitted (false); defaults to true and in the project, the default value for this option is false ?
It's a bug or I don't understand ?
Dariusz Rumiński
@keradus
This message was deleted
@ke20 The default configuration of the fixer is true. Then, each project can use it with configuration it wants. In PHP CS Fixer project, we follow Symfony's ruleset configuration, that configures b_mode=false