Fix MA0110 to handle property initializers#1014
Conversation
Co-authored-by: meziantou <[email protected]>
Co-authored-by: meziantou <[email protected]>
| .WithLanguageVersion(Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp14) | ||
| .WithAnalyzer<UseRegexSourceGeneratorAnalyzer>() | ||
| .WithCodeFixProvider<UseRegexSourceGeneratorFixer>() | ||
| .WithNoFixCompilation() |
There was a problem hiding this comment.
@copilot Remove the WithNoFixCompilation, all tests in this file must compile. Be sure to target C# 14 if needed
There was a problem hiding this comment.
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:
- Add source generator support to the test infrastructure?
- Remove the property initializer tests entirely?
- 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.
Co-authored-by: meziantou <[email protected]>
Co-authored-by: meziantou <[email protected]>
| return this; | ||
| } | ||
|
|
||
| public ProjectBuilder WithRegexSourceGenerator() |
There was a problem hiding this comment.
@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?
Co-authored-by: meziantou <[email protected]>
|
@copilot The CI is failing. Can you have a look? |
Co-authored-by: meziantou <[email protected]>
Fix MA0110 to handle property initializers
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.