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

BaselineNeonErrorFormatter: Sort errors by normalized relative path, … #536

Merged
merged 3 commits into from
Sep 9, 2021
Merged

BaselineNeonErrorFormatter: Sort errors by normalized relative path, … #536

merged 3 commits into from
Sep 9, 2021

Conversation

dktapps
Copy link
Contributor

@dktapps dktapps commented May 27, 2021

…instead of original absolute path

while in theory the net result should be the same (because the leading part of the path would be the same), / and \ have a different sorting order, so output gets sorted differently on Windows than on Linux.
This fixes phpstan/phpstan#5085.

…instead of original absolute path

while in theory the net result should be the same (because the leading part of the path would be the same), / and \ have a different sorting order, so output gets sorted differently on Windows than on Linux.
This fixes #5085.
@ondrejmirtes
Copy link
Member

Any change in src/ without change in tests/ is a red flag. Add a failing test first, thanks.

@ondrejmirtes ondrejmirtes force-pushed the master branch 2 times, most recently from efd31ce to 0471f87 Compare July 29, 2021 14:08
@ondrejmirtes
Copy link
Member

@dktapps Do you plan to finish this PR? Thanks.

@dktapps
Copy link
Contributor Author

dktapps commented Sep 8, 2021

Sorry, I forgot all about it. I'll try and find some time to finish it today.

@staabm
Copy link
Contributor

staabm commented Sep 9, 2021

Add a failing test first

@dktapps I think I have a failling test for the issue, but the fix proposed here seems to not fix it #667

@staabm staabm mentioned this pull request Sep 9, 2021
@dktapps
Copy link
Contributor Author

dktapps commented Sep 9, 2021

As I recall, last time I tried to write tests with this, I had some problem with SimpleRelativePathHelper not normalizing the separator.

@dktapps
Copy link
Contributor Author

dktapps commented Sep 9, 2021

I've added a test case. If you run it against the original code, the Error without path separators will appear in between the other two, like so:
image

With the change it passes as expected.

Copy link
Contributor

@mvorisek mvorisek left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -207,6 +207,9 @@ public function outputOrderingProvider(): \Generator
new Error('Second error in a different file', 'TestfileB', 4),
new Error('Error #1 in a different file', 'TestfileB', 5),
new Error('Second error in a different file', 'TestfileB', 6),
new Error('Error with Windows path separators', 'TestFiles\\TestA', 1),
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be named a "dir separator", not a "path separator" as the later means something else, see https://www.php.net/manual/en/dir.constants.php

Comment on lines +18 to +21
return str_replace('\\', '/', substr($filename, strlen($this->currentWorkingDirectory) + 1));
}

return $filename;
return str_replace('\\', '/', $filename);
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need the same fix in other implementations of RelativePathHelper ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not that I'm aware of. The one used for regular analysis already performs dirsep normalization.

@dktapps
Copy link
Contributor Author

dktapps commented Sep 9, 2021

Test failure looks unrelated.

@ondrejmirtes ondrejmirtes merged commit 1ef74b7 into phpstan:master Sep 9, 2021
@ondrejmirtes
Copy link
Member

Thank you!

@dktapps dktapps deleted the baseline-neon-sort-normalized-paths branch September 9, 2021 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants