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

Use specified line endings in multiline comments. #550

Merged
merged 3 commits into from
May 25, 2022

Conversation

veelo
Copy link
Contributor

@veelo veelo commented May 23, 2022

fix #228

Copy link
Member

@WebFreak001 WebFreak001 left a comment

Choose a reason for hiding this comment

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

not sure if the tests folder is the right place for this, as git may change the line endings on different OSes or settings.

Note: the reason for this issue is that the comment tokens coming from libdparse are pasted as-is (tokens are never modified in dfmt) which is why the LF is kept in a CRLF file.

You would need to add replace code when outputting comments and strings (which will exhibit the same behavior) to fix this issue.

tests/issue0228.args Outdated Show resolved Hide resolved
@veelo
Copy link
Contributor Author

veelo commented May 24, 2022

not sure if the tests folder is the right place for this, as git may change the line endings on different OSes or settings.

Good point. I'll remove the files from the repository and generate them instead.

You would need to add replace code when outputting comments and strings (which will exhibit the same behavior) to fix this issue.

I think https://github.com/dlang-community/dfmt/pull/550/files#diff-f5d86cddb20837cd3a9f154e16b9a929d7b7d133ce71a5022127e5ec30d94a00 does the right thing. eolString is the platform-dependent standard line ending, or the specified one with --end_of_line.

test.d from #551 correctly detects #228, and this fixes it (barring your point above).

@veelo
Copy link
Contributor Author

veelo commented May 24, 2022

eolString is the platform-dependent standard line ending [...]

I take that back. It currently is LF by default, see #552.

Multi-line tokens would be written with `lf`, regardless the `end_of_line` setting.

Fixes dlang-community#228.
@veelo
Copy link
Contributor Author

veelo commented May 24, 2022

not sure if the tests folder is the right place for this, as git may change the line endings on different OSes or settings.

If everything works as advertised, this shouldn't be happening courtesy .gitattributes that I added.

I had to rewrite this slightly to work properly for all kinds of line endings in the input.

@veelo veelo requested a review from WebFreak001 May 24, 2022 16:04
@veelo veelo changed the title WIP crlf in multiline comments, #228 Use specified line endings in multiline comments. May 24, 2022
output.put(current.text.replace("\r", ""));
else
output.put(current.text);
output.put(current.text.lineSplitter.joiner(eolString));
Copy link
Contributor Author

@veelo veelo May 24, 2022

Choose a reason for hiding this comment

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

For a moment I thought this would omit the trailing newline. But dfmt always ends the output with a newline even if the input doesn't, so it's good. #551 will detect if this ever changes.

Copy link
Member

Choose a reason for hiding this comment

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

instead of doing the short and easy, but memory intensive way, how about adding a helper function that first checks if there are non-conforming line-endings and then runs the lineSplitter + appends it all on it?

Copy link
Member

Choose a reason for hiding this comment

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

nvm I just realized these are ranges and should be fine as is

@WebFreak001 WebFreak001 merged commit f81ddea into dlang-community:master May 25, 2022
@veelo
Copy link
Contributor Author

veelo commented May 25, 2022

Thanks.

@veelo veelo deleted the issue0228 branch May 25, 2022 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

end_of_line=crlf produces lf in multiline comments
2 participants