Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(PhpcsFormatter): remove last PHP_EOL before parsing json #684

Closed
wants to merge 2 commits into from

Conversation

matiasfuster
Copy link
Contributor

Q A
Branch master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Documented? yes
Fixed tickets #662

5 months ago a commit changes how PHPCS ends the json report by adding a new line at the end. You can see here: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Reports/Json.php#L101

This messes up the PhpcsFormatter because the last "\n" that finds is the new PHP_EOL that is added to de report.

With this fix it won't print the json report and will prompt for autofixing like before.

No

@matiasfuster
Copy link
Contributor Author

Any updates on this??

@@ -24,7 +24,7 @@ public function format(Process $process): string
return $process->getErrorOutput();
}

$pos = strrpos($output, "\n");
$pos = strrpos(trim($output), "\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to do this trim at line 22 instead?
That way, the code always works with the normalized version.
(Now $pos works on a different output value then the substr method)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch works for me, where I have the same "rogue" JSON output. I'm using 0.16.1

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until this is patched, we can run the following:

sed -i 's#$pos = strrpos($output, "\\n");#$pos = strrpos(trim($output), "\\n");#g' vendor/phpro/grumphp/src/Formatter/PhpcsFormatter.php

@veewee
Copy link
Contributor

veewee commented Oct 10, 2019

Thanks for reporting @matiasfuster! I added a small remark. Besides that : all good for me.

@veewee veewee added this to the 0.16.2 milestone Oct 10, 2019
@matiasfuster
Copy link
Contributor Author

Hi! Problem with adding it at 22 is that in older versions it would trim the last “}” of the json report. This way it just removes de EOL. Do you agree?

@veewee
Copy link
Contributor

veewee commented Oct 10, 2019

No : trim only removes whitespace characters if you don't specify a character mask.

@matiasfuster
Copy link
Contributor Author

You are right, i'm still asleep! Closing and resubmitting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants