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!
These inspections highlight problems that are potentially more subjective, such as short, disemvoweled identifier names.
Identifies conditional assignments to mutually exclusive Boolean literal values in conditional branches.
Default severity: Warning
The assignment could be made directly to the result of the conditional Boolean expression instead.
This inspection means to indicate when the project has not been renamed.
Default severity: Suggestion
VBA projects should be meaningfully named, to avoid namespace clashes when referencing other VBA projects.
Identifies empty 'Case' blocks that can be safely removed.
Default severity: Warning
Case blocks in VBA do not "fall through"; an empty 'Case' block might be hiding a bug.
Identifies empty 'Do...Loop While' blocks that can be safely removed.
Default severity: Suggestion
Dead code should be removed. A loop without a body is usually redundant.
Identifies empty 'Else' blocks that can be safely removed.
Default severity: Warning
Empty code blocks are redundant, dead code that should be removed. They can also be misleading about their intent: an empty block may be signalling an unfinished thought or an oversight.