From d9afcb3726a5b831281f797d98f8ab2b8bb32c5e Mon Sep 17 00:00:00 2001 From: IvenBach Date: Wed, 18 Nov 2020 18:03:10 -0800 Subject: [PATCH 001/135] Opportunistic string.Empty replacement --- .../Inspections/SheetAccessedUsingStringInspectionTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RubberduckTests/Inspections/SheetAccessedUsingStringInspectionTests.cs b/RubberduckTests/Inspections/SheetAccessedUsingStringInspectionTests.cs index df237582a3..6fcff40269 100644 --- a/RubberduckTests/Inspections/SheetAccessedUsingStringInspectionTests.cs +++ b/RubberduckTests/Inspections/SheetAccessedUsingStringInspectionTests.cs @@ -216,7 +216,7 @@ private IEnumerable ArrangeParserAndGetResults(string inputCo var builder = new MockVbeBuilder(); var referencedProject = builder.ProjectBuilder("ReferencedProject", ProjectProtection.Unprotected) - .AddComponent("SheetFromOtherProject", ComponentType.Document, "", + .AddComponent("SheetFromOtherProject", ComponentType.Document, string.Empty, properties: new[] { CreateVBComponentPropertyMock("Name", "SheetFromOtherProject").Object, @@ -226,7 +226,7 @@ private IEnumerable ArrangeParserAndGetResults(string inputCo var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected) .AddComponent("Module1", ComponentType.StandardModule, inputCode) - .AddComponent("Sheet1", ComponentType.Document, "", + .AddComponent("Sheet1", ComponentType.Document, string.Empty, properties: new[] { CreateVBComponentPropertyMock("Name", sheetName).Object, From 120c1a8c9946438e780d32cf8641de8e39fe509b Mon Sep 17 00:00:00 2001 From: IvenBach Date: Wed, 18 Nov 2020 23:25:05 -0800 Subject: [PATCH 002/135] Convert to lambda expression body --- .../Concrete/SheetAccessedUsingStringInspection.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs index bb16ba037e..5c67180412 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs @@ -166,9 +166,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; } } From d84341230d79e46816f1e93a77eeff8c52bf2b66 Mon Sep 17 00:00:00 2001 From: IvenBach Date: Wed, 18 Nov 2020 23:38:42 -0800 Subject: [PATCH 003/135] Add inspection and test --- ...rationDeclaredWithinWorksheetInspection.cs | 51 ++++++++++++ .../Inspections/InspectionInfo.Designer.cs | 9 +++ .../Inspections/InspectionInfo.resx | 3 + .../Inspections/InspectionResults.Designer.cs | 9 +++ .../Inspections/InspectionResults.resx | 4 + ...nDeclaredWithinWorksheetInspectionTests.cs | 78 +++++++++++++++++++ 6 files changed, 154 insertions(+) create mode 100644 Rubberduck.CodeAnalysis/Inspections/Concrete/EnumerationDeclaredWithinWorksheetInspection.cs create mode 100644 RubberduckTests/Inspections/EnumerationDeclaredWithinWorksheetInspectionTests.cs diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/EnumerationDeclaredWithinWorksheetInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/EnumerationDeclaredWithinWorksheetInspection.cs new file mode 100644 index 0000000000..3d6929c3e0 --- /dev/null +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/EnumerationDeclaredWithinWorksheetInspection.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Antlr4.Runtime.Misc; +using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Results; +using Rubberduck.Parsing; +using Rubberduck.Parsing.Grammar; +using Rubberduck.Parsing.Symbols; +using Rubberduck.Parsing.VBA; +using Rubberduck.Parsing.VBA.DeclarationCaching; +using Rubberduck.Resources.Inspections; +using Rubberduck.VBEditor; +using Rubberduck.VBEditor.ComManagement; + +namespace Rubberduck.CodeAnalysis.Inspections.Concrete +{ + internal class EnumerationDeclaredWithinWorksheetInspection : InspectionBase + { + private readonly IProjectsProvider _projectsProvider; + + public EnumerationDeclaredWithinWorksheetInspection(IDeclarationFinderProvider declarationFinderProvider, IProjectsProvider projectsProvider) + : base(declarationFinderProvider) + { + _projectsProvider = projectsProvider; + } + + protected override IEnumerable DoGetInspectionResults(DeclarationFinder finder) + { + var declaredEnums = finder.DeclarationsWithType(DeclarationType.Enumeration) + .Where(d => d.QualifiedModuleName.ComponentType == VBEditor.SafeComWrappers.ComponentType.DocObject); + + return declaredEnums.Select(d => InspectionResult(d)); + } + + protected override IEnumerable DoGetInspectionResults(QualifiedModuleName module, DeclarationFinder finder) + { + var declaredEnums = finder.DeclarationsWithType(DeclarationType.Enumeration) + .Where(d => d.QualifiedModuleName == module); + + return declaredEnums.Select(d => InspectionResult(d)); + } + + protected virtual IInspectionResult InspectionResult(Declaration declaration) + { + return new DeclarationInspectionResult(this, InspectionResults.EnumerationDeclaredWithinWorksheetInspection, declaration); + } + } +} diff --git a/Rubberduck.Resources/Inspections/InspectionInfo.Designer.cs b/Rubberduck.Resources/Inspections/InspectionInfo.Designer.cs index 94c31a999a..d45a80ad4a 100644 --- a/Rubberduck.Resources/Inspections/InspectionInfo.Designer.cs +++ b/Rubberduck.Resources/Inspections/InspectionInfo.Designer.cs @@ -258,6 +258,15 @@ public static string EncapsulatePublicFieldInspection { } } + /// + /// Looks up a localized string similar to Enumeration defined within Worksheet object.. + /// + public static string EnumerationDeclaredWithinWorksheetInspection { + get { + return ResourceManager.GetString("EnumerationDeclaredWithinWorksheetInspection", resourceCulture); + } + } + /// /// Looks up a localized string similar to A procedure that returns an object may return 'Nothing'. That will cause a runtime error 91 - "Object variable or With block variable not set" on subsequent member access. Perform an 'Is Nothing' check after the 'Set' assignment to guard against runtime errors.. /// diff --git a/Rubberduck.Resources/Inspections/InspectionInfo.resx b/Rubberduck.Resources/Inspections/InspectionInfo.resx index a26a31668d..728f27610a 100644 --- a/Rubberduck.Resources/Inspections/InspectionInfo.resx +++ b/Rubberduck.Resources/Inspections/InspectionInfo.resx @@ -451,4 +451,7 @@ If the parameter can be null, ignore this inspection result; passing a null valu The last parameter (the 'Value' parameter) of property mutators are always passed ByVal. This is true regardless of the presence or absence of a ByRef or ByVal modifier. Exception: A UserDefinedType must always be passed ByRef even when it is the last parameter of a property mutator. + + Enumeration defined within Worksheet object. + \ No newline at end of file diff --git a/Rubberduck.Resources/Inspections/InspectionResults.Designer.cs b/Rubberduck.Resources/Inspections/InspectionResults.Designer.cs index 0ec21c193f..5c5038f9e7 100644 --- a/Rubberduck.Resources/Inspections/InspectionResults.Designer.cs +++ b/Rubberduck.Resources/Inspections/InspectionResults.Designer.cs @@ -258,6 +258,15 @@ public static string EncapsulatePublicFieldInspection { } } + /// + /// Looks up a localized string similar to The enumeration {0} declared within {1} should be declared within a standard module. + /// + public static string EnumerationDeclaredWithinWorksheetInspection { + get { + return ResourceManager.GetString("EnumerationDeclaredWithinWorksheetInspection", resourceCulture); + } + } + /// /// Looks up a localized string similar to Result of '{0}' call is not tested for 'Nothing'.. /// diff --git a/Rubberduck.Resources/Inspections/InspectionResults.resx b/Rubberduck.Resources/Inspections/InspectionResults.resx index e7b771919a..49813bfbe4 100644 --- a/Rubberduck.Resources/Inspections/InspectionResults.resx +++ b/Rubberduck.Resources/Inspections/InspectionResults.resx @@ -524,4 +524,8 @@ In memoriam, 1972-2018 Misleading ByRef modifier used for parameter '{0}' ({1}). {0} Parameter, {1} Member + + The enumeration {0} declared within {1} should be declared within a standard module + {0} identifier; {1} declaring Worksheet. + \ No newline at end of file diff --git a/RubberduckTests/Inspections/EnumerationDeclaredWithinWorksheetInspectionTests.cs b/RubberduckTests/Inspections/EnumerationDeclaredWithinWorksheetInspectionTests.cs new file mode 100644 index 0000000000..7edd1d9944 --- /dev/null +++ b/RubberduckTests/Inspections/EnumerationDeclaredWithinWorksheetInspectionTests.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Rubberduck.CodeAnalysis.Inspections; +using Rubberduck.CodeAnalysis.Inspections.Concrete; +using Rubberduck.Parsing.VBA; +using Rubberduck.VBEditor.SafeComWrappers; +using RubberduckTests.Mocks; +using NUnit.Framework; + +namespace RubberduckTests.Inspections +{ + class EnumerationDeclaredWithinWorksheetInspectionTests : InspectionTestsBase + { + [Test] + [Category("Inspections")] + public void EnumerationDeclaredWithinWorksheet_InspectionName() + { + var inspection = new EnumerationDeclaredWithinWorksheetInspection(null, null); + + Assert.AreEqual(nameof(EnumerationDeclaredWithinWorksheetInspection), inspection.Name); + } + + [Test] + [Category("Inspections")] + public void Project_with_multiple_enumerations_only_returns_worksheet_result() + { + #region InputCode + const string worksheet1Code = @"Option Explicit +Public Enum Worksheet1Enumeration + Option1 = 0 + Option2 = 1 + Option3 = 3 + Option4 = 7 +End Enum +"; + const string worksheet2Code = @"Option Explicit +Dim bar As Long"; + const string standardModuleCode = @"Option Explicit +Public Enum StdModEnumeration + Option1 = 0 + Option2 = 1 + Option3 = 2 + Option4 = 4 +End Enum"; + const string classModuleCode = @"Option Explicit +Public Enum ClassModEnum + Option1 = 0 + Option2 = 1 +End Enum"; + #endregion + + var vbeBuilder = new MockVbeBuilder(); + var project = vbeBuilder.ProjectBuilder("Project1", ProjectProtection.Unprotected) + .AddComponent("Sheet1", ComponentType.DocObject, worksheet1Code) + .AddComponent("Sheet2", ComponentType.DocObject, worksheet2Code) + .AddComponent("Module1", ComponentType.StandardModule, standardModuleCode) + .AddComponent("ClsMod", ComponentType.ClassModule, classModuleCode) + .Build(); + + vbeBuilder.AddProject(project); + + var vbe = vbeBuilder.Build(); + + int actual = InspectionResults(vbe.Object).Count(); + + Assert.AreEqual(1, actual); + } + + protected override IInspection InspectionUnderTest(RubberduckParserState state) + { + return new EnumerationDeclaredWithinWorksheetInspection(state, state.ProjectsProvider); + } + } +} From ddb6a71ab8b5d8dc922b83962c9926fa658741d3 Mon Sep 17 00:00:00 2001 From: IvenBach Date: Tue, 24 Nov 2020 15:08:12 -0800 Subject: [PATCH 004/135] Implement new base for inheritance --- -multiinst | 0 ...rationDeclaredWithinWorksheetInspection.cs | 25 ++-- ...nDeclaredWithinWorksheetInspectionTests.cs | 112 ++++++++++++++---- 3 files changed, 98 insertions(+), 39 deletions(-) create mode 100644 -multiinst diff --git a/-multiinst b/-multiinst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/EnumerationDeclaredWithinWorksheetInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/EnumerationDeclaredWithinWorksheetInspection.cs index 3d6929c3e0..9a6c40f145 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/EnumerationDeclaredWithinWorksheetInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/EnumerationDeclaredWithinWorksheetInspection.cs @@ -14,10 +14,11 @@ using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; using Rubberduck.VBEditor.ComManagement; +using Rubberduck.VBEditor.SafeComWrappers; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { - internal class EnumerationDeclaredWithinWorksheetInspection : InspectionBase + internal class EnumerationDeclaredWithinWorksheetInspection : DeclarationInspectionBase { private readonly IProjectsProvider _projectsProvider; @@ -27,25 +28,17 @@ public EnumerationDeclaredWithinWorksheetInspection(IDeclarationFinderProvider d _projectsProvider = projectsProvider; } - protected override IEnumerable DoGetInspectionResults(DeclarationFinder finder) + protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { - var declaredEnums = finder.DeclarationsWithType(DeclarationType.Enumeration) - .Where(d => d.QualifiedModuleName.ComponentType == VBEditor.SafeComWrappers.ComponentType.DocObject); - - return declaredEnums.Select(d => InspectionResult(d)); + return declaration.DeclarationType == DeclarationType.Enumeration + && declaration.QualifiedModuleName.ComponentType == ComponentType.DocObject; } - protected override IEnumerable DoGetInspectionResults(QualifiedModuleName module, DeclarationFinder finder) + protected override string ResultDescription(Declaration declaration) { - var declaredEnums = finder.DeclarationsWithType(DeclarationType.Enumeration) - .Where(d => d.QualifiedModuleName == module); - - return declaredEnums.Select(d => InspectionResult(d)); - } - - protected virtual IInspectionResult InspectionResult(Declaration declaration) - { - return new DeclarationInspectionResult(this, InspectionResults.EnumerationDeclaredWithinWorksheetInspection, declaration); + return string.Format(InspectionResults.EnumerationDeclaredWithinWorksheetInspection, + declaration.IdentifierName, + declaration.ParentScopeDeclaration.IdentifierName); } } } diff --git a/RubberduckTests/Inspections/EnumerationDeclaredWithinWorksheetInspectionTests.cs b/RubberduckTests/Inspections/EnumerationDeclaredWithinWorksheetInspectionTests.cs index 7edd1d9944..8756b28c41 100644 --- a/RubberduckTests/Inspections/EnumerationDeclaredWithinWorksheetInspectionTests.cs +++ b/RubberduckTests/Inspections/EnumerationDeclaredWithinWorksheetInspectionTests.cs @@ -26,50 +26,116 @@ public void EnumerationDeclaredWithinWorksheet_InspectionName() [Test] [Category("Inspections")] - public void Project_with_multiple_enumerations_only_returns_worksheet_result() + [Category("EnumerationDeclaredWithinWorksheet")] + public void Project_with_multiple_enumerations_flags_only_enum_declared_within_worksheets() { #region InputCode - const string worksheet1Code = @"Option Explicit -Public Enum Worksheet1Enumeration - Option1 = 0 - Option2 = 1 - Option3 = 3 - Option4 = 7 -End Enum -"; - const string worksheet2Code = @"Option Explicit -Dim bar As Long"; + const string worksheetCode = @"Option Explicit +Public Enum WorksheetEnum + wsMember1 = 0 + wsMember1 = 1 +End Enum"; const string standardModuleCode = @"Option Explicit -Public Enum StdModEnumeration - Option1 = 0 - Option2 = 1 - Option3 = 2 - Option4 = 4 +Public Enum StdModEnum + stdMember1 = 0 + stdMember1 = 2 End Enum"; const string classModuleCode = @"Option Explicit Public Enum ClassModEnum - Option1 = 0 - Option2 = 1 + classMember1 = 0 + classMember2 = 3 +End Enum"; + const string userFormModuleCode = @"Option Explicit +Public Enum FormEnum + formMember1 = 0 + formMember2 = 4 End Enum"; #endregion var vbeBuilder = new MockVbeBuilder(); var project = vbeBuilder.ProjectBuilder("Project1", ProjectProtection.Unprotected) - .AddComponent("Sheet1", ComponentType.DocObject, worksheet1Code) - .AddComponent("Sheet2", ComponentType.DocObject, worksheet2Code) - .AddComponent("Module1", ComponentType.StandardModule, standardModuleCode) - .AddComponent("ClsMod", ComponentType.ClassModule, classModuleCode) + .AddComponent("Sheet", ComponentType.DocObject, worksheetCode) + .AddComponent("StdModule", ComponentType.StandardModule, standardModuleCode) + .AddComponent("ClsMod", ComponentType.ClassModule, classModuleCode) + .AddComponent("UserFormMod", ComponentType.UserForm, userFormModuleCode) .Build(); vbeBuilder.AddProject(project); var vbe = vbeBuilder.Build(); - int actual = InspectionResults(vbe.Object).Count(); + var inspectionResults = InspectionResults(vbe.Object); + int actual = inspectionResults.Count(); Assert.AreEqual(1, actual); } + [Test] + [Category("Inspections")] + [Category("EnumerationDeclaredWithinWorksheet")] + [TestCase(ComponentType.ActiveXDesigner)] + [TestCase(ComponentType.ClassModule)] + [TestCase(ComponentType.ComComponent)] + [TestCase(ComponentType.Document)] + [TestCase(ComponentType.MDIForm)] + [TestCase(ComponentType.PropPage)] + [TestCase(ComponentType.RelatedDocument)] + [TestCase(ComponentType.ResFile)] + [TestCase(ComponentType.StandardModule)] + [TestCase(ComponentType.Undefined)] + [TestCase(ComponentType.UserControl)] + [TestCase(ComponentType.UserForm)] + [TestCase(ComponentType.VBForm)] + public void Enumerations_declared_within_non_worksheet_object_have_no_inpsection_result(ComponentType componentType) + { + const string code = @"Option Explicit +Public Enum TestEnum + Member1 + Member2 +End Enum"; + + var vbeBuilder = new MockVbeBuilder(); + var project = vbeBuilder.ProjectBuilder("UnitTestProject", ProjectProtection.Unprotected) + .AddComponent(componentType.ToString() + "module", componentType, code) + .Build(); + + vbeBuilder.AddProject(project); + + var vbe = vbeBuilder.Build(); + + var inspectionResults = InspectionResults(vbe.Object); + int actual = inspectionResults.Count(); + + Assert.AreEqual(0, actual); + } + + [Test] + [Category("Inspections")] + [Category("EnumerationDeclaredWithinWorksheet")] + public void Private_type_declared_within_worksheet_has_no_inspection_result() + { + const string code = @"Option Explicit + +Private Type THelper + Name As String + Address As String +End Type + +Private this as THelper"; + + var vbeBuilder = new MockVbeBuilder(); + var project = vbeBuilder.ProjectBuilder("UnitTestProject", ProjectProtection.Unprotected) + .AddComponent("WorksheetForTest", ComponentType.DocObject, code) + .Build(); + + var vbe = vbeBuilder.Build(); + + var inspectionResults = InspectionResults(vbe.Object); + int actual = inspectionResults.Count(); + + Assert.AreEqual(0, actual); + } + protected override IInspection InspectionUnderTest(RubberduckParserState state) { return new EnumerationDeclaredWithinWorksheetInspection(state, state.ProjectsProvider); From 3b731851dce9f6f1d13e379c7035c7e54dc2ed9f Mon Sep 17 00:00:00 2001 From: IvenBach Date: Wed, 25 Nov 2020 12:04:51 -0800 Subject: [PATCH 005/135] Refactor to use higher abstraction level Removed unused using directives. --- ...nDeclaredWithinWorksheetInspectionTests.cs | 70 ++++++------------- 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/RubberduckTests/Inspections/EnumerationDeclaredWithinWorksheetInspectionTests.cs b/RubberduckTests/Inspections/EnumerationDeclaredWithinWorksheetInspectionTests.cs index 8756b28c41..c6beee14c5 100644 --- a/RubberduckTests/Inspections/EnumerationDeclaredWithinWorksheetInspectionTests.cs +++ b/RubberduckTests/Inspections/EnumerationDeclaredWithinWorksheetInspectionTests.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; +using System.Linq; using Rubberduck.CodeAnalysis.Inspections; using Rubberduck.CodeAnalysis.Inspections.Concrete; using Rubberduck.Parsing.VBA; using Rubberduck.VBEditor.SafeComWrappers; -using RubberduckTests.Mocks; using NUnit.Framework; namespace RubberduckTests.Inspections @@ -34,37 +28,34 @@ public void Project_with_multiple_enumerations_flags_only_enum_declared_within_w Public Enum WorksheetEnum wsMember1 = 0 wsMember1 = 1 -End Enum"; +End Enum +"; const string standardModuleCode = @"Option Explicit Public Enum StdModEnum stdMember1 = 0 stdMember1 = 2 -End Enum"; +End Enum +"; const string classModuleCode = @"Option Explicit Public Enum ClassModEnum classMember1 = 0 classMember2 = 3 -End Enum"; +End Enum +"; const string userFormModuleCode = @"Option Explicit Public Enum FormEnum formMember1 = 0 formMember2 = 4 -End Enum"; +End Enum +"; #endregion - var vbeBuilder = new MockVbeBuilder(); - var project = vbeBuilder.ProjectBuilder("Project1", ProjectProtection.Unprotected) - .AddComponent("Sheet", ComponentType.DocObject, worksheetCode) - .AddComponent("StdModule", ComponentType.StandardModule, standardModuleCode) - .AddComponent("ClsMod", ComponentType.ClassModule, classModuleCode) - .AddComponent("UserFormMod", ComponentType.UserForm, userFormModuleCode) - .Build(); + var inspectionResults = InspectionResultsForModules( + ("Sheet", worksheetCode, ComponentType.DocObject), + ("StdModule", standardModuleCode, ComponentType.StandardModule), + ("ClsMod", classModuleCode, ComponentType.ClassModule), + ("UserFormMod", userFormModuleCode, ComponentType.UserForm)); - vbeBuilder.AddProject(project); - - var vbe = vbeBuilder.Build(); - - var inspectionResults = InspectionResults(vbe.Object); int actual = inspectionResults.Count(); Assert.AreEqual(1, actual); @@ -92,21 +83,11 @@ public void Enumerations_declared_within_non_worksheet_object_have_no_inpsection Public Enum TestEnum Member1 Member2 -End Enum"; - - var vbeBuilder = new MockVbeBuilder(); - var project = vbeBuilder.ProjectBuilder("UnitTestProject", ProjectProtection.Unprotected) - .AddComponent(componentType.ToString() + "module", componentType, code) - .Build(); - - vbeBuilder.AddProject(project); +End Enum +"; - var vbe = vbeBuilder.Build(); - - var inspectionResults = InspectionResults(vbe.Object); - int actual = inspectionResults.Count(); - - Assert.AreEqual(0, actual); + var inspectionResults = InspectionResultsForModules((componentType.ToString() + "module", code, componentType)); + Assert.IsFalse(inspectionResults.Any()); } [Test] @@ -121,19 +102,12 @@ Name As String Address As String End Type -Private this as THelper"; - - var vbeBuilder = new MockVbeBuilder(); - var project = vbeBuilder.ProjectBuilder("UnitTestProject", ProjectProtection.Unprotected) - .AddComponent("WorksheetForTest", ComponentType.DocObject, code) - .Build(); +Private this as THelper +"; - var vbe = vbeBuilder.Build(); - - var inspectionResults = InspectionResults(vbe.Object); - int actual = inspectionResults.Count(); + var inspectionResults = InspectionResultsForModules(("WorksheetForTest", code, ComponentType.DocObject)); - Assert.AreEqual(0, actual); + Assert.IsFalse(inspectionResults.Any()); } protected override IInspection InspectionUnderTest(RubberduckParserState state) From 92e26ab5eca07ed653757596e415056259c9b2b5 Mon Sep 17 00:00:00 2001 From: IvenBach Date: Wed, 25 Nov 2020 12:07:48 -0800 Subject: [PATCH 006/135] Remove unused using directives --- .../EnumerationDeclaredWithinWorksheetInspection.cs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/EnumerationDeclaredWithinWorksheetInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/EnumerationDeclaredWithinWorksheetInspection.cs index 9a6c40f145..44020925ef 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/EnumerationDeclaredWithinWorksheetInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/EnumerationDeclaredWithinWorksheetInspection.cs @@ -1,18 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Antlr4.Runtime.Misc; -using Rubberduck.CodeAnalysis.Inspections.Abstract; -using Rubberduck.CodeAnalysis.Inspections.Results; -using Rubberduck.Parsing; -using Rubberduck.Parsing.Grammar; +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; using Rubberduck.VBEditor.ComManagement; using Rubberduck.VBEditor.SafeComWrappers; From 11c022b96f523ef37a37f13bde770a959dcf9956 Mon Sep 17 00:00:00 2001 From: IvenBach Date: Wed, 25 Nov 2020 12:19:17 -0800 Subject: [PATCH 007/135] Remove local file used by git --- -multiinst | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 -multiinst diff --git a/-multiinst b/-multiinst deleted file mode 100644 index e69de29bb2..0000000000 From 9a02dd19bda47fad18e258c5ca7b538fcce555e1 Mon Sep 17 00:00:00 2001 From: IvenBach Date: Wed, 25 Nov 2020 14:22:14 -0800 Subject: [PATCH 008/135] Add inspection name resource --- .../Inspections/InspectionInfo.Designer.cs | 2 +- Rubberduck.Resources/Inspections/InspectionInfo.resx | 2 +- .../Inspections/InspectionNames.Designer.cs | 9 +++++++++ Rubberduck.Resources/Inspections/InspectionNames.resx | 3 +++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Rubberduck.Resources/Inspections/InspectionInfo.Designer.cs b/Rubberduck.Resources/Inspections/InspectionInfo.Designer.cs index d45a80ad4a..257b760c5a 100644 --- a/Rubberduck.Resources/Inspections/InspectionInfo.Designer.cs +++ b/Rubberduck.Resources/Inspections/InspectionInfo.Designer.cs @@ -259,7 +259,7 @@ public static string EncapsulatePublicFieldInspection { } /// - /// Looks up a localized string similar to Enumeration defined within Worksheet object.. + /// Looks up a localized string similar to Copying a worksheet which contains an `Enum` declaration will duplicate the enum resulting in a state which prevents compilation. Moving the enumeration declaration to a standard module will avoid this situation.. /// public static string EnumerationDeclaredWithinWorksheetInspection { get { diff --git a/Rubberduck.Resources/Inspections/InspectionInfo.resx b/Rubberduck.Resources/Inspections/InspectionInfo.resx index 728f27610a..0ebce445b5 100644 --- a/Rubberduck.Resources/Inspections/InspectionInfo.resx +++ b/Rubberduck.Resources/Inspections/InspectionInfo.resx @@ -452,6 +452,6 @@ If the parameter can be null, ignore this inspection result; passing a null valu The last parameter (the 'Value' parameter) of property mutators are always passed ByVal. This is true regardless of the presence or absence of a ByRef or ByVal modifier. Exception: A UserDefinedType must always be passed ByRef even when it is the last parameter of a property mutator. - Enumeration defined within Worksheet object. + Copying a worksheet which contains an `Enum` declaration will duplicate the enum resulting in a state which prevents compilation. Moving the enumeration declaration to a standard module will avoid this situation. \ No newline at end of file diff --git a/Rubberduck.Resources/Inspections/InspectionNames.Designer.cs b/Rubberduck.Resources/Inspections/InspectionNames.Designer.cs index b1a1a7f01b..3ead79cc80 100644 --- a/Rubberduck.Resources/Inspections/InspectionNames.Designer.cs +++ b/Rubberduck.Resources/Inspections/InspectionNames.Designer.cs @@ -258,6 +258,15 @@ public static string EncapsulatePublicFieldInspection { } } + /// + /// Looks up a localized string similar to Enumeration declared within worksheet. + /// + public static string EnumerationDeclaredWithinWorksheetInspection { + get { + return ResourceManager.GetString("EnumerationDeclaredWithinWorksheetInspection", resourceCulture); + } + } + /// /// Looks up a localized string similar to Member access may return 'Nothing'. /// diff --git a/Rubberduck.Resources/Inspections/InspectionNames.resx b/Rubberduck.Resources/Inspections/InspectionNames.resx index 0862131df8..6d37bd5103 100644 --- a/Rubberduck.Resources/Inspections/InspectionNames.resx +++ b/Rubberduck.Resources/Inspections/InspectionNames.resx @@ -451,4 +451,7 @@ Misleading ByRef parameter modifier + + Enumeration declared within worksheet + \ No newline at end of file From 9c82a4fb4f835d109496cdc550f18aa9316cee04 Mon Sep 17 00:00:00 2001 From: IvenBach Date: Wed, 25 Nov 2020 14:30:41 -0800 Subject: [PATCH 009/135] Add delay to SearchBox --- Rubberduck.Core/UI/Settings/InspectionSettings.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rubberduck.Core/UI/Settings/InspectionSettings.xaml b/Rubberduck.Core/UI/Settings/InspectionSettings.xaml index a91363f8b6..378dff010a 100644 --- a/Rubberduck.Core/UI/Settings/InspectionSettings.xaml +++ b/Rubberduck.Core/UI/Settings/InspectionSettings.xaml @@ -63,7 +63,7 @@