Skip to content

Commit 60e2dac

Browse files
committed
Fix Ignore and IgnoreModule for UnderscoreInPublicMemberName Inspection
Fixes #4965
1 parent 8b4fe5a commit 60e2dac

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/UnderscoreInPublicClassModuleMemberInspection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Rubberduck.Parsing.Inspections.Abstract;
66
using Rubberduck.Resources.Inspections;
77
using Rubberduck.Parsing.VBA;
8+
using Rubberduck.Inspections.Inspections.Extensions;
89

910
namespace Rubberduck.Inspections.Concrete
1011
{
@@ -46,6 +47,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
4647
.Where(w => !interfaceMembers.Contains(w) && !eventHandlers.Contains(w))
4748
.Where(w => w.Accessibility == Parsing.Symbols.Accessibility.Public || w.Accessibility == Parsing.Symbols.Accessibility.Implicit)
4849
.Where(w => w.IdentifierName.Contains('_'))
50+
.Where(d => !d.IsIgnoringInspectionResultFor(AnnotationName))
4951
.ToList();
5052

5153
return names.Select(issue =>

RubberduckTests/Inspections/UnderscoreInPublicClassModuleMemberInspectionTests.cs

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
namespace RubberduckTests.Inspections
99
{
1010
[TestFixture]
11+
[Category("Inspections")]
12+
[Category("UnderscoreInPublicMember")]
1113
public class UnderscoreInPublicClassModuleMemberInspectionTests
1214
{
1315
[Test]
14-
[Category("Inspections")]
1516
public void BasicExample_Sub()
1617
{
1718
const string inputCode =
@@ -29,7 +30,48 @@ public void BasicExample_Sub()
2930
}
3031

3132
[Test]
32-
[Category("Inspections")]
33+
public void Basic_Ignored()
34+
{
35+
const string inputCode =
36+
@"'@Ignore UnderscoreInPublicClassModuleMember
37+
Public Sub This_Is_Ignored()
38+
End Sub
39+
40+
Public Sub This_Should_Be_Marked()
41+
End Sub";
42+
var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out _);
43+
using (var state = MockParser.CreateAndParse(vbe.Object))
44+
{
45+
var inspection = new UnderscoreInPublicClassModuleMemberInspection(state);
46+
var inspector = InspectionsHelper.GetInspector(inspection);
47+
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;
48+
49+
Assert.AreEqual(1, inspectionResults.Count());
50+
}
51+
}
52+
53+
[Test]
54+
public void Basic_IgnoreModule()
55+
{
56+
const string inputCode =
57+
@"'@IgnoreModule UnderscoreInPublicClassModuleMember
58+
Public Sub This_Is_Ignored()
59+
End Sub
60+
61+
Public Sub This_Is_Also_Ignored()
62+
End Sub";
63+
var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out _);
64+
using (var state = MockParser.CreateAndParse(vbe.Object))
65+
{
66+
var inspection = new UnderscoreInPublicClassModuleMemberInspection(state);
67+
var inspector = InspectionsHelper.GetInspector(inspection);
68+
var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;
69+
70+
Assert.AreEqual(0, inspectionResults.Count());
71+
}
72+
}
73+
74+
[Test]
3375
public void BasicExample_Function()
3476
{
3577
const string inputCode =
@@ -47,7 +89,6 @@ public void BasicExample_Function()
4789
}
4890

4991
[Test]
50-
[Category("Inspections")]
5192
public void BasicExample_Property()
5293
{
5394
const string inputCode =
@@ -65,7 +106,6 @@ public void BasicExample_Property()
65106
}
66107

67108
[Test]
68-
[Category("Inspections")]
69109
public void StandardModule()
70110
{
71111
const string inputCode =
@@ -83,7 +123,6 @@ public void StandardModule()
83123
}
84124

85125
[Test]
86-
[Category("Inspections")]
87126
public void NoUnderscore()
88127
{
89128
const string inputCode =
@@ -101,7 +140,6 @@ public void NoUnderscore()
101140
}
102141

103142
[Test]
104-
[Category("Inspections")]
105143
public void FriendMember_WithUnderscore()
106144
{
107145
const string inputCode =
@@ -119,7 +157,6 @@ public void FriendMember_WithUnderscore()
119157
}
120158

121159
[Test]
122-
[Category("Inspections")]
123160
public void Implicit_WithUnderscore()
124161
{
125162
const string inputCode =
@@ -137,7 +174,6 @@ public void Implicit_WithUnderscore()
137174
}
138175

139176
[Test]
140-
[Category("Inspections")]
141177
public void ImplementsInterface()
142178
{
143179
const string inputCode1 =

0 commit comments

Comments
 (0)