CommunityToolkit / CommunityToolkit/Maui
UseCommunityToolkitInitializationAnalyzer reformats my code
- Dominant language
- C#
- Stars
- 2.7k
- Forks
- 500
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 7
Description
### 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
1. Create a new .NET MAUI project
2. Add CommunityToolkit.Maui package reference
3. in MauiProgram.cs let the analyzer "fix" your code to add the `.UseCommunityToolkit()` call
4. Notice how it reformats your code and indents
Before:

After:

### Environment
```markdown
- .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](https://github.com/dotnet/roslyn-sdk/issues/1099) that makes this not work - I'm using MSTest which doesn't have this issue.
Contributor guide
Assessment
This issue has not been assessed yet.