Skip to content

Commit

Permalink
Do not report variable not used if it has assignments. Closes #2427
Browse files Browse the repository at this point in the history
  • Loading branch information
comintern committed Oct 28, 2018
1 parent 7ae665a commit 36737a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
.Where(declaration =>
!declaration.IsWithEvents
&& !IsIgnoringInspectionResultFor(declaration, AnnotationName)
&& declaration.References.All(reference => reference.IsAssignment));
&& !declaration.References.Any());

return declarations.Select(issue =>
new DeclarationInspectionResult(this,
Expand Down
20 changes: 16 additions & 4 deletions RubberduckTests/Inspections/VariableNotUsedInspectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,24 @@ public void VariableNotUsed_DoesNotReturnsResult_UsedInNameStatement()

[Test]
[Category("Inspections")]
public void InspectionName()
public void VariableUsed_DoesNotReturnResultIfAssigned()
{
const string inspectionName = "VariableNotUsedInspection";
var inspection = new VariableNotUsedInspection(null);
const string inputCode =
@"Function Foo() As Boolean
Dim var1 as String
var1 = ""test""
End Function";

var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
using (var state = MockParser.CreateAndParse(vbe.Object))
{

var inspection = new VariableNotUsedInspection(state);
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

Assert.AreEqual(inspectionName, inspection.Name);
Assert.AreEqual(0, inspectionResults.Count());
}
}

}
}

0 comments on commit 36737a4

Please sign in to comment.