3

I am currently using PHP_Beautifier for formatting code with the following command like options

-t -l "ArrayNested() IndentStyles(style=bsd) NewLines(before=T_CLASS:function:T_COMMENT,after=T_COMMENT)"

It works great except for the fact that it strips out all the blank lines. After a bit of searching, I found it posted as a bug that is open since 2007.

I tried looking into the codebase but was unable to locate the specific code that does this. I appreciate any help I can get in the right direction.

durron597
  • 31,968
  • 17
  • 99
  • 158
Sukumar
  • 3,502
  • 3
  • 26
  • 29

2 Answers2

3

I'm clbustos, the developer of PHP_Beautifier. This is one of the most requested features, so I expected to implement it on the next release. If you want to dig, the function to see if PHP_Beautifier::removeWhitespace

clbustos
  • 156
  • 6
1

Also needing this beautifier, while preserving blank lines in the sources.

I did check out the last version of this script, and I've done a dirty hack (not being a PHP dvpr...) : commenting two lines in the file beautifier.php in the function public function removeWhitespace()

 for ($i = count($this->aOut) -1 ; $i >= 0 ; $i--) { // go backwards
            $cNow = &$this->aOut[$i];
            if (strlen(trim($cNow)) == 0) { // only space
                if (!$this->addedBlankLine || ($cNow!="\r" && $cNow!="\n")) {
                      //array_pop($this->aOut); // delete it!
                      //$pop++;****
                }
            } else { // we find something!
                $cNow = rtrim($cNow); // rtrim out
                break;
            }
        }

This hack does preserve all the blank lines, but there's a side effect : some unwanted lines appears after brackets, and all the tabs characters are not replaced, but it's better for me than not having blank lines...

Phil
  • 11
  • 2