-
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.
All Code Inspections' severity level can be configured to any of the following severity levels.
- Do Not Show
- Hint
- Suggestion
- Warning
- Error
It's a best practice in VBA to always declare Option Explicit
at the beginning of every code module.
This Inspection has a default severity of Warning
.
When a variable is not explicitly declared with a type, it is implicitly declared as a Variant
type. Variants allow anything to be stored in them. It's best practice to explicitly declare all types.
This Inspection has a default severity of Warning
.
When a Function's return type is not specified, it will return a Variant
type. It's best practice to explicitly declare a return type.
This Inspection has a default severity of Suggestion
.
If not specified, all arguments are passed ByRef
. It's best practice to pass all arguments ByVal
unless it's truly necessary to pass by reference. At the least, all parameters should have this option explicitly specified. Rubberduck has quick fix options for both situations.
This Inspection has a default severity of Warning
.
It's best practice to give each variable declaration its own line and Dim
statement.
This:
Dim foo As String, bar As Integer, baz As Long
Can be written as:
Dim foo As String
Dim bar As Integer
Dim baz As Long
This helps avoid making the mistake of not declaring a type for each variable. For example, in this code:
Dim foo, bar, baz As Long
only baz
is declared as Long
. foo
and bar
are implicitly declared as Variant
.
This Inspection has a default severity of Suggestion
.
VBA supports the archaic and obsolete BASIC REM
syntax for comments. REM
should be replaced with a single quote ('
).
This Inspection has a default severity of Suggestion
.
For a roadmap of Code Inspections to be implemented in the future, please see the Open Issues with the Code Inspections label. If you think of something you'd like to see added to the list of Code Inspections, please Submit your feature request as an issue.
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 >> Options.
All Code Inspections' severity level can be configured to any of the following severity levels.
- Do Not Show
- Hint
- Suggestion
- Warning
- Error
Advanced users may also directly modify the rubberduck.config
file.
<CodeInspections>
<CodeInspection Name="Parameter is passed ByRef implicitly" Severity="Warning" InspectionType="CodeQualityIssues" />
<CodeInspection Name="Function returns an implicit Variant" Severity="DoNotShow" InspectionType="CodeQualityIssues" />
<CodeInspection Name="Instruction contains multiple declarations" Severity="Hint" InspectionType="CodeQualityIssues" />
<CodeInspection Name="Use of obsolete Rem comment syntax" Severity="Suggestion" InspectionType="MaintainabilityAndReadabilityIssues" />
<CodeInspection Name="Option Explicit is not specified" Severity="Error" InspectionType="CodeQualityIssues" />
<CodeInspection Name="Variable type is implicitly Variant" Severity="Warning" InspectionType="CodeQualityIssues" />
</CodeInspections>
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