Skip to content

Commit 4d43909

Browse files
committed
Implement centralized ignore-handling for inspections
1 parent 3ebc6e4 commit 4d43909

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Rubberduck.CodeAnalysis/Inspections/Abstract/InspectionBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ public IEnumerable<IInspectionResult> GetInspectionResults(CancellationToken tok
105105
{
106106
var _stopwatch = new Stopwatch();
107107
_stopwatch.Start();
108-
var result = DoGetInspectionResults();
108+
var declarationFinder = State.DeclarationFinder;
109+
var result = DoGetInspectionResults()
110+
.Where(ir => !ir.IsIgnoringInspectionResult(declarationFinder));
109111
_stopwatch.Stop();
110112
_logger.Trace("Intercepted invocation of '{0}.{1}' returned {2} objects.", GetType().Name, nameof(DoGetInspectionResults), result.Count());
111113
_logger.Trace("Intercepted invocation of '{0}.{1}' ran for {2}ms", GetType().Name, nameof(DoGetInspectionResults), _stopwatch.ElapsedMilliseconds);

Rubberduck.CodeAnalysis/Inspections/Extensions/IgnoreRelatedExtensions.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
using Rubberduck.Parsing;
1+
using Rubberduck.Inspections.Results;
2+
using Rubberduck.Parsing;
23
using Rubberduck.Parsing.Annotations;
4+
using Rubberduck.Parsing.Inspections.Abstract;
35
using Rubberduck.Parsing.Symbols;
46
using Rubberduck.Parsing.VBA.DeclarationCaching;
57
using Rubberduck.VBEditor;
8+
using System;
69
using System.Linq;
710

811
namespace Rubberduck.Inspections.Inspections.Extensions
@@ -30,6 +33,21 @@ public static bool IsIgnoringInspectionResultFor(this QualifiedContext parserCon
3033
return parserContext.ModuleName.IsIgnoringInspectionResultFor(parserContext.Context.Start.Line, declarationFinder, inspectionName);
3134
}
3235

36+
public static bool IsIgnoringInspectionResult(this IInspectionResult result, DeclarationFinder declarationFinder)
37+
{
38+
switch (result)
39+
{
40+
case DeclarationInspectionResult dr:
41+
return dr.Target.IsIgnoringInspectionResultFor(dr.Inspection.AnnotationName);
42+
case IdentifierReferenceInspectionResult irr:
43+
return irr.QualifiedName.IsIgnoringInspectionResultFor(irr.Context.Start.Line, declarationFinder, irr.Inspection.AnnotationName);
44+
case QualifiedContextInspectionResult qcr:
45+
return qcr.QualifiedName.IsIgnoringInspectionResultFor(qcr.Context.Start.Line, declarationFinder, qcr.Inspection.AnnotationName);
46+
default:
47+
return false;
48+
}
49+
}
50+
3351
private static bool IsIgnoringInspectionResultFor(this QualifiedModuleName module, int line, DeclarationFinder declarationFinder, string inspectionName)
3452
{
3553
var lineScopedAnnotations = declarationFinder.FindAnnotations<IgnoreAnnotation>(module, line);

0 commit comments

Comments
 (0)