nanch / phpfmt_stable

This is a stable snapshot (version 6125cf9) of the phpfmt plugin for Sublime Text
143 stars 34 forks source link

Space around "?" on nullable type hints #36

Open eddiriarte opened 7 years ago

eddiriarte commented 7 years ago

this:

protected function firstItem(): ?CustomClass
{
    if (count($this->list) < 1) {
        return null;
    }

    return $this->list[0];
}

is beeing transformed to....

protected function firstItem():  ? CustomClass
{
    if (count($this->list) < 1) {
        return null;
    }

    return $this->list[0];
}

Due to several complainings with my colleages I disabled the "space resizing"

"excludes":
[
    "ResizeSpaces"
],

... anyway maybe you could find a way to fix this in the next versions. THX

MKCG commented 6 years ago

A quick fix would be to replace the line 4903 of the fmt.stub.php file accessible after uncompressing the fmt.phar :

$this->appendCode(' ' . $text . $this->getSpace(!$this->rightTokenIs(ST_COLON)));

by :

$this->appendCode(' ' . $text . $this->getSpace(!$this->rightTokenIs(ST_COLON) && ($id !== ST_QUESTION || !$this->rightTokenIs(T_STRING))));

I made a repository to fix this issue : https://github.com/MKCG/phpfmt_7-1 It seems to work properly and have no side effect.

eddiriarte commented 6 years ago

hi, thx, gonna try this tomorrow at work. just quick reviewed your code and I was doing something similar few lines before... but i was forced to divide the ST_CONCAT and ST_QUESTION blocks in the switch(and duplicate some lines)... hope your solution is better ;) btw. i was using https://github.com/Shaked/php.tools to generate the phar... it has also some tests to check regressions.

kokororin commented 6 years ago

Hi, after change the following code, several tests are broken. By the way, Anyone want to join the phpfmt-next organization to continue developing ?