Static code analysis can find hundreds of opportunities in VBA code.
Rubberduck builds its own internal representation of the code, and then proceeds to analyze it. Each individual inspection can easily be disabled, or configured to issue inspection results at different severity levels ranging from Hint
to Error
.
Use the Inspection Results toolwindow to review Rubberduck’s findings, search, filter, regroup results by inspection, location, type, or severity. Each inspection result comes with a detailed description of what’s being flagged and why, so you can make an enlightened decision.
Unless configured otherwise, Rubberduck automatically runs inspections after the a parser/resolver cycle completes (regardless of whether the inspection results toolwindow is displayed or not).
For the best experience, it would be recommended to first try Rubberduck with an empty project, add a new module, and write, say, a loop that counts 1 to 10 and outputs to the debug pane - then to parse that and review the inspection results; carefully review the inspection settings, and consider disabling the inspections that irreconcilably clash with your preferences: use meaningful names alone can easily produce hundreds upon hundreds of results if you’re not that much into using vowels, or if you, say, prefix all your variable names; these inspections can be re-enabled anytime you’re ready!
This tab lists all items found in the .xml documentation assets from the latest pre-release build. To modify this content, a pull request must be merged into the [next] branch.
Locates explicit 'Let' assignments.
Default severity: Suggestion
The legacy syntax is obsolete/redundant; prefer implicit Let-coercion instead.
Flags usages of members marked as obsolete with an @Obsolete("justification") Rubberduck annotation.
Default severity: Warning
Marking members as obsolete can help refactoring a legacy code base. This inspection is a tool that makes it easy to locate obsolete member calls.
Flags declarations where a type hint is used in place of an 'As' clause.
Default severity: Suggestion
Type hints were made obsolete when declaration syntax introduced the 'As' keyword. Prefer explicit type names over type hint symbols.
Flags 'While...Wend' loops as obsolete.
Default severity: Warning
'While...Wend' loops were made obsolete when 'Do While...Loop' statements were introduced. 'While...Wend' loops cannot be exited early without a GoTo jump; 'Do...Loop' statements can be conditionally exited with 'Exit Do'.
Flags obsolete 'On Local Error' statements.
Default severity: Suggestion
All errors are "local" - the keyword is redundant/confusing and should be removed.
Flags modules that specify Option Base 1.
Default severity: Hint
Implicit array lower bound is 0 by default, and Option Base 1 makes it 1. While compelling in a 1-based environment like the Excel object model, having an implicit lower bound of 1 for implicitly-sized user arrays does not change the fact that arrays are always better off with explicit boundaries. Because 0 is always the lower array bound in many other programming languages, this option may trip a reader/maintainer with a different background.
Flags modules that omit Option Explicit.
Default severity: Error
This option makes variable declarations mandatory. Without it, a typo gets compiled as a new on-the-spot Variant/Empty variable with a new name. Omitting this option amounts to refusing the little help the VBE can provide with compile-time validation.
Flags parameters that are passed by reference (ByRef), but could be passed by value (ByVal).
Default severity: Suggestion
Explicitly specifying a ByVal modifier on a parameter makes the intent explicit: this parameter is not meant to be assigned. In contrast, a parameter that is passed by reference (implicitly, or explicitly ByRef) makes it ambiguous from the calling code's standpoint, whether the procedure might re-assign these ByRef values and introduce a bug.
Identifies parameter declarations that are not used.
Default severity: Warning
Declarations that are not used anywhere should probably be removed.
Warns about 'Sub' procedures that could be refactored into a 'Function'.
Default severity: Suggestion
Idiomatic VB code uses 'Function' procedures to return a single value. If the procedure isn't side-effecting, consider writing is as a 'Function' rather than a 'Sub' the returns a result through a 'ByRef' parameter.