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

Provide Line Ending option #285

Open
CyberBotX opened this issue May 29, 2020 · 7 comments · May be fixed by #295
Open

Provide Line Ending option #285

CyberBotX opened this issue May 29, 2020 · 7 comments · May be fixed by #295

Comments

@CyberBotX
Copy link

Is your feature request related to a problem? Please describe.
I usually prefer to have LF as my line endings instead of CRLF. Although I use an extension, Line Endings Unifier, to accomplish this, XAML Styler will always change the line endings to CRLF. Even if Line Endings Unifier changes the line endings afterwards, the result is that Visual Studio will claim the entire file has been changed because of the line endings being switched back and forth.

Describe the solution you'd like
I'd like to see an option in XAML Styler to set the line endings, with the options being CRLF, LF or CR (basically Windows, Unix and Mac line endings).

Describe alternatives you've considered
Using Line Endings Unifier does fix the line endings (when set to apply to .xaml) after saving and does so after XAML Styler has fixed the formatting. It does not get around the problem described at the top regarding Visual Studio showing the entire file as changed.

@virzak
Copy link
Contributor

virzak commented Aug 7, 2020

Should .editorconfig file be taken into account?

[*.xaml]
end_of_line              = crlf

This is an absolutely crucial feature.

@virzak
Copy link
Contributor

virzak commented Aug 8, 2020

@cyberbot band-aid solution:

Try running it with WSL (install it under Linux first)

Running it from ms-dos should look like this:

wsl /home/<username>/.dotnet/tools/xstyler -p -r -d Wpf -l Minimal

@virzak virzak linked a pull request Aug 16, 2020 that will close this issue
7 tasks
@grochocki
Copy link
Contributor

Have you configured git to handle line endings? If not, XAML Styler may not be the only offender, and this could help address it universally. If so, and XAML Styler is messing with line endings, I think we should treat this as a bug. We should not be changing line endings, and instead, if we can detect what they are in the input file, I would suggest we ensure it is preserved in the output.

@CyberBotX
Copy link
Author

My project doesn't use git at the moment. So yes, XAML Styler is messing with line endings.

@virzak
Copy link
Contributor

virzak commented Aug 24, 2020

@grochocki .gitattibutes is definitely helpful to ensure that line endings are standardized. It definitely works when a commit is performed. Microsoft recommends having * text eol=lf in certain situations.

There are other issues at play here. Consider a working environment with Windows OS, two IDEs VS and VS Code, as well as WSL.

  1. Pre-commit hooks: if one was to run xstyler -p -r -d MyWpf -l Minimal it would output different results under Linux and Windows and there is currently no way to enforce line ending, hence Create EndOfLine option #295. The goal is to fail the commit only for actual bad formatting, not a bad end of line character. .gitattibutes won't get a chance to do its conversion before the pre-commit hooks fails.

  2. Switching between VS Code and VS while editing a xaml file would keep changing the line ending. That's because VS Code respects .editorconfig end_of_line setting and XamlStyler doesn't. When it comes to .cs files, both IDEs respect the .editorconfig setting. I could send a PR including that as well.

  3. .gitattibutes setting generates annoying warnings every time the .xaml format doesn't match when staging changes.

@virzak
Copy link
Contributor

virzak commented Feb 24, 2021

@grochocki any thoughts on this?

@desiter
Copy link

desiter commented May 26, 2021

@grochocki, I wanted to introduce XamlStyler to my team's project but it overrides LF to CRLF in every file. Moreover it looks like the xstyler CLI tool adds BOM to the formatted output even if it wasn't there. Look like CFLF and utf-8 settings are hardcoded.

Version control settings could be a band-aid solution to fix the line-ending but my team is using LF on Windows too and we all don't override line-ending neither with git, perforce or other version control. In some cases we need to use both CRLF and LF in the same project and it's a conscious decision to configure it. For example in VS 2019 .editorconfig is the only way to configure line endings.

I agree with @virzak that XamlStyler can benefit a lot with either respecting the .editorconfig or providing it's own config property.

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.

4 participants