-
Notifications
You must be signed in to change notification settings - Fork 316
Open
Labels
enhancementFeature requests, or enhancements to existing features. Ideas. Anything within the project's scope.Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope.feature-inspectionsup-for-grabsUse this label in conjunction with a difficulty level label, e.g. difficulty-02-duckyUse this label in conjunction with a difficulty level label, e.g. difficulty-02-ducky
Description
What
If an object instance is created with the New keyword (ex. Set myColl = New Collection) and the variable is later set using a function returning that object type, then the "Assignment Not Used" inspection is triggered.
This sub-type of "Assignment Not Used" could have a hotfix.
In the example below, an instance of the Collection object is created but then overwritten by the next line. The line Set myColl = New Collection is not necessary and can be safely deleted.
Why
Inspection results are good. Hotfixes are better!
Example
This code should trigger the inspection:
Public Sub DoSomething()
Dim myColl As Collection
Set myColl = New Collection
Set myColl = FunctionReturningCollection
End SubQuickFixes
-
Remove object instance creation
Example code, after quickfix is applied:
Public Sub DoSomething()
Dim myColl As Collection
Set myColl = FunctionReturningCollection
End SubResources
- InspectionNames: ObjectAssignmentNotUsed
- InspectionInfo: An object instance is created with the New keyword but the object is later set using a method that does not require the object instance to be created in advance.
- InspectionResults: ??
Metadata
Metadata
Assignees
Labels
enhancementFeature requests, or enhancements to existing features. Ideas. Anything within the project's scope.Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope.feature-inspectionsup-for-grabsUse this label in conjunction with a difficulty level label, e.g. difficulty-02-duckyUse this label in conjunction with a difficulty level label, e.g. difficulty-02-ducky