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

Error in MSBuild package when code contains an acute accent #768

Closed
Meligy opened this issue Nov 28, 2022 · 4 comments · Fixed by #787
Closed

Error in MSBuild package when code contains an acute accent #768

Meligy opened this issue Nov 28, 2022 · 4 comments · Fixed by #787
Assignees
Labels
Milestone

Comments

@Meligy
Copy link

Meligy commented Nov 28, 2022

Let's say I have this enum:

public enum MeetingLocation
{
  Café,
  Restaurant
}

I can build the project just fine even though it has the acute accent (é).

But if I add the CSharpier MSBuild package, I get an error on build:

  Error <FULL_FILE_PATH> - Failed to compile so was not formatted.

Of course the file does not get formatted, but it does not block formatting other files or fail the build itself.

Adding the comment // csharpier-ignore to the beginning of the file or the previous line does not seem to help.

This is tested agains CSharpier.MsBuild@0.20.0, on .NET SDK 6.0.403.

The VS Code extension does not seem to have a problem (yes, I checked the extension logs).

@belav
Copy link
Owner

belav commented Nov 28, 2022

I wasn't able to reproduce this until I installed 6.0.403, as a workaround going back to 6.0.401 should get you past the problem.

This does not appear specific to csharpier.msbuild, when I install csharpier 0.20.0 in my test project the dotnet csharpier . command fails with the same error.

@belav belav added type:bug Something isn't working priority:high area:cli labels Nov 28, 2022
@belav belav added this to the 1.0.0 milestone Nov 28, 2022
@belav belav self-assigned this Nov 28, 2022
@Meligy
Copy link
Author

Meligy commented Nov 28, 2022

Wow. I totally did not expect it to be related to .NET SDK version. I mentioned it just to provide as much info as I could.

Thanks for the hint.

@belav
Copy link
Owner

belav commented Nov 28, 2022

I'm no longer sure downgrading will work. After downgrading I still have the problem. I did track it down to an issue with incorrectly detecting file encoding.

When the file is UTF8, csharpier is detecting it as SBCSCodePageEncoding, which leads to

    Café,
// instead of
    Café,

When I switch the file encoding to UTF-8-BOM, then csharpier can format the file.

I'm using https://github.com/CharsetDetector/UTF-unknown to do the file encoding detection, so this may be a bug with that library. The latest version of the library still has the issue.

Another option that will probably work is adding the file to a csharpierignore file, because then csharpier will not try to read the file at all. Using // csharpier-ignore requires that csharpier is able to compile the file in order to read the comments.

@belav
Copy link
Owner

belav commented Nov 28, 2022

So it appears that UTF.Unknown is detecting 3 possible encodings for a file with the given enum. UFT8 has a confidence of only .5, and windows-1250 has a confidence of .75. I opened this issue - CharsetDetector/UTF-unknown#159

If I remember correctly the IDE extensions stream all of the files to csharpier using UTF8. Which explains why you don't run into this issue with them. I an inclined to change csharpier to use UTF8 if it is in the possible detected encodings. But I don't know enough about file encodings to know if that could cause a problem for people.

belav added a commit that referenced this issue Nov 28, 2022
@belav belav modified the milestones: 0.21.0, 0.22.0 Nov 28, 2022
belav added a commit that referenced this issue Nov 29, 2022
belav added a commit that referenced this issue Jan 4, 2023
belav added a commit that referenced this issue Jan 9, 2023
belav added a commit that referenced this issue Jan 15, 2023
* Only read UTF8 and UTF8-BOM encoding

closes #768

* Removing UTF.Unknown

* Adding some comments for why we read without BOM

* Update Src/CSharpier.Cli/FileReader.cs

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

* formatting file

* see if this will fix the random build failures

* fix test

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
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants