dotnet / format

Home for the dotnet-format command

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dotnet format reporting wrong (line, character) for WHITESPACE error

jamallucas opened this issue · comments

When I run

dotnet format --verbosity detailed

I get "File.cs(1,1): error WHITESPACE: Fix whitespace formatting."
for the fix on line 12

before: if(intVariable == 0)
after: if (intVariable == 0)

The fix adds a space after the if, which is on line 12 and char number 15. The tool reports that the change was done on line 1, character 1.

When I run

dotnet format --report .

I also get the wrong values for line and character number

"FileChanges": [
      {
        "LineNumber": 1,
        "CharNumber": 1,
        "DiagnosticId": "WHITESPACE",
        "FormatDescription": "Fix whitespace formatting."
      }
    ]

However if I add --verify-no-changes then I get the right information

dotnet format --verify-no-changes --verbosity detailed
gives me
File.cs(12,15): error WHITESPACE: Fix whitespace formatting. Insert '\s'.

and
dotnet format --verify-no-changes --report .
also returns the right information

"FileChanges": [
      {
        "LineNumber": 12,
        "CharNumber": 15,
        "DiagnosticId": "WHITESPACE",
        "FormatDescription": "Fix whitespace formatting."
      }
    ]

We can probably just change our whitespace formatter to always request detailed changes.

if (formatOptions.SaveFormattedFiles)
{
return await GetFormattedDocument(document, optionSet, cancellationToken).ConfigureAwait(false);
}
else
{
return await GetFormattedDocumentWithDetailedChanges(document, sourceText, optionSet, cancellationToken).ConfigureAwait(false);
}