-
Notifications
You must be signed in to change notification settings - Fork 665
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
Harmonise line endings in baseline for multi-line code snippets #9239
Comments
Hey @jon48, can you reproduce the issue on https://psalm.dev ? |
This cannot be reproduced there, as there is no baseline capability, nor CRLF/LF setting. |
The underlying issue is with |
Yes, I am not denying that, and as you are saying the Windows installer for git set My suggestion was only to try and normalise the CRLF to LF when creating and comparing the baseline, so that the result do not depend on the user having chosen all the correct settings to use LF in a Windows environment. |
I am facing the same issue, but it's not because of GIT. I disabled |
I fixed it with How do I force Git to use LF instead of CR+LF under Windows? After you disable autocrlf you have to refresh the working tree. |
Hello,
This is bug very similar to #5979, but contrary to this initial issue, my problems comes when the
code
element of the baseline contains a multi-line snippet. The fix was totrim
the code content (that was relocated as part of the 5.x upgrade, but the idea remains the same), but that would remove only the characters at the beginning or the end of the string, but do not cater for potential carriage returns and line feeds inside the string.So, depending on whether CRLF or LF mode is used, when the baseline is generated and/or compared, there may be respectively additional or missing
characters in the baseline file, that means that errors are not recognised as part of the baseline if the environment do not use the same line ending. In my case, my dev environment is Windows, using CRLF, where the baseline is produced and I can get the "No errors found!" result, whilst the GitHub actions use a Linux environment, and LF mode, and fail (on a message not clear at all, as it seems identical to the baseline).I feel that the in the line below, there should be an harmonisation of the line endings, by maybe dropping the
entity if present, so that CRLF will be harmonised to LF. Of course, this is not the only change that would be required, and that mayneed to wait Psalm 6, or have an alternative solution, as this is maybe a breaking change.
psalm/src/Psalm/ErrorBaseline.php
Line 121 in 4eacb2f
I have tried to showcase it in the small example attached. (hopefully, it will make sense).
Using Psalm 5.6.0, I have created the same code twice, once in a file with CRLF endings, one with LF endings, to simulate the two environments. The anonymous function will of course raise an error, as an
int
is expected rather thanbool
.Taking the CRLF as reference for the baseline, it generates the below (which I manually duplicate for
test.LF.php
). Please note the
entities to encode the carriage return; the line feed is not encoded, and is a line break in the file.Then, I run for the CRLF environment:
Running on CRLF environment
And for the LF environment, using the same baseline file:
Running on LF environment
The LR environment throws an error (with a "displayed" code identical to the one in the baseline, but the line endings are actually different), whereas the CRLF completes fine. I would expect both environments to complete successfully with the same baseline, as the code is seemingly the same.
The text was updated successfully, but these errors were encountered: