Skip to content

Commit a7fafa5

Browse files
committed
fixed ImplicitActiveSheetReferenceInspection and broken tests
1 parent 8755a77 commit a7fafa5

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

RetailCoder.VBE/Inspections/ImplicitActiveSheetReferenceInspection.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@
44
using Rubberduck.Inspections.Resources;
55
using Rubberduck.Inspections.Results;
66
using Rubberduck.Parsing.VBA;
7-
using Rubberduck.VBEditor.Application;
8-
using Rubberduck.VBEditor.Extensions;
9-
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
107

118
namespace Rubberduck.Inspections
129
{
1310
public sealed class ImplicitActiveSheetReferenceInspection : InspectionBase
1411
{
15-
private readonly IHostApplication _hostApp;
16-
17-
public ImplicitActiveSheetReferenceInspection(IVBE vbe, RubberduckParserState state)
12+
public ImplicitActiveSheetReferenceInspection(RubberduckParserState state)
1813
: base(state)
1914
{
20-
_hostApp = vbe.HostApplication();
2115
}
2216

2317
public override string Meta { get { return InspectionsUI.ImplicitActiveSheetReferenceInspectionMeta; } }
@@ -31,23 +25,18 @@ public ImplicitActiveSheetReferenceInspection(IVBE vbe, RubberduckParserState st
3125

3226
public override IEnumerable<InspectionResultBase> GetInspectionResults()
3327
{
34-
if (_hostApp == null || _hostApp.ApplicationName != "Excel")
35-
{
36-
return Enumerable.Empty<InspectionResultBase>();
37-
// if host isn't Excel, the ExcelObjectModel declarations shouldn't be loaded anyway.
38-
}
39-
4028
var matches = BuiltInDeclarations.Where(item =>
4129
item.ProjectName == "Excel" &&
4230
Targets.Contains(item.IdentifierName) &&
43-
item.ParentDeclaration.ComponentName == "Global" &&
31+
item.ParentDeclaration.ComponentName == "_Global" &&
4432
item.AsTypeName == "Range").ToList();
4533

4634
var issues = matches.Where(item => item.References.Any())
4735
.SelectMany(declaration => declaration.References.Distinct());
4836

49-
return issues.Select(issue =>
50-
new ImplicitActiveSheetReferenceInspectionResult(this, issue));
37+
return issues
38+
.Where(issue => !issue.IsInspectionDisabled(Name))
39+
.Select(issue => new ImplicitActiveSheetReferenceInspectionResult(this, issue));
5140
}
5241
}
5342
}

RubberduckTests/Inspections/ImplicitActiveSheetReferenceInspectionTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ End Sub
4949
parser.Parse(new CancellationTokenSource());
5050
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
5151

52-
var inspection = new ImplicitActiveSheetReferenceInspection(vbe.Object, parser.State);
52+
var inspection = new ImplicitActiveSheetReferenceInspection(parser.State);
5353
var inspectionResults = inspection.GetInspectionResults();
5454

5555
Assert.AreEqual(1, inspectionResults.Count());
@@ -86,10 +86,10 @@ End Sub
8686
parser.Parse(new CancellationTokenSource());
8787
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
8888

89-
var inspection = new ImplicitActiveSheetReferenceInspection(vbe.Object, parser.State);
89+
var inspection = new ImplicitActiveSheetReferenceInspection(parser.State);
9090
var inspectionResults = inspection.GetInspectionResults();
9191

92-
Assert.AreEqual(1, inspectionResults.Count());
92+
Assert.AreEqual(0, inspectionResults.Count());
9393
}
9494

9595
[TestMethod]
@@ -127,7 +127,7 @@ Dim arr1() As Variant
127127
parser.Parse(new CancellationTokenSource());
128128
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
129129

130-
var inspection = new ImplicitActiveSheetReferenceInspection(vbe.Object, parser.State);
130+
var inspection = new ImplicitActiveSheetReferenceInspection(parser.State);
131131
var inspectionResults = inspection.GetInspectionResults();
132132

133133
inspectionResults.First().QuickFixes.Single(s => s is IgnoreOnceQuickFix).Fix();
@@ -146,7 +146,7 @@ public void InspectionType()
146146
.Build();
147147
var vbe = builder.AddProject(project).Build();
148148

149-
var inspection = new ImplicitActiveSheetReferenceInspection(vbe.Object, null);
149+
var inspection = new ImplicitActiveSheetReferenceInspection(null);
150150
Assert.AreEqual(CodeInspectionType.MaintainabilityAndReadabilityIssues, inspection.InspectionType);
151151
}
152152

@@ -162,7 +162,7 @@ public void InspectionName()
162162
var vbe = builder.AddProject(project).Build();
163163

164164
const string inspectionName = "ImplicitActiveSheetReferenceInspection";
165-
var inspection = new ImplicitActiveSheetReferenceInspection(vbe.Object, null);
165+
var inspection = new ImplicitActiveSheetReferenceInspection(null);
166166

167167
Assert.AreEqual(inspectionName, inspection.Name);
168168
}

0 commit comments

Comments
 (0)