Rubberduck icon indicating copy to clipboard operation
Rubberduck copied to clipboard

Flag Public event handlers and interface implementations

Open retailcoder opened this issue 3 years ago • 1 comments

What Code Quality inspection flagging Public members that are event handlers or interface implementations.

Why Making these members public puts them on the class' default interface, which means underscored members appear in the list of members of the containing class module when an object variable is declared with the class' default interface (i.e. the class name). Instead of being invoked directly, a dedicated (not underscored) public member on the class' default interface should be added; the implementation can be moved to the new public member and invoked from the private interface implementation.

Example This code should trigger the inspection:

Public Sub Worksheet_BeforeSave(Cancel As Boolean)
    '...do stuff...
End Sub

QuickFixes Should Rubberduck offer one or more quickfix(es) for this inspection? Describe them here (note: all inspections allow for IgnoreOnceQuickFix, unless explicitly specified):

  1. Move implementation to Public method

    Kind of an "extract method lite, where we just grab the whole entire method body and mirror the signature:

    Example code, after quickfix is applied:

    Public Sub DoStuff(Cancel As Boolean)
        '...do stuff...
    End Sub
    
    Private Sub Worksheet_BeforeSave(Cancel As Boolean)
        DoStuff Cancel
    End Sub
    

Resources Each inspection needs a number of resource strings - please provide a suggestion here:

  • InspectionNames: PublicImplementationShouldBePrivateInspection
  • InspectionInfo: the default interface of a class module should not expose the implementation of other interfaces; event handler procedures should be Private.
  • InspectionResults: Member '{0}' should be Private.

retailcoder avatar Apr 09 '21 17:04 retailcoder