Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
d9afcb3
Opportunistic string.Empty replacement
IvenBach Nov 19, 2020
120c1a8
Convert to lambda expression body
IvenBach Nov 19, 2020
d843412
Add inspection and test
IvenBach Nov 19, 2020
ddb6a71
Implement new base for inheritance
IvenBach Nov 24, 2020
3b73185
Refactor to use higher abstraction level
IvenBach Nov 25, 2020
92e26ab
Remove unused using directives
IvenBach Nov 25, 2020
11c022b
Remove local file used by git
IvenBach Nov 25, 2020
9a02dd1
Add inspection name resource
IvenBach Nov 25, 2020
9c82a4f
Add delay to SearchBox
IvenBach Nov 25, 2020
5b32723
Correct type comparison
IvenBach Nov 26, 2020
7019b39
Edit inspection resources
IvenBach Nov 26, 2020
272ce50
Limit inspection to Public Enums
IvenBach Nov 28, 2020
5c12b5f
Update naming to reflect public accessor
IvenBach Nov 28, 2020
81fa53e
Update unit tests
IvenBach Nov 28, 2020
81a9d93
Merge remote-tracking branch 'upstream/next' into Issue5608_declaring…
IvenBach Nov 28, 2020
ae4ee51
Update test to use expected argument
IvenBach Nov 28, 2020
d7d91b1
Rename class
IvenBach Nov 30, 2020
80403b5
Provide type to base constructor
IvenBach Nov 30, 2020
ee31b2f
Add sealed access modifier
IvenBach Nov 30, 2020
c577ccc
Add more sealed modifiers
IvenBach Nov 30, 2020
3462681
Remove unused backing field
IvenBach Nov 30, 2020
feb4c75
Add XML documentation
IvenBach Nov 30, 2020
60e4020
Update Accessibility check
IvenBach Nov 30, 2020
eb4a289
Add DeleteDeclarationsRefactoringAction
BZngr Apr 11, 2021
ea23b4a
Add FixMany(...) function to IQuickFix
BZngr Apr 11, 2021
a4d1138
Modify RemoveUnusedDeclarationQuickFix to use refactoring action
BZngr Apr 11, 2021
73f8ae6
Modify EncapsulateField to use DeleteDeclarationsRefactoringAction
BZngr Apr 11, 2021
e83676b
Modify MoveCloserToUsage to use DeleteDeclarationsRefactoringAction
BZngr Apr 14, 2021
b79a497
Delete IModuleRewriterExtensions
BZngr Apr 15, 2021
6842721
Merge branch 'next' into 5719_RemoveUnusedDeclarationQF_Formatting
BZngr Apr 16, 2021
97d6bc1
fixes document subtype resolution
retailcoder Apr 6, 2021
6480521
declare public variable for document module
retailcoder Apr 6, 2021
e89ab04
fixed classification for default instance variable, removed fake vari…
retailcoder Apr 7, 2021
f51d03a
Account for qualified calls resolving to _SuperClass
retailcoder Apr 7, 2021
3de5f5c
added missing DeclarationType resource key
retailcoder Apr 7, 2021
5dfdd9b
address a few possible exceptions
retailcoder Apr 7, 2021
56d69cb
Closes #5722
bclothier Apr 7, 2021
898bb9c
Added remarks to xmldoc
retailcoder Apr 8, 2021
a0a3bb6
fixes the broken xmldoc example
retailcoder Apr 8, 2021
9073bdf
Refactor to use specialized scope RefactoringActions
BZngr May 7, 2021
2f68d41
Constructor Inject supporting deletion refactoringAction references
BZngr Jun 17, 2021
bb9ef5e
Improve EndOfStatementContent handling
BZngr Jun 19, 2021
50a6e74
Use DeleteDeclarationTestResolver to create objects
BZngr Jun 25, 2021
b0382ac
Register factories for DeleteDeclarationRefactoringAction
BZngr Jun 24, 2021
1a9c73f
Remove Indenter option from DeleteDeclarationsRefactoringAction
BZngr Jul 30, 2021
d73b34d
Update for DeleteDeclarationsRefactoring
BZngr Aug 2, 2021
a1bee34
Refactor DeleteDeclarationsRefactoringAction
BZngr Jun 27, 2021
d97f9d0
Update test for comment handling
BZngr Aug 25, 2021
038f0ed
Refactor to use DeleteDeclarationsRefactoringAction
BZngr Aug 25, 2021
6576a48
Update for DeleteDeclarationsRefactoringAction changes
BZngr Aug 25, 2021
6c73367
Merge branch 'next' into SyncWithNext
BZngr Aug 25, 2021
63c48c4
Add Comment Verification TODO resource
BZngr Aug 27, 2021
8f380e2
Refactor DeleteDeclarationsRefactoringAction
BZngr Aug 27, 2021
88e0fe5
Merge branch '5719_RemoveUnusedDeclarationQF_Formatting' of https://g…
BZngr Aug 28, 2021
f906023
Minor Corrections following GH push
BZngr Aug 31, 2021
fb3abc8
Merge branch 'next' into 5719SyncWithNext
BZngr Oct 13, 2021
e5198b1
Remove residual references to ReplaceReferencesRefactoringAction comp…
BZngr Oct 13, 2021
6fb6bf4
Rename FixMany to Fix
BZngr Oct 17, 2021
a5092e6
Modify IDeclarationDeletionGroup return types
BZngr Oct 17, 2021
c106c80
Add abstract Predicate guard clause to base class
BZngr Oct 17, 2021
0787e31
Merge pull request #5734 from BZngr/5719_RemoveUnusedDeclarationQF_Fo…
retailcoder Dec 11, 2021
fe1a9c6
Merge pull request #5912 from retailcoder/next
retailcoder Dec 11, 2021
d3db027
Fixed spelling & improved wording
Rsge Jan 4, 2022
cd4f58c
Merge pull request #5927 from Rsge/next
Vogel612 Jan 4, 2022
a2b5be4
Implement DeclarationStatment Parameter for MoveCloserToUsageRefracto…
awb95 Jan 11, 2022
58a9282
Add MoveCloserToUsageDialog to Select Declaration Statement
awb95 Jan 12, 2022
be6a382
Use Localisation Ressource Texts for UI
awb95 Jan 12, 2022
a47ee9c
Test
awb95 Jan 14, 2022
130d2b7
Update appveyor.yml
rubberduck-vba-releasebot Jan 15, 2022
774a0be
Merge pull request #5930 from rubberduck-vba/patch-releasebot-token
retailcoder Jan 15, 2022
0836aee
also update the green release token
Vogel612 Jan 15, 2022
4282947
Default Declaration Statement
awb95 Jan 16, 2022
1f241a0
Acknowledge that module constants can have attributes
MDoerner Jan 18, 2022
8f85e13
Basic Changes for Tests
awb95 Jan 19, 2022
67cbb3f
Edit Existing Tests
awb95 Jan 19, 2022
2fc0973
Add some tests for MoveCloserToUsage UI-Selection
awb95 Jan 20, 2022
1fb587f
Update appveyor.yml
rubberduck-vba-releasebot Jan 24, 2022
9551c34
Update README.md
retailcoder Jan 24, 2022
de86e8d
Update appveyor.yml
retailcoder Jan 24, 2022
723fe31
Merge pull request #5938 from rubberduck-vba/releasebot-patch-appveyo…
retailcoder Jan 24, 2022
70e5479
Merge pull request #5934 from MDoerner/FixVarDescOnConstant
retailcoder Jan 24, 2022
e701c16
Update MissingAttributeInspectionTests.cs
retailcoder Jan 24, 2022
2c0aca1
Typo in reasoning - ProcedureCanBeWrittenAsFunction
doterik Jan 24, 2022
7862d61
Edit Existing QuickFixTests
awb95 Jan 26, 2022
f9baa8c
Merge pull request #5939 from doterik/patch-1
retailcoder Jan 27, 2022
d107bd5
FIx Typo
awb95 Jan 27, 2022
04fb0e4
Cleanup MoveCloserToUsageRefractoring
awb95 Jan 27, 2022
c8bf757
comments
awb95 Jan 27, 2022
4a765c9
BreakDown CheckThatThereIsNoOtherSameNameDeclarationInScopeInReferenc…
awb95 Jan 28, 2022
c317874
Clean Model
awb95 Jan 28, 2022
e09d7b7
Improve Static Declaration Detection
awb95 Jan 28, 2022
51b7b7a
typo
awb95 Jan 28, 2022
afdfd1a
Merge branch 'rubberduck-vba:next' into dev-5459-Move_Closer_to_Usage…
awb95 Jan 28, 2022
394cfab
Update appveyor.yml
retailcoder Jan 29, 2022
7a6bfed
Update appveyor.yml
retailcoder Jan 29, 2022
0adff04
Update appveyor.yml
retailcoder Jan 29, 2022
7c523c4
Update appveyor.yml
retailcoder Jan 29, 2022
1296cbd
Revert "Update MissingAttributeInspectionTests.cs"
MDoerner Feb 21, 2022
47c62f7
Save attributes for constants with the correct key
MDoerner Feb 21, 2022
535ce21
single-quote upload filespec for codecov
Vogel612 Feb 21, 2022
b270eba
Merge pull request #5948 from MDoerner/FixDecOnConstAgain
retailcoder Feb 21, 2022
f17590b
Merge pull request #5949 from rubberduck-vba/codecov-the-ever-so-manyeth
retailcoder Feb 21, 2022
4ebc870
Use env to generate release build URL
Vogel612 Feb 23, 2022
a07fcac
Merge pull request #5951 from rubberduck-vba/appveyor-release-url
retailcoder Feb 24, 2022
3621d82
Refine TODO Marker detection
Vogel612 Mar 7, 2022
379a84f
Add 'On Error Resume Next' following TestExit label
BZngr Apr 25, 2022
753c0aa
Fix RemoveOptionStatementQuickFix Description for different Option-St…
awb95 May 6, 2022
548d850
Rename RemoveOptionBaseStatement* to RemoveRedundantOptionStatement*
awb95 May 6, 2022
c037610
Fix Resource typo
awb95 May 6, 2022
2ed018c
Merge pull request #5958 from rubberduck-vba/fix/todo-markers
Vogel612 May 7, 2022
3694d83
Merge pull request #5975 from BZngr/5963_TestExceptionHandling
Vogel612 May 7, 2022
b88c22f
Merge pull request #5976 from awb95/dev-5955-Incorrect_QuickFix_Descr…
Vogel612 May 7, 2022
76bbdd9
Update PAT
rubberduck-vba-releasebot May 7, 2022
8c9753a
Merge pull request #5978 from rubberduck-vba/rubberduck-vba-releasebo…
Vogel612 May 7, 2022
dabd719
Update Italian translation.
PhilCattivocaratere May 8, 2022
25728b3
Merge pull request #5980 from PhilCattivocaratere/next
retailcoder May 8, 2022
18dadad
Apply suggestions from code review
awb95 May 11, 2022
07d05cd
Fix incorrect suggestions
awb95 May 11, 2022
c05a29c
Apply some suggestions
awb95 May 15, 2022
be40f30
Apply suggestion
awb95 May 15, 2022
4a63755
Update SettingsDesigner.SettingsSingleFileGenerator
BZngr May 17, 2022
7221ea0
Modify Inspection to evaluate Supertype names
BZngr May 18, 2022
b808bd8
Update tests for SuperType names evaluation
BZngr May 18, 2022
9388405
Update xmldoc content
BZngr May 22, 2022
1e09fb4
Rename Inspection and Tests
BZngr May 22, 2022
c8bb74f
Update Resources
BZngr May 22, 2022
0568382
Merge branch 'next' into 5608_WkshtEnumDeclaration
BZngr May 26, 2022
332198d
Init _emptyLineHandlingMethod from UserSettings
BZngr Jun 11, 2022
a96c138
Merge pull request #5985 from BZngr/5285_EmptyLineHandlingMethod
retailcoder Jun 11, 2022
512f685
Merge pull request #5983 from BZngr/5608_WkshtEnumDeclaration
retailcoder Jun 12, 2022
9d132b5
Merge pull request #5941 from awb95/dev-5459-Move_Closer_to_Usage
retailcoder Jun 12, 2022
fea653b
Modify XXXNotUsed inspection resources
BZngr Jun 13, 2022
06ddf1e
Modify ParameterNotUsedInspection resource
BZngr Jun 13, 2022
c102b38
Delete XXXNotUsedInspection resources
BZngr Jun 13, 2022
4f05117
Delete ParameterNotUsedInspection resource
BZngr Jun 14, 2022
f5c8497
Implement Project Export Folder caching
BZngr Jun 17, 2022
95b0041
Add Project/Path Cache tests
BZngr Jun 17, 2022
ba5b8fa
Refactor/Update tests
BZngr Jun 19, 2022
1a2818d
Declare IFileSystemBrowsesrFactory field as private readonly
BZngr Jun 22, 2022
987bfb6
Refactor ExportAllCommand_MultipleProjectFolders test
BZngr Jun 22, 2022
2761497
Add ProjectToExportFolderMap registration
BZngr Jun 23, 2022
9e8f113
Introduce ProjectToExportFolderMap
BZngr Jun 23, 2022
5f65968
Introduce ProjectToExportFolderMap
BZngr Jun 23, 2022
b57837b
Merge pull request #5988 from BZngr/5584_CacheExportPath
retailcoder Jul 13, 2022
8207742
Merge pull request #5986 from BZngr/IsNotUsedResources
retailcoder Jul 13, 2022
a12790c
Italian translation 2.5.2.6096-pre
PhilCattivocaratere Jul 17, 2022
8ecbf90
Add UDTMemberNotUsedInspection
BZngr Jul 20, 2022
e1f6e84
Add UDTMemberNotUsedInspection
BZngr Jul 20, 2022
19c3104
Merge pull request #6004 from BZngr/UDTMemberNotUsed
retailcoder Jul 20, 2022
d7a3b8d
Merge pull request #1 from rubberduck-vba/next
PhilCattivocaratere Jul 21, 2022
45cf5c2
Altre piccole traduzioni
PhilCattivocaratere Jul 21, 2022
41fee8a
Merge branch 'next' of https://github.com/PhilCattivocaratere/Rubberd…
PhilCattivocaratere Jul 21, 2022
c61e14f
Merge pull request #6001 from PhilCattivocaratere/next
Vogel612 Jul 22, 2022
f139365
Comments translation
PhilCattivocaratere Jul 23, 2022
bb4ce86
Merge pull request #6005 from PhilCattivocaratere/TraduzioneCommenti
Vogel612 Jul 24, 2022
76d59f8
Fix Indents on comments
awb95 Aug 19, 2022
9059983
Add Test for Issue #6007
awb95 Aug 19, 2022
81d5125
Fix Restore alignment Stack on ')'
awb95 Aug 19, 2022
1254523
Fix existing Test - wrong Indenter Setting
awb95 Aug 19, 2022
7082d83
Merge pull request #6008 from awb95/dev-6007-Indenter_comments
Vogel612 Aug 19, 2022
b288249
Update appveyor.yml
rubberduck-vba-releasebot Aug 20, 2022
b15503a
Merge pull request #6010 from rubberduck-vba/rubberduck-vba-releasebo…
Vogel612 Aug 20, 2022
c5a5713
Recognize "If Then:" as SingleLine-If so no Indent
awb95 Aug 20, 2022
73514da
Fix Regex for IfThenElseOnSameLineWorks-Test
awb95 Aug 20, 2022
1cf1f61
Edit Test to contain valid VBA Code and address #5929
awb95 Aug 20, 2022
1054c58
Add Link to corresponding Issue
awb95 Aug 20, 2022
749024a
Merge pull request #6009 from awb95/dev-5960-Inconsistant_indentation
retailcoder Aug 20, 2022
b1fb5be
Update Rubberduck.SmartIndenter/LogicalCodeLine.cs
awb95 Aug 20, 2022
22b5e41
Update Rubberduck.SmartIndenter/AbsoluteCodeLine.cs
awb95 Aug 20, 2022
5ff67f4
Merge pull request #6012 from awb95/dev-5929-Indent_Single_Line_If_th…
retailcoder Aug 21, 2022
143fc9d
Extend Regex for Declare 'PtrSafe'
awb95 Aug 22, 2022
fccbe4e
Add Test for Declare PtrSafe #4795
awb95 Aug 22, 2022
b53f353
Merge pull request #6014 from awb95/dev-4795-Indenter_Declare_PtrSafe
retailcoder Aug 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![banner](https://user-images.githubusercontent.com/5751684/113501222-8edfe880-94f1-11eb-99a9-64583e413ef3.png)
<!-- ![banner](https://user-images.githubusercontent.com/5751684/113501222-8edfe880-94f1-11eb-99a9-64583e413ef3.png) -->

[**Installing**](https://github.com/rubberduck-vba/Rubberduck/wiki/Installing) • [Contributing](https://github.com/rubberduck-vba/Rubberduck/blob/next/CONTRIBUTING.md) • [Attributions](https://github.com/rubberduck-vba/Rubberduck/blob/next/docs/Attributions.md) • [Blog](https://rubberduckvba.blog) • [Wiki](https://github.com/rubberduck-vba/Rubberduck/wiki) • [rubberduckvba.com](https://rubberduckvba.com)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
/// ]]>
/// </module>
/// </example>
internal class EmptyMethodInspection : DeclarationInspectionBase
internal sealed class EmptyMethodInspection : DeclarationInspectionBase
{
public EmptyMethodInspection(IDeclarationFinderProvider declarationFinderProvider)
: base(declarationFinderProvider, DeclarationType.Member)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public override bool VisitModuleDeclarations(VBAParser.ModuleDeclarationsContext
public override bool VisitModuleDeclarationsElement(VBAParser.ModuleDeclarationsElementContext context)
{
return context.moduleVariableStmt() == null
&& context.constStmt() == null
&& context.moduleConstStmt() == null
&& context.enumerationStmt() == null
&& context.udtDeclaration() == null
&& context.eventStmt() == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
/// Warns about 'Sub' procedures that could be refactored into a 'Function'.
/// </summary>
/// <why>
/// Idiomatic VB code uses 'Function' procedures to return a single value. If the procedure isn't side-effecting, consider writing is as a
/// 'Function' rather than a 'Sub' the returns a result through a 'ByRef' parameter.
/// Idiomatic VB code uses 'Function' procedures to return a single value. If the procedure isn't side-effecting, consider writing it as a
/// 'Function' rather than a 'Sub' that returns a result through a 'ByRef' parameter.
/// </why>
/// <example hasResult="true">
/// <module name="MyModule" type="Standard Module">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using Rubberduck.CodeAnalysis.Inspections.Abstract;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using Rubberduck.Parsing.VBA.DeclarationCaching;
using Rubberduck.Resources.Inspections;
using Rubberduck.VBEditor.SafeComWrappers;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <summary>
/// Identifies public enumerations declared within worksheet modules.
/// </summary>
/// <why>
/// Copying a worksheet which contains a public Enum declaration will also create a copy of the Enum declaration.
/// The copied Enum declaration will result in an 'Ambiguous name detected' compiler error.
/// Declaring Enumerations in Standard or Class modules avoids unintentional duplication of an Enum declaration.
/// </why>
/// <example hasResult="true">
/// <module name="WorksheetModule" type="Document Module">
/// <![CDATA[
/// Public Enum ExampleEnum
/// FirstEnum = 0
/// SecondEnum
/// End Enum
/// ]]>
/// </module>
/// </example>
/// <example hasResult="false">
/// <module name="WorksheetModule" type="Document Module">
/// <![CDATA[
/// Private Enum ExampleEnum
/// FirstEnum = 0
/// SecondEnum
/// End Enum
/// ]]>
/// </module>
/// </example>
internal sealed class PublicEnumerationDeclaredInWorksheetInspection : DeclarationInspectionBase
{
private readonly string[] _worksheetSuperTypeNames = new string[] { "Worksheet", "_Worksheet" };

public PublicEnumerationDeclaredInWorksheetInspection(IDeclarationFinderProvider declarationFinderProvider)
: base(declarationFinderProvider, DeclarationType.Enumeration)
{}

protected override bool IsResultDeclaration(Declaration enumeration, DeclarationFinder finder)
{
if (enumeration.Accessibility != Accessibility.Private
&& enumeration.QualifiedModuleName.ComponentType == ComponentType.Document)
{
if (enumeration.ParentDeclaration is ClassModuleDeclaration classModuleDeclaration)
{
return RetrieveSuperTypeNames(classModuleDeclaration).Intersect(_worksheetSuperTypeNames).Any();
}
}

return false;
}

protected override string ResultDescription(Declaration declaration)
{
return string.Format(InspectionResults.PublicEnumerationDeclaredInWorksheetInspection,
declaration.IdentifierName);
}

/// <summary>
/// Supports property injection for testing.
/// </summary>
/// <remarks>
/// MockParser does not populate SuperTypes/SuperTypeNames. RetrieveSuperTypeNames Func allows injection
/// of ClassModuleDeclaration.SuperTypeNames property results.
/// </remarks>
public Func<ClassModuleDeclaration, IEnumerable<string>> RetrieveSuperTypeNames { set; private get; } = GetSuperTypeNames;

private static IEnumerable<string> GetSuperTypeNames(ClassModuleDeclaration classModule)
{
return classModule.SupertypeNames;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,6 @@ private static string ComponentPropertyValue(IVBComponent component, string prop
return null;
}

protected override string ResultDescription(IdentifierReference reference, string codeName)
{
return InspectionResults.SheetAccessedUsingStringInspection;
}
protected override string ResultDescription(IdentifierReference reference, string codeName) => InspectionResults.SheetAccessedUsingStringInspection;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete.ThunderCode
/// While perfectly legal as Type or Enum member names, these identifiers should be avoided:
/// they need to be square-bracketed everywhere they are used.
/// </why>
internal class KeywordsUsedAsMemberInspection : DeclarationInspectionBase
internal sealed class KeywordsUsedAsMemberInspection : DeclarationInspectionBase
{
public KeywordsUsedAsMemberInspection(IDeclarationFinderProvider declarationFinderProvider)
: base(declarationFinderProvider, DeclarationType.EnumerationMember, DeclarationType.UserDefinedTypeMember)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete.ThunderCode
/// code our friend Andrew Jackson would have written to confuse Rubberduck's parser and/or resolver.
/// This inspection may accidentally reveal non-breaking spaces in code copied and pasted from a website.
/// </why>
internal class NonBreakingSpaceIdentifierInspection : DeclarationInspectionBase
internal sealed class NonBreakingSpaceIdentifierInspection : DeclarationInspectionBase
{
private const string Nbsp = "\u00A0";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using Rubberduck.CodeAnalysis.Inspections.Abstract;
using Rubberduck.CodeAnalysis.Inspections.Extensions;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using Rubberduck.Parsing.VBA.DeclarationCaching;
using Rubberduck.Resources.Inspections;
using System.Linq;

namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <summary>
/// Warns about User Defined Type (UDT) members that are never referenced.
/// </summary>
/// <why>
/// Declarations that are never used should be removed.
/// </why>
/// <example hasResult="true">
/// <module name="MyModule" type="Standard Module">
/// <![CDATA[
/// Private Type TTestModule
/// FirstVal As Long
/// End Type
///
/// Private this As TTestModule
/// ]]>
/// </module>
/// </example>
/// <example hasResult="false">
/// <module name="MyModule" type="Standard Module">
/// <![CDATA[
/// Private Type TTestModule
/// FirstVal As Long
/// End Type
///
/// Private this As TTestModule
///
/// 'UDT Member is assigned but not used
/// Public Sub DoSomething()
/// this.FirstVal = 42
/// End Sub
/// ]]>
/// </module>
/// </example>
/// <example hasResult="false">
/// <module name="MyModule" type="Standard Module">
/// <![CDATA[
/// Private Type TTestModule
/// FirstVal As Long
/// End Type
///
/// Private this As TTestModule
///
/// 'UDT Member is assigned and read
/// Public Sub DoSomething()
/// this.FirstVal = 42
/// Debug.Print this.FirstVal
/// End Sub
/// ]]>
/// </module>
/// </example>
internal sealed class UDTMemberNotUsedInspection : DeclarationInspectionBase
{
public UDTMemberNotUsedInspection(IDeclarationFinderProvider declarationFinderProvider)
: base(declarationFinderProvider, DeclarationType.UserDefinedTypeMember)
{}

protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder)
{
return declaration.DeclarationType.Equals(DeclarationType.UserDefinedTypeMember)
&& !declaration.References.Any();
}

protected override string ResultDescription(Declaration declaration)
{
var declarationType = declaration.DeclarationType.ToLocalizedString();
var declarationName = declaration.IdentifierName;
return string.Format(
InspectionResults.IdentifierNotUsedInspection,
declarationType,
declarationName);
}
}
}
16 changes: 16 additions & 0 deletions Rubberduck.CodeAnalysis/QuickFixes/Abstract/QuickFixBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ public void RemoveInspections(params Type[] inspections)
public virtual CodeKind TargetCodeKind => CodeKind.CodePaneCode;

public abstract void Fix(IInspectionResult result, IRewriteSession rewriteSession);

/// <summary>
/// FixMany defers the enumeration of inspection results to the QuickFix
/// </summary>
/// <remarks>
/// The default implementation enumerates the results collection calling Fix() for each result.
/// Override this funcion when a QuickFix needs operate on results as a group (e.g., RemoveUnusedDeclarationQuickFix)
/// </remarks>
public virtual void Fix(IReadOnlyCollection<IInspectionResult> results, IRewriteSession rewriteSession)
{
foreach (var result in results)
{
Fix(result, rewriteSession);
}
}

public abstract string Description(IInspectionResult result);

public abstract bool CanFixMultiple { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ namespace Rubberduck.CodeAnalysis.QuickFixes.Concrete
/// ]]>
/// </after>
/// </example>
internal sealed class RemoveOptionBaseStatementQuickFix : QuickFixBase
internal sealed class RemoveRedundantOptionStatementQuickFix : QuickFixBase
{
public RemoveOptionBaseStatementQuickFix()
public RemoveRedundantOptionStatementQuickFix()
: base(typeof(RedundantOptionInspection))
{}

Expand All @@ -47,7 +47,12 @@ public override void Fix(IInspectionResult result, IRewriteSession rewriteSessio
rewriter.Remove(result.Context);
}

public override string Description(IInspectionResult result) => Resources.Inspections.QuickFixes.RemoveOptionBaseStatementQuickFix;
public override string Description(IInspectionResult result)
{
return string.Format(
Resources.Inspections.QuickFixes.RemoveRedundantOptionStatementQuickFix,
result.Context.GetText());
}

public override bool CanFixMultiple => true;
public override bool CanFixInProcedure => false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
using Rubberduck.CodeAnalysis.Inspections.Concrete;
using Rubberduck.CodeAnalysis.QuickFixes.Abstract;
using Rubberduck.Parsing.Rewriter;
using Rubberduck.Refactorings;
using Rubberduck.Refactorings.DeleteDeclarations;
using System.Collections.Generic;
using System.Linq;

namespace Rubberduck.CodeAnalysis.QuickFixes.Concrete
{
Expand Down Expand Up @@ -35,14 +39,25 @@ namespace Rubberduck.CodeAnalysis.QuickFixes.Concrete
/// </example>
internal sealed class RemoveUnassignedIdentifierQuickFix : QuickFixBase
{
public RemoveUnassignedIdentifierQuickFix()
private readonly ICodeOnlyRefactoringAction<DeleteDeclarationsModel> _refactoring;
public RemoveUnassignedIdentifierQuickFix(DeleteDeclarationsRefactoringAction refactoringAction)
: base(typeof(VariableNotAssignedInspection))
{}
{
_refactoring = refactoringAction;
}

public override void Fix(IInspectionResult result, IRewriteSession rewriteSession)
{
var rewriter = rewriteSession.CheckOutModuleRewriter(result.Target.QualifiedModuleName);
rewriter.Remove(result.Target);
var model = new DeleteDeclarationsModel(result.Target);

_refactoring.Refactor(model, rewriteSession);
}

public override void Fix(IReadOnlyCollection<IInspectionResult> results, IRewriteSession rewriteSession)
{
var model = new DeleteDeclarationsModel(results.Select(r => r.Target));

_refactoring.Refactor(model, rewriteSession);
}

public override string Description(IInspectionResult result) => Resources.Inspections.QuickFixes.RemoveUnassignedIdentifierQuickFix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
using Rubberduck.CodeAnalysis.Inspections.Concrete;
using Rubberduck.CodeAnalysis.QuickFixes.Abstract;
using Rubberduck.Parsing.Rewriter;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Refactorings;
using Rubberduck.Refactorings.Common;
using Rubberduck.Refactorings.DeleteDeclarations;
using System.Collections.Generic;
using System.Linq;

namespace Rubberduck.CodeAnalysis.QuickFixes.Concrete
{
Expand Down Expand Up @@ -31,25 +37,37 @@ namespace Rubberduck.CodeAnalysis.QuickFixes.Concrete
/// Option Explicit
///
/// Public Sub DoSomething()
///
/// Debug.Print 42
/// End Sub
/// ]]>
/// </after>
/// </example>
internal sealed class RemoveUnusedDeclarationQuickFix : QuickFixBase
{
public RemoveUnusedDeclarationQuickFix()
private readonly ICodeOnlyRefactoringAction<DeleteDeclarationsModel> _refactoring;

public RemoveUnusedDeclarationQuickFix(DeleteDeclarationsRefactoringAction refactoringAction)
: base(typeof(ConstantNotUsedInspection),
typeof(ProcedureNotUsedInspection),
typeof(VariableNotUsedInspection),
typeof(LineLabelNotUsedInspection))
{}
typeof(LineLabelNotUsedInspection),
typeof(UDTMemberNotUsedInspection))
{
_refactoring = refactoringAction;
}

public override void Fix(IInspectionResult result, IRewriteSession rewriteSession)
{
var rewriter = rewriteSession.CheckOutModuleRewriter(result.Target.QualifiedModuleName);
rewriter.Remove(result.Target);
var model = new DeleteDeclarationsModel(result.Target);

_refactoring.Refactor(model, rewriteSession);
}

public override void Fix(IReadOnlyCollection<IInspectionResult> results, IRewriteSession rewriteSession)
{
var model = new DeleteDeclarationsModel(results.Select(r => r.Target));

_refactoring.Refactor(model, rewriteSession);
}

public override string Description(IInspectionResult result) => Resources.Inspections.QuickFixes.RemoveUnusedDeclarationQuickFix;
Expand Down
1 change: 1 addition & 0 deletions Rubberduck.CodeAnalysis/QuickFixes/IQuickFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Rubberduck.CodeAnalysis.QuickFixes
public interface IQuickFix
{
void Fix(IInspectionResult result, IRewriteSession rewriteSession);
void Fix(IReadOnlyCollection<IInspectionResult> results, IRewriteSession rewriteSession);
string Description(IInspectionResult result);

bool CanFixMultiple { get; }
Expand Down
Loading