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

Line endings not set #935

Closed
phuhl opened this issue Aug 22, 2023 · 3 comments · Fixed by #960
Closed

Line endings not set #935

phuhl opened this issue Aug 22, 2023 · 3 comments · Fixed by #960

Comments

@phuhl
Copy link

phuhl commented Aug 22, 2023

It seems that running dotnet-csharpier . on our project folder does not do anything about line endings. Files that have "lf" line endings keep them, files that have "crlf" keep them, too.

I'd expect that one of the two is chosen and applied.

Am I doing something wrong?

@phuhl
Copy link
Author

phuhl commented Aug 22, 2023

Ok, it seems that csharpier by default uses the EndOfLine.Auto mode. Changing the first line in a file from LF to CRLF makes csharpier reformat the whole file and vice versa.

I'd argue, csharpier should behave differently and pick one line ending as otherwise you still have different OSes with different line endings that might interfere and constantly change line endings from the one to the other.

@belav
Copy link
Owner

belav commented Aug 22, 2023

The current behavior is taken from prettier. Originally CSharpier exposed options for Auto, CRLF and LF, but that was removed early on. If CSharpier were to use only LF, I assume that would make some windows users unhappy, and vice versa.

Another option would be to read the first file to determine which line ending to use, but if that first file changes, or if the first file is not always consistent then things could also flip back and forth.

The advice we've followed at work is to get all of the line endings consistent, and then use a .gitattributes file with * text=auto, which checks out the file with CRLF on windows, but commits it as LF. And non-windows leaves it as LF.

I'm not opposed to re-exposing the options for line endings, which would solve your problem and also allow people to easily do a one time cleanup before changing it back to auto.

@phuhl
Copy link
Author

phuhl commented Aug 22, 2023

Ah, interesting, I did not know about the situation at prettierjs. Apparently, the current solution prettierjs uses is by default to enforce LF but a config option exists that can be set to auto, cr, lf, or crlf (https://prettier.io/docs/en/options.html#end-of-line).

For our team, re-exposing the existing option would solve our issue :)

@belav belav added this to the 0.26.0 milestone Aug 22, 2023
belav added a commit that referenced this issue Sep 10, 2023
belav added a commit that referenced this issue Sep 17, 2023
* Re-add support for line endings being configurable.

closes #935

* Format file

* Update Src/CSharpier.Cli/Options/CaseInsensitiveEnumConverter.cs

Co-authored-by: Lasath Fernando <devel@lasath.org>

---------

Co-authored-by: Lasath Fernando <devel@lasath.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants