mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
41 lines
1.7 KiB
C#
41 lines
1.7 KiB
C#
using System.Collections.Immutable;
|
|
using System.Linq;
|
|
using Microsoft.CodeAnalysis;
|
|
using Microsoft.CodeAnalysis.Diagnostics;
|
|
|
|
namespace Robust.Analyzers
|
|
{
|
|
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
|
public class MeansImplicitAssigmentSuppressor : DiagnosticSuppressor
|
|
{
|
|
const string MeansImplicitAssignmentAttribute = "Robust.Shared.MeansImplicitAssignmentAttribute";
|
|
|
|
public override void ReportSuppressions(SuppressionAnalysisContext context)
|
|
{
|
|
var implAttr = context.Compilation.GetTypeByMetadataName(MeansImplicitAssignmentAttribute);
|
|
foreach (var reportedDiagnostic in context.ReportedDiagnostics)
|
|
{
|
|
if(reportedDiagnostic.Id != Diagnostics.MeansImplicitAssignment.SuppressedDiagnosticId) continue;
|
|
|
|
var node = reportedDiagnostic.Location.SourceTree?.GetRoot(context.CancellationToken).FindNode(reportedDiagnostic.Location.SourceSpan);
|
|
if (node == null) continue;
|
|
|
|
var symbol = context.GetSemanticModel(reportedDiagnostic.Location.SourceTree).GetDeclaredSymbol(node);
|
|
|
|
if (symbol == null || !symbol.GetAttributes().Any(a =>
|
|
a.AttributeClass?.GetAttributes().Any(attr =>
|
|
SymbolEqualityComparer.Default.Equals(attr.AttributeClass, implAttr)) == true))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
context.ReportSuppression(Suppression.Create(
|
|
Diagnostics.MeansImplicitAssignment,
|
|
reportedDiagnostic));
|
|
}
|
|
}
|
|
|
|
public override ImmutableArray<SuppressionDescriptor> SupportedSuppressions => ImmutableArray.Create(Diagnostics.MeansImplicitAssignment);
|
|
}
|
|
}
|