dotnet / format

Home for the dotnet-format command

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dotnet format whitespace --verify-no-changes fails on"/" char

Nowak-Kacper opened this issue · comments

Hi everyone,
as in title dotnet format whitespace --verify-no-changes fails in lines where "/" char is.
I am running command with git workflow so it might be related to this.

Error:
Program.cs(6,3): error WHITESPACE: Fix whitespace formatting. Replace 4 characters with '\n\t\t'.
Program.cs(12,1): error WHITESPACE: Fix whitespace formatting. Replace 2 characters with '\t\t'.

This is the content of my .gitattributes file:
Set the default behavior, in case people don't have core.autocrlf set.
*/ text=auto
Declare files that will always have CRLF line endings on checkout.
**/*.cs text eol=crlf

From the whitespace errors it appears to be trying to fixup indentation by replacing characters with tabs. Is it possible there are mixed spaces and tabs? Also, are the line numbers accurate?

  1. Line numbers are good, sometimes error is pointing to the line above/under thie line with "/" characters
  2. Indents are correct, no mixed spaces/tabs
    For more context i can add that i have over 700 errors and all of them are in lines with "/" or above/down

One more error example, maybe it will bring something new.
(233,4): error WHITESPACE: Fix whitespace formatting. Replace 5 characters with '\n\t\t\t'.
(234,14): error WHITESPACE: Fix whitespace formatting. Replace 5 characters with '\n\t\t\t'.
(242,47): error WHITESPACE: Fix whitespace formatting. Replace 7 characters with '\n\n\t\t\t'.
(244,10): error WHITESPACE: Fix whitespace formatting. Replace 5 characters with '\n\t\t\t'.
(246,44): error WHITESPACE: Fix whitespace formatting. Replace 7 characters with '\n\n\t\t\t'.
(248,13): error WHITESPACE: Fix whitespace formatting. Replace 5 characters with '\n\t\t\t'.
In file all indents are ok, locally i can not reproduce this error.

Declare files that will always have CRLF line endings on checkout.
**/*.cs text eol=crlf

So we are always checking these files out with windows line endings. Does your .editorconfig also specify end_of_line=crlf for *.cs files? Otherwise, the formatter will default to the platform specific line ending.

Currently not, previously I had it but there was more errors than now, should I bring it back? If yes, how should I update some files on git to crlf format? By running git ls-files --eol I see some files are in lf.

I tried to run git add --renormalize . with eol set to crlf in .gitattributes and .editorcong but it overwrites only files in crlf format, and seems to be ignoring the lf files.

Already done this, just to be sure I did it again today, but some files are still in lf format.
Part of output from git ls-files --eol

i/mixed w/crlf  attr/
i/crlf  w/crlf  attr/
i/crlf  w/crlf  attr/
i/mixed w/crlf  attr/
i/crlf  w/crlf  attr/
i/lf    w/crlf  attr/ 
i/lf    w/crlf  attr/ 
i/lf    w/crlf  attr/ 
i/crlf  w/crlf  attr/
i/lf    w/crlf  attr/ 
i/lf    w/crlf  attr/ 
i/lf    w/crlf  attr/ 
i/crlf  w/crlf  attr/
i/lf    w/crlf  attr/
i/lf    w/crlf  attr/
i/crlf  w/crlf  attr/

Not saying this is the issue, just something I noticed after looking at a few .gitattributes files (see https://grep.app/search?q=.cs+text+eol). You could simplify yours by removing the directory separators.

# Set the default behavior, in case people don't have core.autocrlf set.
- */ text=auto
+ * text=auto
# Declare files that will always have CRLF line endings on checkout.
- **/*.cs text eol=crlf
+ *.cs text eol=crlf

Not sure how much more help I can be. In the absence of an end_of_line settings in the .editorconfig, dotnet-format will default to using the environment newline for line endings, which may not match your .gitattributes configuration. So, if you are not letting git automatically handle line endings you will want to configure your .editorconfig to match.