Skip to content

Commit

Permalink
[GH-131|500] - taking into account ReceivedExtensions.Received with q…
Browse files Browse the repository at this point in the history
…uantity in analyzers
  • Loading branch information
tpodolak committed Feb 2, 2020
1 parent 013b132 commit 721e929
Show file tree
Hide file tree
Showing 12 changed files with 811 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ private void AnalyzeInvocation(SyntaxNodeAnalysisContext syntaxNodeContext)
var diagnostic = Diagnostic.Create(
diagnosticDescriptor,
invocationExpression.GetLocation(),
methodSymbol.Name);
methodSymbol.Name,
methodSymbol.ContainingType.Name);

syntaxNodeContext.ReportDiagnostic(diagnostic);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public static bool IsThrowLikeMethod(this ISymbol symbol)

public static bool IsReceivedLikeMethod(this ISymbol symbol)
{
return IsMember(symbol, MetadataNames.ReceivedMethodNames);
return IsMember(symbol, MetadataNames.ReceivedMethodNames) ||
IsMember(symbol, MetadataNames.ReceivedWithQuantityMethodNames);
}

public static bool IsWhenLikeMethod(this ISymbol symbol)
Expand Down
7 changes: 7 additions & 0 deletions src/NSubstitute.Analyzers.Shared/MetadataNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ internal class MetadataNames
public const string NSubstituteArgFullTypeName = "NSubstitute.Arg";
public const string NSubstituteArgCompatFullTypeName = "NSubstitute.Arg.Compat";
public const string NSubstituteSubstituteExtensionsFullTypeName = "NSubstitute.SubstituteExtensions";
public const string NSubstituteReceivedExtensionsFullTypeName = "NSubstitute.ReceivedExtensions.ReceivedExtensions";
public const string NSubstituteReturnsExtensionsFullTypeName = "NSubstitute.ReturnsExtensions.ReturnsExtensions";
public const string NSubstituteExceptionExtensionsFullTypeName = "NSubstitute.ExceptionExtensions.ExceptionExtensions";
public const string NSubstituteCallInfoFullTypeName = "NSubstitute.Core.CallInfo";
Expand Down Expand Up @@ -66,6 +67,12 @@ internal class MetadataNames
[NSubstituteDidNotReceiveWithAnyArgsMethod] = NSubstituteSubstituteExtensionsFullTypeName
};

public static readonly IReadOnlyDictionary<string, string> ReceivedWithQuantityMethodNames = new Dictionary<string, string>
{
[NSubstituteReceivedMethod] = NSubstituteReceivedExtensionsFullTypeName,
[NSubstituteReceivedWithAnyArgsMethod] = NSubstituteReceivedExtensionsFullTypeName,
};

public static readonly IReadOnlyDictionary<string, string> WhenMethodNames = new Dictionary<string, string>
{
[NSubstituteWhenMethod] = NSubstituteSubstituteExtensionsFullTypeName,
Expand Down
2 changes: 1 addition & 1 deletion src/NSubstitute.Analyzers.Shared/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
<comment>An optional longer localizable description of the diagnostic.</comment>
</data>
<data name="UnusedReceivedForOrdinaryMethodMessageFormat" xml:space="preserve">
<value>Unused received check. To fix, make sure there is a call after "{0}". Correct: "SubstituteExtensions.{0}(sub).SomeCall();". Incorrect: "SubstituteExtensions.{0}(sub);"</value>
<value>Unused received check. To fix, make sure there is a call after "{0}". Correct: "{1}.{0}(sub).SomeCall();". Incorrect: "{1}.{0}(sub);"</value>
<comment>The format-able message the diagnostic displays.</comment>
</data>
<data name="UnusedReceivedForOrdinaryMethodTitle" xml:space="preserve">
Expand Down
Loading

0 comments on commit 721e929

Please sign in to comment.