-
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 not be considered as an obligation to change anything about the code; they are meant to inform the maintainer about these issues.
Code Inspections are configurable and stored in the Rubberduck.config
file that is installed along with the add-in to the C:\Users\Username\AppData\Roaming\Rubberduck\
directory.
Severity levels can be set through the Settings dialog by going to Rubberduck >> Settings:
The Code Inspection Settings section lists severity levels for each individual inspection:
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 everything else that needs the parse trees.
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.)
The shortname of an inspection can be found in a few places.
For the current release of Rubberduck, the shortname can be found on the Rubberduck website, http://rubberduckvba.com/Inspections/List. From there, click on the inspection you wish to ignore. The inspection shortname will be the last section of the URL, minus "Inspection".
For example, the information page for "Implicit ByRef Parameter Inspection" is located at: http://rubberduckvba.com/Inspections/Details/ImplicitByRefParameterInspection. The corresponding inspection shortname is: ImplicitByRefParameter
.
Pre-release versions of Rubberduck may contain inspections not yet found in the current release version.
The inspection names may be found on GitHub: https://github.com/rubberduck-vba/Rubberduck/tree/next/Rubberduck.Inspections/Concrete. The inspection shortname will be the corresponding source file name, minus "Inspection.cs".
For example, the source file for "Implicit ByRef Parameter Inspection is: ImplicitByRefParameterInspection.cs
and the corresponding shortname is: ImplicitByRefParameter
.
- ImplicitByRefParameterInspection
- ImplicitPublicMemberInspection
- ImplicitVariantReturnTypeInspection
- ModuleOptionsNotSpecifiedFirstInspection
- MultipleDeclarationsInspection
- NonReturningFunctionInspection
- ObsoleteCallStatementInspection
- ObsoleteCommentSyntaxInspection
- ObsoleteGlobalInspection
- ObsoleteLetStatementInspection
- ObsoleteTypeHintInspection
- OptionBaseInspection
- OptionExplicitInspection
- ParameterCanBeByValInspection
- ParameterNotUsedInspection
- UnassignedVariableUsageInspection
- VariableNotDeclaredInspection
- VariableTypeNotDeclaredInspection
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