-
Notifications
You must be signed in to change notification settings - Fork 301
Code Inspections
Rubberduck provide code analysis via the Code Inspections functionality. The code in all open VBA Projects is parsed and Rubberduck suggests improvements. Many of these can be automatically corrected by the add in by using the "Fix" button.
Quickfixes are not intended to be used blindly, and some of them may end up leaving the code non-compilable (like removing the declaration for a variable that's referenced, but never assigned to). Inspection results should never be considered as an obligation to change anything about the code; they are meant to inform the maintainer about these [potential] issues.
Code Inspections are configurable and stored in the Rubberduck.config
file that is installed along with the add-in to the %AppData%\Rubberduck\
directory.
Severity levels can be set through the Settings dialog:
The Code Inspection Settings page lists severity levels for each inspection, in a search/filter-enabled list.
Severity levels can be configured to any of the following:
- Do Not Show turns off an inspection.
- Hint level would be for inspections that raise a flag, something to keep in mind while maintaining the code.
- Suggestion level is for inspections that can enhance the code base.
- Warning level is for potentially serious issues.
- Error level is for definitely serious issues that can result in compilation or runtime errors, or unexpected bugs.
Inspections run automatically whenever the parser has an up-to-date image of the code in the IDE. By default, the Ctrl+Shift+I hotkey brings up the Inspection Results toolwindow:
The Refresh command requests a re-parse of everything in the IDE, which updates inspection results and all toolwindows.
The Fix button is actually a dynamic drop-down menu that lists all quick-fixes supported by the selected inspection result. Most inspections support an ignore once quick-fix that inserts a special annotation instructing Rubberduck to ignore a specific place in the code for a specific inspection.
The Grouping button is also a drop-down, that lets you regroup inspection results either by location (module) or by inspection type.
The Copy button copies inspection results to various formats in the clipboard, so you can paste them as a formatted table in Excel, as HTML in Word, or as plain text in a Code Review Stack Exchange post.
The Settings button brings up the settings dialog on the inspection settings page, to let you configure inspection severities.
The bottom pane (which can be dragged/resized vertically) contains information about the selected inspection result, as well as quick links to apply the default fix (the one that's listed first in the Fix drop-down) to the entire module or project, and a link to automatically disable an inspection (i.e. automatically set its severity level to DoNotShow
).
Inspections can be ignored on the module level and on the line level.
Inspections are ignored by placing an '@Ignore
annotation followed by the inspection shortname (minus any "Inspection" at the end of the name.)
- Module level:
'@IgnoreModule InspectionShortName
- Line/instruction level:
'@Ignore InspectionShortName
Other options:
- Ignore all in Module:
@IgnoreModule
- Ignore one or more specific inspections:
@IgnoreModule InspectionShortName1, InspectionShortName2, ...
To view inspection names, group inspection results by inspection (the lightbulb icon); the names are the group headings.
Note: the inspection results toolwindow performs better with filtered results...
The website has a list of all inspections that automatically updates itself as new inspections are merged into the repository. Inspections that have not yet been merged into the [master] branch, will appear with a "pre-release" marker.
Each inspection's details page contains a short summary, a detailed description of the reasoning behind it, library references required in order for this inspection to run (if applicable), and code examples:
rubberduckvba.com
© 2014-2021 Rubberduck project contributors
- Contributing
- Build process
- Version bump
- Architecture Overview
- IoC Container
- Parser State
- The Parsing Process
- How to view parse tree
- UI Design Guidelines
- Strategies for managing COM object lifetime and release
- COM Registration
- Internal Codebase Analysis
- Projects & Workflow
- Adding other Host Applications
- Inspections XML-Doc
-
VBE Events