-
Notifications
You must be signed in to change notification settings - Fork 4
refactor: convert NoMethodsInPropertySetupAnalyzer to IOperation #955
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
Changes from all commits
187a7c7
db78020
681e023
56866d6
962f7b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,12 @@ namespace Moq.Analyzers.Test.Helpers; | |
| /// </remarks> | ||
| public static class ReferenceAssemblyCatalog | ||
| { | ||
| /// <summary> | ||
| /// Gets the name of the reference assembly group for .NET 8.0 without Moq. | ||
| /// Used to test analyzer behavior when Moq is not referenced. | ||
| /// </summary> | ||
| public static string Net80 => nameof(Net80); | ||
|
|
||
| /// <summary> | ||
| /// Gets the name of the reference assembly group for .NET 8.0 with an older version of Moq (4.8.2). | ||
| /// </summary> | ||
|
|
@@ -32,6 +38,9 @@ public static class ReferenceAssemblyCatalog | |
| /// </remarks> | ||
| public static IReadOnlyDictionary<string, ReferenceAssemblies> Catalog { get; } = new Dictionary<string, ReferenceAssemblies>(StringComparer.Ordinal) | ||
| { | ||
| // .NET 8.0 without Moq, used to verify analyzers short-circuit when Moq is not referenced. | ||
| { nameof(Net80), ReferenceAssemblies.Net.Net80 }, | ||
|
|
||
|
Comment on lines
+41
to
+43
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update After adding 📝 Suggested doc fix /// <remarks>
-/// The key is the name of the reference assembly group (<see cref="Net80WithOldMoq"/> and <see cref="Net80WithNewMoq"/>).
+/// The key is the name of the reference assembly group
+/// (<see cref="Net80"/>, <see cref="Net80WithOldMoq"/>, and <see cref="Net80WithNewMoq"/>).
/// </remarks>As per coding guidelines, "All public APIs must have complete XML documentation with accurate, up-to-date content." 🤖 Prompt for AI Agents |
||
| // 4.8.2 was one of the first popular versions of Moq. Ensure this version is prior to 4.13.1, as it changed the internal | ||
| // implementation of `.As<T>()` (see https://github.com/devlooped/moq/commit/b552aeddd82090ee0f4743a1ab70a16f3e6d2d11). | ||
| { nameof(Net80WithOldMoq), ReferenceAssemblies.Net.Net80.AddPackages([new PackageIdentity("Moq", "4.8.2")]) }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation for finding the mocked method call mixes
IOperationwithSyntaxNodeanalysis by falling back toFindMockedMethodInvocationFromSetupMethod. This partially defeats the purpose of refactoring toIOperation.Additionally, the
FindMockedMethodInvocationFromSetupMethodhelper only works for expression-bodied lambdas (x => x.Method()) and will fail for block-bodied lambdas (x => { return x.Method(); }), asLambdaExpressionSyntax.Bodywould be aBlockSyntax.You can implement this logic purely using the
IOperationtree, which will be more robust and align better with the refactoring goal. This also provides an opportunity to correctly handle block-bodied lambdas.