From 942fa5aa500130543d5c266cc48729608d23be79 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Jul 2025 00:44:09 +0000 Subject: [PATCH 1/2] Initial plan From 46fb92099fe1e49c15516f009c709129baceacdf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Jul 2025 01:01:11 +0000 Subject: [PATCH 2/2] feat: update AsShouldBeUsedOnlyForInterfaceAnalyzer metadata as requested Co-authored-by: rjmurillo <6811113+rjmurillo@users.noreply.github.com> --- src/Analyzers/AnalyzerReleases.Unshipped.md | 1 + .../AsShouldBeUsedOnlyForInterfaceAnalyzer.cs | 10 ++++++---- src/Common/DiagnosticCategory.cs | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Analyzers/AnalyzerReleases.Unshipped.md b/src/Analyzers/AnalyzerReleases.Unshipped.md index 196fcd259..fe53379f9 100644 --- a/src/Analyzers/AnalyzerReleases.Unshipped.md +++ b/src/Analyzers/AnalyzerReleases.Unshipped.md @@ -11,6 +11,7 @@ Moq1205 | Moq | Warning | EventSetupHandlerShouldMatchEventTypeAnalyzer Moq1206 | Moq | Warning | ReturnsAsyncShouldBeUsedForAsyncMethodsAnalyzer Moq1207 | Moq | Error | SetupSequenceShouldBeUsedOnlyForOverridableMembersAnalyzer Moq1210 | Moq | Error | VerifyShouldBeUsedOnlyForOverridableMembersAnalyzer +Moq1300 | Usage | Error | AsShouldBeUsedOnlyForInterfaceAnalyzer (updated category from Moq to Usage) Moq1301 | Moq | Warning | Mock.Get() should not take literals Moq1302 | Moq | Warning | LINQ to Mocks expression should be valid (flags non-virtual members including fields, events, nested and chained accesses) Moq1420 | Moq | Info | RedundantTimesSpecificationAnalyzer diff --git a/src/Analyzers/AsShouldBeUsedOnlyForInterfaceAnalyzer.cs b/src/Analyzers/AsShouldBeUsedOnlyForInterfaceAnalyzer.cs index c008d6a7a..69c724411 100644 --- a/src/Analyzers/AsShouldBeUsedOnlyForInterfaceAnalyzer.cs +++ b/src/Analyzers/AsShouldBeUsedOnlyForInterfaceAnalyzer.cs @@ -9,15 +9,17 @@ namespace Moq.Analyzers; public class AsShouldBeUsedOnlyForInterfaceAnalyzer : DiagnosticAnalyzer { private static readonly LocalizableString Title = "Moq: Invalid As type parameter"; - private static readonly LocalizableString Message = "Mock.As() should take interfaces only"; + private static readonly LocalizableString Message = "Mock.As() should take interfaces only, but '{0}' is not an interface"; + private static readonly LocalizableString Description = "Mock.As() should take interfaces only."; private static readonly DiagnosticDescriptor Rule = new( DiagnosticIds.AsShouldOnlyBeUsedForInterfacesRuleId, Title, Message, - DiagnosticCategory.Moq, + DiagnosticCategory.Usage, DiagnosticSeverity.Error, isEnabledByDefault: true, + description: Description, helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/{ThisAssembly.GitCommitId}/docs/rules/{DiagnosticIds.AsShouldOnlyBeUsedForInterfacesRuleId}.md"); /// @@ -76,7 +78,7 @@ private static void Analyze(OperationAnalysisContext context, ImmutableArray generic type argument and report the diagnostic on it GenericNameSyntax? asGeneric = invocationOperation.Syntax @@ -86,7 +88,7 @@ private static void Analyze(OperationAnalysisContext context, ImmutableArray