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

Correctly format files with dos line endings #81

Merged
merged 3 commits into from
Sep 23, 2023

Conversation

nikhilraojl
Copy link
Contributor

Closes #80

I did this the simplest way, but it may not be the right way. Please suggest if something can be improved or changed

printer/src/algorithm.rs Outdated Show resolved Hide resolved
printer/src/algorithm.rs Outdated Show resolved Hide resolved
printer/src/algorithm.rs Outdated Show resolved Hide resolved
}
}

pub fn set_dos(&mut self, value: bool) {
Copy link
Owner

@bram209 bram209 Sep 20, 2023

Choose a reason for hiding this comment

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

we could pass this to the constructor of Printer instead, no need for a setter in that case.
(I don't think you would ever switch to a different line ending style halfway formatting, so it does not have to be mutable)

@bram209
Copy link
Owner

bram209 commented Sep 20, 2023

hey, thanks for your contribution!

I am not really a fan of platform specific line endings. Files are transferred from one platform to the other, etc. And I believe on the reading side every editor would be able to read LF line endings? I haven't use windows in ages, but I think you could configure git to automatically convert line endings to LF.

Anyhow, it is still nice to support this. Code looks good to me, only have some very minor suggestions (mostly naming), well done 👍

@bram209
Copy link
Owner

bram209 commented Sep 20, 2023

I think most people will be fine with having the formatter automatically detect line endings, but if you feel like it, you could also add a configuration option newline_style to FormatterSettings like so:

https://github.com/bram209/leptosfmt/blob/main/formatter/src/formatter/mod.rs#L38

This could have the following variants: Auto, Native, Windows, Unix.

Where Native you could use conditional compilation, like so:

val crlf_line_endings =  cfg!(windows) 

But if you want to leave it at what you currently have, that is perfectly fine as well : )

@nikhilraojl
Copy link
Contributor Author

nikhilraojl commented Sep 21, 2023

I haven't use windows in ages, but I think you could configure git to automatically convert line endings to LF.

CRLF is default on windows. But git will replace CRLF as LF when a commit is done, but files will stay as CRLF for editing locally. I understand this is not good but that's windows 🤷 . I will try to move away from CRLF

I think most people will be fine with having the formatter automatically detect line endings, but if you feel like it, you could also add a configuration option newline_style to FormatterSettings like so:

I would like to do this later as I don't conditional compilation stuff yet. Will definitely give it a go later

@bram209 bram209 enabled auto-merge (squash) September 23, 2023 07:56
@bram209 bram209 merged commit 0f9c511 into bram209:main Sep 23, 2023
bram209 pushed a commit that referenced this pull request Sep 25, 2023
* Correctly format files with dos line endings

* Refactor and naming improvements

* Avoid panic on empty file

[skip ci] Update CHANGELOG.md

[skip ci] Update CHANGELOG.md
bram209 pushed a commit that referenced this pull request Sep 25, 2023
* Correctly format files with dos line endings

* Refactor and naming improvements

* Avoid panic on empty file

[skip ci] Update CHANGELOG.md

[skip ci] Update CHANGELOG.md
@nikhilraojl nikhilraojl deleted the format_dos_files branch October 1, 2023 07:09
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.

Formatter changing file format from dos -> unix
2 participants