UseCommunityToolkitInitializationAnalyzer reformats my code
Is there an existing issue for this?
- [X] I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- [X] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
The codefixer for adding the UseCommunityToolkit call will reformat my code.
Expected Behavior
Keep my original indentations - this is especially important for a more complex set of code here that I don't want reformatted. The specific example below isn't super bad, but as this build expression grows and becomes more complex, this autofix gets very annoying. If I want VS to reformat, I'll just use the VS tooling explicitly.
Steps To Reproduce
- Create a new .NET MAUI project
- Add CommunityToolkit.Maui package reference
- in MauiProgram.cs let the analyzer "fix" your code to add the
.UseCommunityToolkit()call - Notice how it reformats your code and indents
Before:
After:
Environment
- .NET MAUI CommunityToolkit: 7.0.1
Anything else?
Issue is caused by the NormalizeWhitespace call here:
https://github.com/CommunityToolkit/Maui/blob/739c843b8d5407739797806837ec63fe2b0910ca/src/CommunityToolkit.Maui.Analyzers.CodeFixes/UseCommunityToolkitInitializationAnalyzerCodeFixProvider.cs#L66
You might also want to enhance your unit tests to test the code fixer. See my version of your analyzer with those tests added here: https://github.com/Esri/arcgis-maps-sdk-dotnet-toolkit/blob/19aea6002b41f539d6cbad0b5e533f3d2dc9c5c9/src/Analyzers/Toolkit.Maui.Analyzers.UnitTests/UseToolkitInitializationAnalyzerTests.cs#L75-L129 Note: There's a bug in xunit that makes this not work - I'm using MSTest which doesn't have this issue.