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

UseCommunityToolkitInitializationAnalyzer reformats my code #1720

Open
2 tasks done
dotMorten opened this issue Feb 28, 2024 · 0 comments
Open
2 tasks done

UseCommunityToolkitInitializationAnalyzer reformats my code #1720

dotMorten opened this issue Feb 28, 2024 · 0 comments
Labels
area/core Issue/Discussion/PR that has to do with the core of the toolkit bug Something isn't working

Comments

@dotMorten
Copy link

dotMorten commented Feb 28, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

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:
image
After:
image

Environment

- .NET MAUI CommunityToolkit: 7.0.1

Anything else?

Issue is caused by the NormalizeWhitespace call here:

newRoot = compilationSyntax.AddUsings(mauiCommunityToolkitUsingStatement).NormalizeWhitespace();

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.

@dotMorten dotMorten added bug Something isn't working unverified labels Feb 28, 2024
@vhugogarcia vhugogarcia added the area/core Issue/Discussion/PR that has to do with the core of the toolkit label Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core Issue/Discussion/PR that has to do with the core of the toolkit bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants