Skip to content

Commit

Permalink
Remove period from analyzer messages and inline in the analyzer class…
Browse files Browse the repository at this point in the history
…es (#86)

Fix RS1032 by removing the period from the end of the analyzer messages.
I also inlined the constants into the appropriate analyzer class instead
of in a shared constants class. This makes future refactoring of the
tests easier, as now the analyzer's ID is part of the analyzer itself.

I also filed #85 to track potential changes to our message and
categories.
  • Loading branch information
MattKotsenas authored Jun 13, 2024
1 parent 548ec1c commit 46df790
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 79 deletions.
14 changes: 9 additions & 5 deletions Source/Moq.Analyzers/AsShouldBeUsedOnlyForInterfaceAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ namespace Moq.Analyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class AsShouldBeUsedOnlyForInterfaceAnalyzer : DiagnosticAnalyzer
{
internal const string RuleId = "Moq1300";
private const string Title = "Moq: Invalid As type parameter";
private const string Message = "Mock.As() should take interfaces only";

private static readonly MoqMethodDescriptorBase MoqAsMethodDescriptor = new MoqAsMethodDescriptor();

private static readonly DiagnosticDescriptor Rule = new(
Diagnostics.AsShouldBeUsedOnlyForInterfaceId,
Diagnostics.AsShouldBeUsedOnlyForInterfaceTitle,
Diagnostics.AsShouldBeUsedOnlyForInterfaceMessage,
Diagnostics.Category,
RuleId,
Title,
Message,
DiagnosticCategory.Moq,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{Diagnostics.AsShouldBeUsedOnlyForInterfaceId}.md");
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{RuleId}.md");

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ namespace Moq.Analyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class CallbackSignatureShouldMatchMockedMethodAnalyzer : DiagnosticAnalyzer
{
internal const string RuleId = "Moq1100";
private const string Title = "Moq: Bad callback parameters";
private const string Message = "Callback signature must match the signature of the mocked method";

private static readonly DiagnosticDescriptor Rule = new(
Diagnostics.CallbackSignatureShouldMatchMockedMethodId,
Diagnostics.CallbackSignatureShouldMatchMockedMethodTitle,
Diagnostics.CallbackSignatureShouldMatchMockedMethodMessage,
Diagnostics.Category,
RuleId,
Title,
Message,
DiagnosticCategory.Moq,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{Diagnostics.CallbackSignatureShouldMatchMockedMethodId}.md");
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{RuleId}.md");

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CallbackSignatureShouldMatchMockedMethodCodeFix : CodeFixProvider
{
public sealed override ImmutableArray<string> FixableDiagnosticIds
{
get { return ImmutableArray.Create(Diagnostics.CallbackSignatureShouldMatchMockedMethodId); }
get { return ImmutableArray.Create(CallbackSignatureShouldMatchMockedMethodAnalyzer.RuleId); }
}

public sealed override FixAllProvider GetFixAllProvider()
Expand Down
14 changes: 9 additions & 5 deletions Source/Moq.Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ namespace Moq.Analyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class ConstructorArgumentsShouldMatchAnalyzer : DiagnosticAnalyzer
{
internal const string RuleId = "Moq1002";
private const string Title = "Moq: No matching constructor";
private const string Message = "Parameters provided into mock do not match any existing constructors";

private static readonly DiagnosticDescriptor Rule = new(
Diagnostics.ConstructorArgumentsShouldMatchId,
Diagnostics.ConstructorArgumentsShouldMatchTitle,
Diagnostics.ConstructorArgumentsShouldMatchMessage,
Diagnostics.Category,
RuleId,
Title,
Message,
DiagnosticCategory.Moq,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{Diagnostics.ConstructorArgumentsShouldMatchId}.md");
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{RuleId}.md");

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
Expand Down
6 changes: 6 additions & 0 deletions Source/Moq.Analyzers/DiagnosticCategory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Moq.Analyzers;

internal static class DiagnosticCategory
{
public static string Moq { get; } = "Moq";
}
38 changes: 0 additions & 38 deletions Source/Moq.Analyzers/Diagnostics.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ namespace Moq.Analyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class NoConstructorArgumentsForInterfaceMockAnalyzer : DiagnosticAnalyzer
{
internal const string RuleId = "Moq1001";
private const string Title = "Moq: Parameters specified for mocked interface";
private const string Message = "Mocked interfaces cannot have constructor parameters";

private static readonly DiagnosticDescriptor Rule = new(
Diagnostics.NoConstructorArgumentsForInterfaceMockId,
Diagnostics.NoConstructorArgumentsForInterfaceMockTitle,
Diagnostics.NoConstructorArgumentsForInterfaceMockMessage,
Diagnostics.Category,
RuleId,
Title,
Message,
DiagnosticCategory.Moq,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{Diagnostics.NoConstructorArgumentsForInterfaceMockId}.md");
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{RuleId}.md");

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
Expand Down
14 changes: 9 additions & 5 deletions Source/Moq.Analyzers/NoMethodsInPropertySetupAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ namespace Moq.Analyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class NoMethodsInPropertySetupAnalyzer : DiagnosticAnalyzer
{
internal const string RuleId = "Moq1101";
private const string Title = "Moq: Property setup used for a method";
private const string Message = "SetupGet/SetupSet should be used for properties, not for methods";

private static readonly DiagnosticDescriptor Rule = new(
Diagnostics.NoMethodsInPropertySetupId,
Diagnostics.NoMethodsInPropertySetupTitle,
Diagnostics.NoMethodsInPropertySetupMessage,
Diagnostics.Category,
RuleId,
Title,
Message,
DiagnosticCategory.Moq,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{Diagnostics.NoMethodsInPropertySetupId}.md");
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{RuleId}.md");

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
Expand Down
14 changes: 9 additions & 5 deletions Source/Moq.Analyzers/NoSealedClassMocksAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ namespace Moq.Analyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class NoSealedClassMocksAnalyzer : DiagnosticAnalyzer
{
internal const string RuleId = "Moq1000";
private const string Title = "Moq: Sealed class mocked";
private const string Message = "Sealed classes cannot be mocked";

private static readonly DiagnosticDescriptor Rule = new(
Diagnostics.NoSealedClassMocksId,
Diagnostics.NoSealedClassMocksTitle,
Diagnostics.NoSealedClassMocksMessage,
Diagnostics.Category,
RuleId,
Title,
Message,
DiagnosticCategory.Moq,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{Diagnostics.NoSealedClassMocksId}.md");
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{RuleId}.md");

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ namespace Moq.Analyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class SetupShouldBeUsedOnlyForOverridableMembersAnalyzer : DiagnosticAnalyzer
{
internal const string RuleId = "Moq1200";
private const string Title = "Moq: Invalid setup parameter";
private const string Message = "Setup should be used only for overridable members";

private static readonly DiagnosticDescriptor Rule = new(
Diagnostics.SetupShouldBeUsedOnlyForOverridableMembersId,
Diagnostics.SetupShouldBeUsedOnlyForOverridableMembersTitle,
Diagnostics.SetupShouldBeUsedOnlyForOverridableMembersMessage,
Diagnostics.Category,
RuleId,
Title,
Message,
DiagnosticCategory.Moq,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{Diagnostics.SetupShouldBeUsedOnlyForOverridableMembersId}.md");
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{RuleId}.md");

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);

Expand Down
14 changes: 9 additions & 5 deletions Source/Moq.Analyzers/SetupShouldNotIncludeAsyncResultAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class SetupShouldNotIncludeAsyncResultAnalyzer : DiagnosticAnalyzer
{
internal const string RuleId = "Moq1201";
private const string Title = "Moq: Invalid setup parameter";
private const string Message = "Setup of async methods should use ReturnsAsync instead of .Result";

private static readonly DiagnosticDescriptor Rule = new(
Diagnostics.SetupShouldNotIncludeAsyncResultId,
Diagnostics.SetupShouldNotIncludeAsyncResultTitle,
Diagnostics.SetupShouldNotIncludeAsyncResultMessage,
Diagnostics.Category,
RuleId,
Title,
Message,
DiagnosticCategory.Moq,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{Diagnostics.SetupShouldNotIncludeAsyncResultId}.md");
helpLinkUri: $"https://github.com/rjmurillo/moq.analyzers/blob/main/docs/rules/{RuleId}.md");

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);

Expand Down

0 comments on commit 46df790

Please sign in to comment.