Skip to content

Commit

Permalink
Raises GRUA02 also for Suppressions
Browse files Browse the repository at this point in the history
  • Loading branch information
manfred-brands authored and JohanLarsson committed Apr 21, 2022
1 parent ed84374 commit d95b69b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
23 changes: 23 additions & 0 deletions Gu.Roslyn.Asserts.Analyzers.Tests/Code.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ private static void Handle(SyntaxNodeAnalysisContext context)
}
}";

public const string PlaceholderSuppressor = @"
namespace N
{
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
internal class PlaceholderSuppressor : DiagnosticSuppressor
{
private static readonly SuppressionDescriptor Placeholder = new(
id: nameof(PlaceholderSuppressor),
suppressedDiagnosticId: ""CS8618"",
justification: ""Placeholder"");
public override ImmutableArray<SuppressionDescriptor> SupportedSuppressions { get; } =
ImmutableArray.Create(Placeholder);
public override void ReportSuppressions(SuppressionAnalysisContext context)
{
}
}
}";

public const string PlaceholderFix = @"
namespace N
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,54 @@ public static void M()
Assert.Valid(Code.PlaceholderAnalyzer, code);
}

[Test]
public static void SuppressedOneParamWithPosition()
{
var code = @"
namespace N
{
using Gu.Roslyn.Asserts;
using NUnit.Framework;
public static class C
{
private static readonly PlaceholderSuppressor Suppressor = new PlaceholderSuppressor();
[Test]
public static void M()
{
var code = ""↓class C { }"";
RoslynAssert.Suppressed(Suppressor, code);
}
}
}";
Assert.Valid(Code.PlaceholderSuppressor, code);
}

[Test]
public static void NotSuppressedOneParamWithPosition()
{
var code = @"
namespace N
{
using Gu.Roslyn.Asserts;
using NUnit.Framework;
public static class C
{
private static readonly PlaceholderSuppressor Suppressor = new PlaceholderSuppressor();
[Test]
public static void M()
{
var code = ""↓class C { }"";
RoslynAssert.NotSuppressed(Suppressor, code);
}
}
}";
Assert.Valid(Code.PlaceholderSuppressor, code);
}

[Test]
public static void DiagnosticsOneParamWithPositionAssertReplace()
{
Expand Down
4 changes: 3 additions & 1 deletion Gu.Roslyn.Asserts.Analyzers/Analyzers/InvocationAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool IsPositionParameter()
return parameter switch
{
{ Name: "before" } => true,
{ Name: "code", ContainingSymbol: IMethodSymbol { Name: "Diagnostics" } } => true,
{ Name: "code", ContainingSymbol: IMethodSymbol { Name: "Diagnostics" or "Suppressed" or "NotSuppressed" } } => true,
_ => false,
};
}
Expand Down Expand Up @@ -213,6 +213,8 @@ private static bool IsCode(IParameterSymbol parameter)
{ Name: "code", ContainingSymbol.Name: "Valid" } => true,
{ Name: "code", ContainingSymbol.Name: "Diagnostics" } => true,
{ Name: "code", ContainingSymbol.Name: "NoDiagnostics" } => true,
{ Name: "code", ContainingSymbol.Name: "Suppressed" } => true,
{ Name: "code", ContainingSymbol.Name: "NotSuppressed" } => true,
{ Name: "before", ContainingSymbol.Name: "CodeFix" } => true,
{ Name: "after", ContainingSymbol.Name: "CodeFix" } => true,
{ Name: "before", ContainingSymbol.Name: "Refactoring" } => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</PropertyGroup>

<PropertyGroup>
<Version>4.0.0</Version>
<Version>4.1.0</Version>
<Description>Analyzers and code fixes for Gu.Roslyn.Asserts. Fixes breaking changes etc.</Description>
<Authors>Johan Larsson.</Authors>
<DevelopmentDependency>true</DevelopmentDependency>
Expand All @@ -35,6 +35,9 @@
<RepositoryUrl>https://github.com/GuOrg/Gu.Roslyn.Asserts</RepositoryUrl>
<PackageTags>Roslyn Diagnostic Analyzer</PackageTags>
<PackageReleaseNotes>
4.1.0
FEATURE: add support for DiagnostisSuppressor with RoslynAssert.Suppressed
4.0.0
BUGFIX: handle breaking change in Roslyn 3.3.1
</PackageReleaseNotes>
</PropertyGroup>
Expand Down

0 comments on commit d95b69b

Please sign in to comment.