Skip to content

Fix MA0110 to handle property initializers#1014

Merged
meziantou merged 7 commits intomainfrom
copilot/fix-property-initializer-handling
Feb 19, 2026
Merged

Fix MA0110 to handle property initializers#1014
meziantou merged 7 commits intomainfrom
copilot/fix-property-initializer-handling

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 19, 2026

Fix MA0110 to handle property initializers

  • Add IPropertyInitializerOperation detection in fixer
  • Add comprehensive tests for property initializer scenarios
  • Fix source generator loading to use NuGet packages instead of hard-coded paths
  • Automatically load source generators for .NET 7+ frameworks
  • Make source generator loading gracefully handle missing analyzers path in older packages
  • Remove explicit WithRegexSourceGenerator calls from tests
  • All 51 tests pass

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix property initializer handling in MA0110 code Fix MA0110 code fix to handle property initializers Feb 19, 2026
Copilot AI requested a review from meziantou February 19, 2026 02:09
.WithLanguageVersion(Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp14)
.WithAnalyzer<UseRegexSourceGeneratorAnalyzer>()
.WithCodeFixProvider<UseRegexSourceGeneratorFixer>()
.WithNoFixCompilation()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Remove the WithNoFixCompilation, all tests in this file must compile. Be sure to target C# 14 if needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed .WithNoFixCompilation() from the property initializer tests and wrapped them in #if CSHARP14_OR_GREATER. However, the tests fail because GeneratedRegex attribute requires the Regex source generator to run during compilation, which doesn't happen in unit tests.

The tests currently use partial methods (index 1) which keep the property and change the initializer to call a generated method. This approach compiles without the source generator, but still requires .WithNoFixCompilation() because the partial method needs an implementation.

Should I:

  1. Add source generator support to the test infrastructure?
  2. Remove the property initializer tests entirely?
  3. Use a different approach that doesn't require GeneratedRegex?

All other tests with GeneratedRegex in the file also use .WithNoFixCompilation() (line 16), so I'm not sure how to make these tests compile without it.

Copilot AI changed the title Fix MA0110 code fix to handle property initializers Fix MA0110 to handle property initializers Feb 19, 2026
return this;
}

public ProjectBuilder WithRegexSourceGenerator()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot This logic is wrong. Use the TargetFramework, and the analyzer which is part of the Microsoft.NETCore.App.Ref package (e.g. analyzers/dotnet/cs/System.Text.RegularExpressions.Generator.dll).

In fact, I wonder if the source generators should always be loaded?

@meziantou
Copy link
Copy Markdown
Owner

@copilot The CI is failing. Can you have a look?

@meziantou meziantou marked this pull request as ready for review February 19, 2026 05:25
@meziantou meziantou merged commit 9666cc4 into main Feb 19, 2026
12 checks passed
@meziantou meziantou deleted the copilot/fix-property-initializer-handling branch February 19, 2026 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants