Skip to content

Commit

Permalink
Merge branch 'rubberduck-vba/next' into UnusedAssignment_FalsePositives
Browse files Browse the repository at this point in the history
  • Loading branch information
BZngr committed Jul 11, 2020
2 parents 7a10c47 + e498d95 commit adb2693
Show file tree
Hide file tree
Showing 287 changed files with 10,569 additions and 1,549 deletions.
Expand Up @@ -53,11 +53,12 @@ public FunctionReturnValueDiscardedInspection(IDeclarationFinderProvider declara
protected override bool IsResultReference(IdentifierReference reference, DeclarationFinder finder)
{
return reference?.Declaration != null
&& !reference.IsAssignment
&& !reference.IsArrayAccess
&& !reference.IsInnerRecursiveDefaultMemberAccess
&& reference.Declaration.DeclarationType == DeclarationType.Function
&& IsCalledAsProcedure(reference.Context);
&& reference.Declaration.IsUserDefined
&& !reference.IsAssignment
&& !reference.IsArrayAccess
&& !reference.IsInnerRecursiveDefaultMemberAccess
&& reference.Declaration.DeclarationType == DeclarationType.Function
&& IsCalledAsProcedure(reference.Context);
}

private static bool IsCalledAsProcedure(ParserRuleContext context)
Expand Down
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using Rubberduck.CodeAnalysis.Inspections.Abstract;
using Rubberduck.CodeAnalysis.Inspections.Extensions;
Expand All @@ -14,32 +15,92 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
/// </summary>
/// <why>
/// Unused procedures are dead code that should probably be removed. Note, a procedure may be effectively "not used" in code, but attached to some
/// Shape object in the host document: in such cases the inspection result should be ignored. An event handler procedure that isn't being
/// resolved as such, may also wrongly trigger this inspection.
/// Shape object in the host document: in such cases the inspection result should be ignored.
/// </why>
/// <remarks>
/// Not all unused procedures can/should be removed: ignore any inspection results for
/// event handler procedures and interface members that Rubberduck isn't recognizing as such.
/// Public procedures of Standard Modules are not flagged by this inspection regardless of
/// the presence or absence of user code references.
/// </remarks>
/// <example hasResult="true">
/// <module name="MyModule" type="Standard Module">
/// <module name="Module1" type="Standard Module">
/// <![CDATA[
/// Option Explicit
///
/// Public Sub DoSomething()
/// ' macro is attached to a worksheet Shape.
/// Private Sub DoSomething()
/// End Sub
/// ]]>
/// </module>
/// </example>
/// <example hasResult="false">
/// <module name="MyModule" type="Standard Module">
/// <module name="Module1" type="Standard Module">
/// <![CDATA[
/// Option Explicit
///
///
/// '@Ignore ProcedureNotUsed
/// Private Sub DoSomething()
/// End Sub
/// ]]>
/// </module>
/// </example>
/// <example hasResult="false">
/// <module name="Macros" type="Standard Module">
/// <![CDATA[
/// Option Explicit
///
/// Public Sub DoSomething()
/// 'a public procedure in a standard module may be a macro
/// 'attached to a worksheet Shape or invoked by means other than user code.
/// End Sub
/// ]]>
/// </module>
/// </example>
/// <example hasResult="true">
/// <module name="Class1" type="Class Module">
/// <![CDATA[
/// Option Explicit
///
/// Public Sub DoSomething()
/// End Sub
///
/// Public Sub DoSomethingElse()
/// End Sub
/// ]]>
/// </module>
/// <module name="Module1" type="Standard Module">
/// <![CDATA[
/// Option Explicit
///
/// Public Sub ReferenceOneClass1Procedure()
/// Dim target As Class1
/// Set target = new Class1
/// target.DoSomething
/// End Sub
/// ]]>
/// </module>
/// </example>
/// <example hasResult="false">
/// <module name="Class1" type="Class Module">
/// <![CDATA[
/// Option Explicit
///
/// Public Sub DoSomething()
/// ' macro is attached to a worksheet Shape.
/// End Sub
///
/// Public Sub DoSomethingElse()
/// End Sub
/// ]]>
/// </module>
/// <module name="Module1" type="Standard Module">
/// <![CDATA[
/// Option Explicit
///
/// Public Sub ReferenceAllClass1Procedures()
/// Dim target As Class1
/// Set target = new Class1
/// target.DoSomething
/// target.DoSomethingElse
/// End Sub
/// ]]>
/// </module>
Expand Down Expand Up @@ -78,8 +139,7 @@ public ProcedureNotUsedInspection(IDeclarationFinderProvider declarationFinderPr
protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder)
{
return !declaration.References
.Any(reference => !reference.IsAssignment
&& !reference.ParentScoping.Equals(declaration)) // recursive calls don't count
.Any(reference => !reference.ParentScoping.Equals(declaration)) // ignore recursive/self-referential calls
&& !finder.FindEventHandlers().Contains(declaration)
&& !IsPublicModuleMember(declaration)
&& !IsClassLifeCycleHandler(declaration)
Expand Down
Expand Up @@ -4,8 +4,9 @@

namespace Rubberduck.CodeAnalysis.Inspections.Extensions
{
internal static class DeclarationTypeExtensions
public static class DeclarationTypeExtensions
{
//ToDo: Move this to resources. (This will require moving resource lookups to Core.)
public static string ToLocalizedString(this DeclarationType type)
{
return RubberduckUI.ResourceManager.GetString("DeclarationType_" + type, CultureInfo.CurrentUICulture);
Expand Down

0 comments on commit adb2693

Please sign in to comment.