Skip to content

Commit ed912ed

Browse files
committed
Addressed comments. Added more examples
1 parent e20d870 commit ed912ed

File tree

1 file changed

+62
-15
lines changed

1 file changed

+62
-15
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureNotUsedInspection.cs

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Generic;
12
using System.Linq;
23
using Rubberduck.CodeAnalysis.Inspections.Abstract;
34
using Rubberduck.CodeAnalysis.Inspections.Extensions;
@@ -14,8 +15,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
1415
/// </summary>
1516
/// <why>
1617
/// Unused procedures are dead code that should probably be removed. Note, a procedure may be effectively "not used" in code, but attached to some
17-
/// Shape object in the host document: in such cases the inspection result should be ignored. An event handler procedure that isn't being
18-
/// resolved as such, may also wrongly trigger this inspection.
18+
/// Shape object in the host document: in such cases the inspection result should be ignored.
1919
/// </why>
2020
/// <remarks>
2121
/// Not all unused procedures can/should be removed: ignore any inspection results for
@@ -24,34 +24,81 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
2424
/// the presence or absence of user code references.
2525
/// </remarks>
2626
/// <example hasResult="true">
27-
/// <module name="MyModule" type="Standard Module">
27+
/// <module name="Module1" type="Standard Module">
28+
/// <![CDATA[
29+
/// Option Explicit
30+
///
31+
/// Private Sub DoSomething()
32+
/// End Sub
33+
/// ]]>
34+
/// </module>
35+
/// </example>
36+
/// <example hasResult="false">
37+
/// <module name="Module1" type="Standard Module">
38+
/// <![CDATA[
39+
/// Option Explicit
40+
///
41+
/// '@Ignore ProcedureNotUsed
42+
/// Private Sub DoSomething()
43+
/// End Sub
44+
/// ]]>
45+
/// </module>
46+
/// </example>
47+
/// <example hasResult="false">
48+
/// <module name="Module1" type="Standard Module">
49+
/// <![CDATA[
50+
/// Option Explicit
51+
///
52+
/// Public Sub DoSomething()
53+
/// End Sub
54+
/// ]]>
55+
/// </module>
56+
/// </example>
57+
/// <example hasResult="true">
58+
/// <module name="Class1" type="Class Module">
2859
/// <![CDATA[
2960
/// Option Explicit
3061
///
31-
/// 'No inspection result
3262
/// Public Sub DoSomething()
33-
/// ' macro is attached to a worksheet Shape.
3463
/// End Sub
3564
///
36-
/// 'Flagged by inspection
37-
/// Private Sub DoSomethingElse()
38-
/// ' macro is attached to a worksheet Shape.
65+
/// Public Sub DoSomethingElse()
66+
/// End Sub
67+
/// ]]>
68+
/// </module>
69+
/// <module name="Module1" type="Standard Module">
70+
/// <![CDATA[
71+
/// Option Explicit
72+
///
73+
/// Public Sub ReferenceOneClass1Procedure()
74+
/// Dim target As Class1
75+
/// Set target = new Class1
76+
/// target.DoSomething
3977
/// End Sub
4078
/// ]]>
4179
/// </module>
4280
/// </example>
4381
/// <example hasResult="false">
44-
/// <module name="MyModule" type="Standard Module">
82+
/// <module name="Class1" type="Class Module">
4583
/// <![CDATA[
4684
/// Option Explicit
4785
///
4886
/// Public Sub DoSomething()
49-
/// ' macro is attached to a worksheet Shape.
5087
/// End Sub
51-
///
52-
/// '@Ignore ProcedureNotUsed
53-
/// Private Sub DoSomethingElse()
54-
/// ' macro is attached to a worksheet Shape.
88+
///
89+
/// Public Sub DoSomethingElse()
90+
/// End Sub
91+
/// ]]>
92+
/// </module>
93+
/// <module name="Module1" type="Standard Module">
94+
/// <![CDATA[
95+
/// Option Explicit
96+
///
97+
/// Public Sub ReferenceAllClass1Procedures()
98+
/// Dim target As Class1
99+
/// Set target = new Class1
100+
/// target.DoSomething
101+
/// target.DoSomethingElse
55102
/// End Sub
56103
/// ]]>
57104
/// </module>
@@ -90,7 +137,7 @@ public ProcedureNotUsedInspection(IDeclarationFinderProvider declarationFinderPr
90137
protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder)
91138
{
92139
return !declaration.References
93-
.Any(reference => !reference.ParentScoping.Equals(declaration)) // recursive calls don't count
140+
.Any(reference => !reference.ParentScoping.Equals(declaration)) // ignore recursive/self-referential calls
94141
&& !finder.FindEventHandlers().Contains(declaration)
95142
&& !IsPublicModuleMember(declaration)
96143
&& !IsClassLifeCycleHandler(declaration)

0 commit comments

Comments
 (0)