Skip to content

Commit adb2693

Browse files
committed
Merge branch 'rubberduck-vba/next' into UnusedAssignment_FalsePositives
2 parents 7a10c47 + e498d95 commit adb2693

File tree

287 files changed

+10569
-1549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

287 files changed

+10569
-1549
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/FunctionReturnValueDiscardedInspection.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ public FunctionReturnValueDiscardedInspection(IDeclarationFinderProvider declara
5353
protected override bool IsResultReference(IdentifierReference reference, DeclarationFinder finder)
5454
{
5555
return reference?.Declaration != null
56-
&& !reference.IsAssignment
57-
&& !reference.IsArrayAccess
58-
&& !reference.IsInnerRecursiveDefaultMemberAccess
59-
&& reference.Declaration.DeclarationType == DeclarationType.Function
60-
&& IsCalledAsProcedure(reference.Context);
56+
&& reference.Declaration.IsUserDefined
57+
&& !reference.IsAssignment
58+
&& !reference.IsArrayAccess
59+
&& !reference.IsInnerRecursiveDefaultMemberAccess
60+
&& reference.Declaration.DeclarationType == DeclarationType.Function
61+
&& IsCalledAsProcedure(reference.Context);
6162
}
6263

6364
private static bool IsCalledAsProcedure(ParserRuleContext context)

Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureNotUsedInspection.cs

Lines changed: 70 additions & 10 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,32 +15,92 @@ 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
2222
/// event handler procedures and interface members that Rubberduck isn't recognizing as such.
23+
/// Public procedures of Standard Modules are not flagged by this inspection regardless of
24+
/// the presence or absence of user code references.
2325
/// </remarks>
2426
/// <example hasResult="true">
25-
/// <module name="MyModule" type="Standard Module">
27+
/// <module name="Module1" type="Standard Module">
2628
/// <![CDATA[
2729
/// Option Explicit
2830
///
29-
/// Public Sub DoSomething()
30-
/// ' macro is attached to a worksheet Shape.
31+
/// Private Sub DoSomething()
3132
/// End Sub
3233
/// ]]>
3334
/// </module>
3435
/// </example>
3536
/// <example hasResult="false">
36-
/// <module name="MyModule" type="Standard Module">
37+
/// <module name="Module1" type="Standard Module">
3738
/// <![CDATA[
3839
/// Option Explicit
39-
///
40+
///
4041
/// '@Ignore ProcedureNotUsed
42+
/// Private Sub DoSomething()
43+
/// End Sub
44+
/// ]]>
45+
/// </module>
46+
/// </example>
47+
/// <example hasResult="false">
48+
/// <module name="Macros" type="Standard Module">
49+
/// <![CDATA[
50+
/// Option Explicit
51+
///
52+
/// Public Sub DoSomething()
53+
/// 'a public procedure in a standard module may be a macro
54+
/// 'attached to a worksheet Shape or invoked by means other than user code.
55+
/// End Sub
56+
/// ]]>
57+
/// </module>
58+
/// </example>
59+
/// <example hasResult="true">
60+
/// <module name="Class1" type="Class Module">
61+
/// <![CDATA[
62+
/// Option Explicit
63+
///
64+
/// Public Sub DoSomething()
65+
/// End Sub
66+
///
67+
/// Public Sub DoSomethingElse()
68+
/// End Sub
69+
/// ]]>
70+
/// </module>
71+
/// <module name="Module1" type="Standard Module">
72+
/// <![CDATA[
73+
/// Option Explicit
74+
///
75+
/// Public Sub ReferenceOneClass1Procedure()
76+
/// Dim target As Class1
77+
/// Set target = new Class1
78+
/// target.DoSomething
79+
/// End Sub
80+
/// ]]>
81+
/// </module>
82+
/// </example>
83+
/// <example hasResult="false">
84+
/// <module name="Class1" type="Class Module">
85+
/// <![CDATA[
86+
/// Option Explicit
87+
///
4188
/// Public Sub DoSomething()
42-
/// ' macro is attached to a worksheet Shape.
89+
/// End Sub
90+
///
91+
/// Public Sub DoSomethingElse()
92+
/// End Sub
93+
/// ]]>
94+
/// </module>
95+
/// <module name="Module1" type="Standard Module">
96+
/// <![CDATA[
97+
/// Option Explicit
98+
///
99+
/// Public Sub ReferenceAllClass1Procedures()
100+
/// Dim target As Class1
101+
/// Set target = new Class1
102+
/// target.DoSomething
103+
/// target.DoSomethingElse
43104
/// End Sub
44105
/// ]]>
45106
/// </module>
@@ -78,8 +139,7 @@ public ProcedureNotUsedInspection(IDeclarationFinderProvider declarationFinderPr
78139
protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder)
79140
{
80141
return !declaration.References
81-
.Any(reference => !reference.IsAssignment
82-
&& !reference.ParentScoping.Equals(declaration)) // recursive calls don't count
142+
.Any(reference => !reference.ParentScoping.Equals(declaration)) // ignore recursive/self-referential calls
83143
&& !finder.FindEventHandlers().Contains(declaration)
84144
&& !IsPublicModuleMember(declaration)
85145
&& !IsClassLifeCycleHandler(declaration)

Rubberduck.CodeAnalysis/Inspections/Extensions/DeclarationTypeExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
namespace Rubberduck.CodeAnalysis.Inspections.Extensions
66
{
7-
internal static class DeclarationTypeExtensions
7+
public static class DeclarationTypeExtensions
88
{
9+
//ToDo: Move this to resources. (This will require moving resource lookups to Core.)
910
public static string ToLocalizedString(this DeclarationType type)
1011
{
1112
return RubberduckUI.ResourceManager.GetString("DeclarationType_" + type, CultureInfo.CurrentUICulture);

0 commit comments

Comments
 (0)