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

XamlStyler.Console changes file without... changes #289

Closed
stefandevo opened this issue Jul 6, 2020 · 7 comments · Fixed by #379
Closed

XamlStyler.Console changes file without... changes #289

stefandevo opened this issue Jul 6, 2020 · 7 comments · Fixed by #379

Comments

@stefandevo
Copy link

Describe the bug
When I run the XamlStyler.Console dotnet tool on a folder, it processes all files, makes no change, because everything is OK, but changes the file in such a way that git adds modified file but without changes.

To Reproduce
Run the tool on a folder that is already formatted correctly.

Expected behavior
No file changes, and no git modified files.

@stefandevo stefandevo added the Bug label Jul 6, 2020
@grochocki
Copy link
Contributor

Thanks for the bug report! Have you tried running this with the passive flag (-p)? Could you share the exact command you are running?

@stefandevo
Copy link
Author

When I use the -p flag, then no files are written, but that's off course because of the fact that passive means you just check without modifications.
I use xstyler -d ./Forms/ -r in the root of my source tree (where my Settings.XamlStyler is).
If there aren't any modifications to be made, still all files get a modified flag in git (without no changes).

@grochocki
Copy link
Contributor

Ah, gotcha -- yea, we should not be writing anything on format if there are no changes.

@Tyrrrz
Copy link
Contributor

Tyrrrz commented Sep 24, 2020

@stefandevo @grochocki could it be that xstyler changes line endings in a file? For example, the original file could be using LF but after running xstyler it changes to CRLF, which git considers to be different.

@LWChris
Copy link

LWChris commented Oct 12, 2020

I noticed some things

  • this also happens in VS 2019 when you hit Ctrl+Shift+S to save the whole solution
  • but only after activating the first XAML file (having a XAML file open already when loading the solution but not activating it isn't enough)
  • saving will "modify" all unchanged, unopened XAML files
  • saving will "unmodify" the active XAML file
  • saving will not change an opened XAML file, no matter if currently "modified" or not according to the UI
  • the byte content of the "modified" and "unmodified" files match
  • their SHA256 hashes (using PowerShell's Get-FileHash) match
  • using "git status" says "no modifications"

@barnski
Copy link

barnski commented Jun 17, 2021

I find the behaviour on Ctrl+Shift+S problematic. XAML Styler formats then all the files in the solution, not those that need saving. Is there a way to work around that?

@michael-hawker
Copy link
Contributor

Ah, gotcha -- yea, we should not be writing anything on format if there are no changes.

It'd also be handy if XAML Styler Console returned a status code where 0 was success and nothing was modified or processed by the style options and 1 meant that a style needed to be updated and a file written.

This would help with CI validation of style enforcement by knowing if XAML Styler actually performed any work or not easily without having to check file statuses after the fact.

michael-hawker added a commit to michael-hawker/XamlStyler that referenced this issue Apr 1, 2022
…will be unchanged.

Modifies the log message to add an "(unmodified)" next to "Finished Processing" message to distinguish any files modified or not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants