From 67dd92d5baff71495faa5dce69638c07597a07e7 Mon Sep 17 00:00:00 2001 From: Mathieu Guindon Date: Sun, 4 Apr 2021 20:29:36 -0400 Subject: [PATCH 1/6] address or suppress most warnings and messages --- .editorconfig | 13 +++ .../Concrete/AssignmentNotUsedInspection.cs | 8 +- .../Concrete/InvalidAnnotationInspection.cs | 7 +- .../SheetAccessedUsingStringInspection.cs | 3 +- .../UnreachableCaseEvaluation/FilterLimits.cs | 14 ++- .../Concrete/ExpandBangNotationQuickFix.cs | 4 +- .../CodeExplorerMemberViewModel.cs | 2 +- .../ExtractMethod/ExtractMethodModel.cs | 24 ++-- .../Command/RunSelectedTestModuleCommand.cs | 4 +- .../UI/Refactorings/ExtractMethodDialog.cs | 7 +- .../ComClientLibrary/UnitTesting/FakeBase.cs | 2 +- .../Concrete/MemberAttributeAnnotation.cs | 2 +- .../Concrete/ModuleAttributeAnnotation.cs | 2 +- .../ComReflection/ComProject.cs | 14 ++- Rubberduck.Parsing/Rubberduck.Parsing.csproj | 3 + Rubberduck.Parsing/UIContext/IUiDispatcher.cs | 5 +- .../VBA/RubberduckParserState.cs | 59 +++------- .../ParseTreeValue/ComparableDateValue.cs | 2 +- .../TypeLibs/Abstract/ITypeInfoFunction.cs | 2 +- .../TypeLibs/Abstract/ITypeInfoVariable.cs | 2 +- .../TypeLibs/Abstract/ITypeInfoWrapper.cs | 10 +- .../VbeRuntime/VbeNativeApiAccessor.cs | 9 +- .../SafeComWrappers/Application/ExcelApp.cs | 7 +- .../SafeComWrappers/VB/VBE.cs | 54 ++++++--- Rubberduck.sln | 1 + .../CodeExplorer/MockedCodeExplorer.cs | 5 +- .../UseMeaningfulNameInspectionTests.cs | 2 +- RubberduckTests/Mocks/MockVbeBuilder.cs | 1 - .../ParserState/ParserStateTests.cs | 3 +- .../ExtractMethod/ExtractMethodModelTests.cs | 105 ++++++------------ .../Rewriter/RewriteSessionTestBase.cs | 2 - 31 files changed, 169 insertions(+), 209 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..74cbe3c9d0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +[*.cs] + +# CS1584: XML comment has syntactically incorrect cref attribute +dotnet_diagnostic.CS1584.severity = none + +# CS1041: expected identifier, invalid keyword +dotnet_diagnostic.CS1041.severity = none + +# CS1658: Warning is overriding an error +dotnet_diagnostic.CS1658.severity = none + +# IDE0079: Remove unnecessary suppression +dotnet_diagnostic.IDE0079.severity = none diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/AssignmentNotUsedInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/AssignmentNotUsedInspection.cs index a944cf3f6d..09c8bbee21 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/AssignmentNotUsedInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/AssignmentNotUsedInspection.cs @@ -35,6 +35,8 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete /// value = otherVar * value /// End Sub /// ]]> + /// + /// /// /// /// (T jumpContext, IdentifierReference resultCandidate, Dictionary labelIdLineNumberPairs) where T : ParserRuleContext { - int? executionBranchLine = null; + int? executionBranchLine; switch (jumpContext) { @@ -220,9 +222,7 @@ private static bool IsPotentiallyUsedViaJump(IdentifierReference resultCandidate break; } - return executionBranchLine.HasValue - ? AssignmentIsUsedPriorToExitStmts(resultCandidate, executionBranchLine.Value) - : false; + return executionBranchLine.HasValue && AssignmentIsUsedPriorToExitStmts(resultCandidate, executionBranchLine.Value); } private static bool AssignmentIsUsedPriorToExitStmts(IdentifierReference resultCandidate, int executionBranchLine) diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/InvalidAnnotationInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/InvalidAnnotationInspection.cs index 2c86270f0f..9b53d9ab4c 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/InvalidAnnotationInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/InvalidAnnotationInspection.cs @@ -222,7 +222,7 @@ public InvalidAnnotationInspection(IDeclarationFinderProvider declarationFinderP { return GetUnboundAnnotations(annotations, userDeclarations, identifierReferences) .Where(pta => !pta.Annotation.Target.HasFlag(AnnotationTarget.General) || pta.AnnotatedLine == null) - .Concat(AttributeAnnotationsOnDeclarationsNotAllowingAttributes(annotations, userDeclarations, identifierReferences)) + .Concat(AttributeAnnotationsOnDeclarationsNotAllowingAttributes(userDeclarations)) .ToList(); } @@ -241,10 +241,7 @@ public InvalidAnnotationInspection(IDeclarationFinderProvider declarationFinderP .Where(pta => pta.Annotation.GetType() != typeof(NotRecognizedAnnotation) && !boundAnnotationsSelections.Contains(pta.QualifiedSelection)); } - private IEnumerable AttributeAnnotationsOnDeclarationsNotAllowingAttributes( - IEnumerable annotations, - IEnumerable userDeclarations, - IEnumerable identifierReferences) + private IEnumerable AttributeAnnotationsOnDeclarationsNotAllowingAttributes(IEnumerable userDeclarations) { return userDeclarations .Where(declaration => declaration.AttributesPassContext == null diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs index bb16ba037e..60c5242b25 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs @@ -129,8 +129,7 @@ private static VBAParser.LiteralExpressionContext SheetNameArgumentLiteralExpres private string CodeNameOfVBComponentMatchingSheetName(string projectId, string sheetName) { var components = _projectsProvider.Components(projectId); - - foreach (var (module, component) in components) + foreach (var (_, component) in components) { if (component.Type != ComponentType.Document) { diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/UnreachableCaseEvaluation/FilterLimits.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/UnreachableCaseEvaluation/FilterLimits.cs index 7189b0e467..a384df2ec7 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/UnreachableCaseEvaluation/FilterLimits.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/UnreachableCaseEvaluation/FilterLimits.cs @@ -36,9 +36,9 @@ internal struct Limit where T : IComparable public static bool operator !=(Limit LHS, Limit RHS) => !(LHS == RHS); - public static bool operator >(Limit LHS, T RHS) => LHS.HasValue ? LHS.Value.CompareTo(RHS) > 0 : false; + public static bool operator >(Limit LHS, T RHS) => LHS.HasValue && LHS.Value.CompareTo(RHS) > 0; - public static bool operator <(Limit LHS, T RHS) => LHS.HasValue? LHS.Value.CompareTo(RHS) < 0 : false; + public static bool operator <(Limit LHS, T RHS) => LHS.HasValue && LHS.Value.CompareTo(RHS) < 0; public static bool operator >=(Limit LHS, Limit RHS) => LHS == RHS || LHS > RHS; @@ -106,7 +106,7 @@ public void SetExtents(T min, T max) public bool SetMinimum(T min) { - var setNewValue = false; + bool setNewValue; if (_min.HasValue) { setNewValue = min.CompareTo(_min.Value) > 0; @@ -123,7 +123,7 @@ public bool SetMinimum(T min) public bool SetMaximum(T max) { - var setNewValue = false; + bool setNewValue; if (_max.HasValue) { setNewValue = max.CompareTo(_max.Value) < 0; @@ -195,6 +195,8 @@ public override bool Equals(object obj) return true; } + public override int GetHashCode() => VBEditor.HashCode.Compute(Minimum, Maximum); + public override string ToString() { var minString = string.Empty; @@ -202,13 +204,13 @@ public override string ToString() if (_min.HasValue) { minString = MinimumExtent.HasValue && _min == MinimumExtent - ? $"Min(typeMin)" : $"Min({_min.ToString()})"; + ? $"Min(typeMin)" : $"Min({_min})"; } if (_max.HasValue) { maxString = MaximumExtent.HasValue && _max == MaximumExtent - ? $"Max(typeMax)" : $"Max({_max.ToString()})"; + ? $"Max(typeMax)" : $"Max({_max})"; } return $"{minString}{maxString}"; } diff --git a/Rubberduck.CodeAnalysis/QuickFixes/Concrete/ExpandBangNotationQuickFix.cs b/Rubberduck.CodeAnalysis/QuickFixes/Concrete/ExpandBangNotationQuickFix.cs index 69edb13884..418ccbdedf 100644 --- a/Rubberduck.CodeAnalysis/QuickFixes/Concrete/ExpandBangNotationQuickFix.cs +++ b/Rubberduck.CodeAnalysis/QuickFixes/Concrete/ExpandBangNotationQuickFix.cs @@ -132,8 +132,8 @@ public override string Description(IInspectionResult result) public override bool CanFixInProject => true; public override bool CanFixAll => true; - private string NonIdentifierCharacters = "[](){}\r\n\t.,'\"\\ |!@#$%^&*-+:=; "; - private string AdditionalNonFirstIdentifierCharacters = "0123456789_"; + private readonly string NonIdentifierCharacters = "[](){}\r\n\t.,'\"\\ |!@#$%^&*-+:=; "; + private readonly string AdditionalNonFirstIdentifierCharacters = "0123456789_"; private static readonly Dictionary DefaultMemberOverrides = new Dictionary { diff --git a/Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerMemberViewModel.cs b/Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerMemberViewModel.cs index a105850106..95dfd89bbf 100644 --- a/Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerMemberViewModel.cs +++ b/Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerMemberViewModel.cs @@ -51,7 +51,7 @@ public override string NameWithSignature } public override bool IsObsolete => - Declaration.Annotations.Any(annotation => annotation is ObsoleteAnnotation); + Declaration.Annotations.Any(pta => pta.Annotation is ObsoleteAnnotation); public static readonly DeclarationType[] SubMemberTypes = { diff --git a/Rubberduck.Core/Refactorings/ExtractMethod/ExtractMethodModel.cs b/Rubberduck.Core/Refactorings/ExtractMethod/ExtractMethodModel.cs index 755e89949b..161a01af3e 100644 --- a/Rubberduck.Core/Refactorings/ExtractMethod/ExtractMethodModel.cs +++ b/Rubberduck.Core/Refactorings/ExtractMethod/ExtractMethodModel.cs @@ -60,14 +60,15 @@ public static class IEnumerableExt public class ExtractMethodModel : IExtractMethodModel { - private List _extractDeclarations; - private IExtractMethodParameterClassification _paramClassify; - private IExtractedMethod _extractedMethod; + private readonly List _extractDeclarations = new List(); + private readonly IExtractMethodParameterClassification _paramClassify; + private readonly IExtractedMethod _extractedMethod; public ExtractMethodModel(IExtractedMethod extractedMethod, IExtractMethodParameterClassification paramClassify) { _extractedMethod = extractedMethod; _paramClassify = paramClassify; + _sourceMember = null; } public void extract(IEnumerable declarations, QualifiedSelection selection, string selectedCode) @@ -101,7 +102,7 @@ public void extract(IEnumerable declarations, QualifiedSelection se } _declarationsToMove = _paramClassify.DeclarationsToMove.ToList(); - _rowsToRemove = splitSelection(selection.Selection, _declarationsToMove).ToList(); + _rowsToRemove = SplitSelection(selection.Selection, _declarationsToMove).ToList(); var methodCallPositionStartLine = selectionStartLine - _declarationsToMove.Count(d => d.Selection.StartLine < selectionStartLine); _positionForMethodCall = new Selection(methodCallPositionStartLine, 1, methodCallPositionStartLine, 1); @@ -136,7 +137,7 @@ private static Declaration FindSelectedDeclaration(IEnumerable decl return declaration; } - public IEnumerable splitSelection(Selection selection, IEnumerable declarations) + public IEnumerable SplitSelection(Selection selection, IEnumerable declarations) { var tupleList = new List>(); var declarationRows = declarations @@ -152,7 +153,7 @@ public IEnumerable splitSelection(Selection selection, IEnumerable splitSelection(Selection selection, IEnumerable _locals; + private readonly List _locals = new List(); public IEnumerable Locals { get { return _locals; } } - private IEnumerable _input; + private readonly IEnumerable _input = new List(); public IEnumerable Inputs { get { return _input; } } - private IEnumerable _output; + private readonly IEnumerable _output = new List(); public IEnumerable Outputs { get { return _output; } } - private List _declarationsToMove; + private List _declarationsToMove = new List(); public IEnumerable DeclarationsToMove { get { return _declarationsToMove; } } public IExtractedMethod Method { get { return _extractedMethod; } } @@ -181,7 +182,8 @@ public IEnumerable splitSelection(Selection selection, IEnumerable _rowsToRemove; + + private IList _rowsToRemove; public IEnumerable RowsToRemove { // we need to split selectionToRemove around any declarations that diff --git a/Rubberduck.Core/UI/Command/RunSelectedTestModuleCommand.cs b/Rubberduck.Core/UI/Command/RunSelectedTestModuleCommand.cs index 217c98de83..5d02405946 100644 --- a/Rubberduck.Core/UI/Command/RunSelectedTestModuleCommand.cs +++ b/Rubberduck.Core/UI/Command/RunSelectedTestModuleCommand.cs @@ -23,7 +23,7 @@ private bool SpecialEvaluateCanExecute(object parameter) { return (parameter ?? FindModuleFromSelection()) is Declaration candidate && candidate.DeclarationType == DeclarationType.ProceduralModule && - candidate.Annotations.Any(annotation => annotation is TestModuleAnnotation) && + candidate.Annotations.Any(pta => pta.Annotation is TestModuleAnnotation) && _engine.CanRun && _engine.Tests.Any(test => test.Declaration.QualifiedModuleName.Equals(candidate.QualifiedModuleName)); } @@ -32,7 +32,7 @@ protected override void OnExecute(object parameter) { if (!((parameter ?? FindModuleFromSelection()) is Declaration candidate) || candidate.DeclarationType != DeclarationType.ProceduralModule || - !candidate.Annotations.Any(annotation => annotation is TestModuleAnnotation) || + !candidate.Annotations.Any(pta => pta.Annotation is TestModuleAnnotation) || !_engine.CanRun) { return; diff --git a/Rubberduck.Core/UI/Refactorings/ExtractMethodDialog.cs b/Rubberduck.Core/UI/Refactorings/ExtractMethodDialog.cs index d8915efa0a..05bf53b50f 100644 --- a/Rubberduck.Core/UI/Refactorings/ExtractMethodDialog.cs +++ b/Rubberduck.Core/UI/Refactorings/ExtractMethodDialog.cs @@ -15,6 +15,7 @@ public partial class ExtractMethodDialog : Form, IExtractMethodDialog { public ExtractMethodDialog() { + _returnValue = null; _parameters = new BindingList(); InitializeComponent(); @@ -152,7 +153,7 @@ public string Preview private BindingList _parameters; public IEnumerable Parameters { - get { return _parameters.Where(p => p.Name != _returnValue.Name); } + get { return _parameters.Where(p => p.Name != _returnValue?.Name); } set { _parameters = new BindingList(value.ToList()); @@ -168,11 +169,11 @@ public IEnumerable ReturnValues set { _returnValues = new BindingList(value.ToList()); - var items = _returnValues.ToArray(); + //var items = _returnValues.ToArray(); } } - private ExtractedParameter _returnValue; + private readonly ExtractedParameter _returnValue; public IEnumerable Inputs { get; set; } public IEnumerable Outputs { get; set; } diff --git a/Rubberduck.Main/ComClientLibrary/UnitTesting/FakeBase.cs b/Rubberduck.Main/ComClientLibrary/UnitTesting/FakeBase.cs index 991b06d7e1..db628abc2a 100644 --- a/Rubberduck.Main/ComClientLibrary/UnitTesting/FakeBase.cs +++ b/Rubberduck.Main/ComClientLibrary/UnitTesting/FakeBase.cs @@ -61,7 +61,7 @@ protected bool TrySetReturnValue(bool any = false) var returnInfo = ReturnValues.Where(r => r.Invocation == (any ? FakesProvider.AllInvocations : (int) InvocationCount) && r.Argument != null && - r.Argument == string.Empty).ToList(); + string.IsNullOrWhiteSpace(r.Argument.ToString())).ToList(); if (returnInfo.Count <= 0) { diff --git a/Rubberduck.Parsing/Annotations/Concrete/MemberAttributeAnnotation.cs b/Rubberduck.Parsing/Annotations/Concrete/MemberAttributeAnnotation.cs index 0418c071c2..ccee8c0949 100644 --- a/Rubberduck.Parsing/Annotations/Concrete/MemberAttributeAnnotation.cs +++ b/Rubberduck.Parsing/Annotations/Concrete/MemberAttributeAnnotation.cs @@ -59,7 +59,7 @@ public MemberAttributeAnnotation() public override IReadOnlyList IncompatibleComponentTypes => _incompatibleComponentTypes; - private static AnnotationArgumentType[] _argumentTypes = new[] + private static readonly AnnotationArgumentType[] _argumentTypes = new[] { AnnotationArgumentType.Attribute, AnnotationArgumentType.Text | AnnotationArgumentType.Number | AnnotationArgumentType.Boolean diff --git a/Rubberduck.Parsing/Annotations/Concrete/ModuleAttributeAnnotation.cs b/Rubberduck.Parsing/Annotations/Concrete/ModuleAttributeAnnotation.cs index a286786a77..37a3c2c473 100644 --- a/Rubberduck.Parsing/Annotations/Concrete/ModuleAttributeAnnotation.cs +++ b/Rubberduck.Parsing/Annotations/Concrete/ModuleAttributeAnnotation.cs @@ -54,7 +54,7 @@ public ModuleAttributeAnnotation() private readonly IReadOnlyList _incompatibleComponentTypes; public override IReadOnlyList IncompatibleComponentTypes => _incompatibleComponentTypes; - private static AnnotationArgumentType[] _argumentTypes = new[] + private static readonly AnnotationArgumentType[] _argumentTypes = new[] { AnnotationArgumentType.Attribute, AnnotationArgumentType.Text | AnnotationArgumentType.Number | AnnotationArgumentType.Boolean diff --git a/Rubberduck.Parsing/ComReflection/ComProject.cs b/Rubberduck.Parsing/ComReflection/ComProject.cs index fd1a184e4a..095433c1a9 100644 --- a/Rubberduck.Parsing/ComReflection/ComProject.cs +++ b/Rubberduck.Parsing/ComReflection/ComProject.cs @@ -34,30 +34,32 @@ public class ComProject : ComBase // YGNI... // ReSharper disable once NotAccessedField.Local +#pragma warning disable IDE0052 // Remove unread private members private readonly TypeLibTypeFlags _flags; +#pragma warning restore IDE0052 // Remove unread private members [DataMember(IsRequired = true)] - private List _aliases = new List(); + private readonly List _aliases = new List(); public IEnumerable Aliases => _aliases; [DataMember(IsRequired = true)] - private List _interfaces = new List(); + private readonly List _interfaces = new List(); public IEnumerable Interfaces => _interfaces; [DataMember(IsRequired = true)] - private List _enumerations = new List(); + private readonly List _enumerations = new List(); public IEnumerable Enumerations => _enumerations; [DataMember(IsRequired = true)] - private List _classes = new List(); + private readonly List _classes = new List(); public IEnumerable CoClasses => _classes; [DataMember(IsRequired = true)] - private List _modules = new List(); + private readonly List _modules = new List(); public IEnumerable Modules => _modules; [DataMember(IsRequired = true)] - private List _structs = new List(); + private readonly List _structs = new List(); public IEnumerable Structs => _structs; //Note - Enums and Types should enumerate *last*. That will prevent a duplicate module in the unlikely(?) diff --git a/Rubberduck.Parsing/Rubberduck.Parsing.csproj b/Rubberduck.Parsing/Rubberduck.Parsing.csproj index 27a1ec1c9f..a639d965e8 100644 --- a/Rubberduck.Parsing/Rubberduck.Parsing.csproj +++ b/Rubberduck.Parsing/Rubberduck.Parsing.csproj @@ -35,6 +35,9 @@ Rubberduck.Parsing.PreProcessing + + + diff --git a/Rubberduck.Parsing/UIContext/IUiDispatcher.cs b/Rubberduck.Parsing/UIContext/IUiDispatcher.cs index 0bfe10becb..7ecac9d496 100644 --- a/Rubberduck.Parsing/UIContext/IUiDispatcher.cs +++ b/Rubberduck.Parsing/UIContext/IUiDispatcher.cs @@ -1,4 +1,5 @@ -using System; +using Rubberduck.VBEditor.Utility; +using System; using System.Threading; using System.Threading.Tasks; @@ -19,7 +20,7 @@ public interface IUiDispatcher /// on the UI thread's dispatcher and executed asynchronously. /// For additional operations on the UI thread, you can get a /// reference to the UI thread's context thanks to the property - /// . + /// . /// /// The action that will be executed on the UI /// thread diff --git a/Rubberduck.Parsing/VBA/RubberduckParserState.cs b/Rubberduck.Parsing/VBA/RubberduckParserState.cs index 564a488c8c..1d2b1d7703 100644 --- a/Rubberduck.Parsing/VBA/RubberduckParserState.cs +++ b/Rubberduck.Parsing/VBA/RubberduckParserState.cs @@ -119,30 +119,10 @@ public sealed class RubberduckParserState : IDisposable, IDeclarationFinderProvi [SuppressMessage("ReSharper", "JoinNullCheckWithUsage")] public RubberduckParserState(IVBE vbe, IProjectsRepository projectRepository, IDeclarationFinderFactory declarationFinderFactory, IVbeEvents vbeEvents) { - if (vbe == null) - { - throw new ArgumentNullException(nameof(vbe)); - } - - if (projectRepository == null) - { - throw new ArgumentException(nameof(projectRepository)); - } - - if (declarationFinderFactory == null) - { - throw new ArgumentNullException(nameof(declarationFinderFactory)); - } - - if (vbeEvents == null) - { - throw new ArgumentNullException(nameof(vbeEvents)); - } - - _vbe = vbe; - _projectRepository = projectRepository; - _declarationFinderFactory = declarationFinderFactory; - _vbeEvents = vbeEvents; + _vbe = vbe ?? throw new ArgumentNullException(nameof(vbe)); + _projectRepository = projectRepository ?? throw new ArgumentException(nameof(projectRepository)); + _declarationFinderFactory = declarationFinderFactory ?? throw new ArgumentNullException(nameof(declarationFinderFactory)); + _vbeEvents = vbeEvents ?? throw new ArgumentNullException(nameof(vbeEvents)); var values = Enum.GetValues(typeof(ParserState)); foreach (var value in values) @@ -167,10 +147,7 @@ private void RefreshFinder(IHostApplication host) _declarationFinderFactory.Release(oldDeclarationFinder); } - public void RefreshDeclarationFinder() - { - RefreshFinder(_hostApp); - } + public void RefreshDeclarationFinder() => RefreshFinder(_hostApp); #region Event Handling @@ -324,15 +301,12 @@ public void OnStatusMessageUpdate(string message) /// were projects with duplicate ID's to clear the old /// declarations referencing the project by the old ID. /// - public void RefreshProjects() - { - _projectRepository.Refresh(); - } + public void RefreshProjects() => _projectRepository.Refresh(); + private void RefreshProject(string projectId) { _projectRepository.Refresh(projectId); - ClearStateCache(projectId); } @@ -456,10 +430,8 @@ public void SetModuleState(QualifiedModuleName module, ParserState state, Cancel } } - private IVBProject GetProject(string projectId) - { - return _projectRepository.Project(projectId); - } + private IVBProject GetProject(string projectId) => _projectRepository.Project(projectId); + public void EvaluateParserState(CancellationToken token) { @@ -657,10 +629,9 @@ public List AllComments } } - public void SetModuleComments(QualifiedModuleName module, IEnumerable comments) - { + public void SetModuleComments(QualifiedModuleName module, IEnumerable comments) => _moduleStates[module].SetComments(new List(comments)); - } + public IReadOnlyCollection GetModuleComments(QualifiedModuleName module) { @@ -723,10 +694,8 @@ private IReadOnlyList AllDeclarationsFromModuleStates } } - private bool ThereAreDeclarations() - { - return _moduleStates.Values.Any(state => state.Declarations != null && state.Declarations.Any()); - } + private bool ThereAreDeclarations() => _moduleStates.Values.Any(state => state.Declarations != null && state.Declarations.Any()); + /// /// Gets a copy of the failed resolution stores directly from the module states. (Used for refreshing the DeclarationFinder.) @@ -954,7 +923,7 @@ public ITokenStream GetAttributesTokenStream(QualifiedModuleName qualifiedModule } /// - /// Removes the specified from the collection. + /// Removes the specified from the collection. /// /// /// Returns true when successful. diff --git a/Rubberduck.Refactorings/Common/ParseTreeValue/ComparableDateValue.cs b/Rubberduck.Refactorings/Common/ParseTreeValue/ComparableDateValue.cs index d7c9a6d2ad..89a5a323a6 100644 --- a/Rubberduck.Refactorings/Common/ParseTreeValue/ComparableDateValue.cs +++ b/Rubberduck.Refactorings/Common/ParseTreeValue/ComparableDateValue.cs @@ -97,7 +97,7 @@ public static bool TryParse(string valueText, out ComparableDateValue value) { return false; } - catch (Exception e) + catch (Exception) { //even though a SyntaxErrorException/InputMismatchException is thrown, //this catch-all block seems to be needed(?) diff --git a/Rubberduck.VBEEditor/ComManagement/TypeLibs/Abstract/ITypeInfoFunction.cs b/Rubberduck.VBEEditor/ComManagement/TypeLibs/Abstract/ITypeInfoFunction.cs index 7f905443f5..d294fd2fef 100644 --- a/Rubberduck.VBEEditor/ComManagement/TypeLibs/Abstract/ITypeInfoFunction.cs +++ b/Rubberduck.VBEEditor/ComManagement/TypeLibs/Abstract/ITypeInfoFunction.cs @@ -21,6 +21,6 @@ public interface ITypeInfoFunction : IDisposable string Name { get; } int ParamCount { get; } PROCKIND ProcKind { get; } - void Dispose(); + //void Dispose(); } } \ No newline at end of file diff --git a/Rubberduck.VBEEditor/ComManagement/TypeLibs/Abstract/ITypeInfoVariable.cs b/Rubberduck.VBEEditor/ComManagement/TypeLibs/Abstract/ITypeInfoVariable.cs index 63bbdf7038..1362744ddd 100644 --- a/Rubberduck.VBEEditor/ComManagement/TypeLibs/Abstract/ITypeInfoVariable.cs +++ b/Rubberduck.VBEEditor/ComManagement/TypeLibs/Abstract/ITypeInfoVariable.cs @@ -8,6 +8,6 @@ public interface ITypeInfoVariable : IDisposable string Name { get; } int MemberID { get; } VARFLAGS MemberFlags { get; } - void Dispose(); + //void Dispose(); } } \ No newline at end of file diff --git a/Rubberduck.VBEEditor/ComManagement/TypeLibs/Abstract/ITypeInfoWrapper.cs b/Rubberduck.VBEEditor/ComManagement/TypeLibs/Abstract/ITypeInfoWrapper.cs index 4172422963..54aba926a4 100644 --- a/Rubberduck.VBEEditor/ComManagement/TypeLibs/Abstract/ITypeInfoWrapper.cs +++ b/Rubberduck.VBEEditor/ComManagement/TypeLibs/Abstract/ITypeInfoWrapper.cs @@ -23,7 +23,7 @@ public interface ITypeInfoWrapper : ITypeInfo, IDisposable System.Runtime.InteropServices.ComTypes.TYPEFLAGS Flags { get; } string ContainerName { get; } ITypeInfoVBEExtensions VBEExtensions { get; } - void Dispose(); + //void Dispose(); int GetSafeRefTypeInfo(int hRef, out ITypeInfoWrapper outTI); IntPtr GetCOMReferencePtr(); int GetContainingTypeLib(IntPtr ppTLB, IntPtr pIndex); @@ -37,14 +37,14 @@ public interface ITypeInfoWrapper : ITypeInfo, IDisposable int GetIDsOfNames(IntPtr rgszNames, int cNames, IntPtr pMemId); int Invoke(IntPtr pvInstance, int memid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr); int GetDocumentation(int memid, IntPtr strName, IntPtr strDocString, IntPtr dwHelpContext, IntPtr strHelpFile); - int GetDllEntry(int memid, System.Runtime.InteropServices.ComTypes.INVOKEKIND invKind, IntPtr pBstrDllName, IntPtr pBstrName, IntPtr pwOrdinal); + new int GetDllEntry(int memid, System.Runtime.InteropServices.ComTypes.INVOKEKIND invKind, IntPtr pBstrDllName, IntPtr pBstrName, IntPtr pwOrdinal); int GetRefTypeInfo(int hRef, IntPtr ppTI); int AddressOfMember(int memid, System.Runtime.InteropServices.ComTypes.INVOKEKIND invKind, IntPtr ppv); int CreateInstance(IntPtr pUnkOuter, ref Guid riid, IntPtr ppvObj); int GetMops(int memid, IntPtr pBstrMops); - void ReleaseTypeAttr(IntPtr pTypeAttr); - void ReleaseFuncDesc(IntPtr pFuncDesc); - void ReleaseVarDesc(IntPtr pVarDesc); + new void ReleaseTypeAttr(IntPtr pTypeAttr); + new void ReleaseFuncDesc(IntPtr pFuncDesc); + new void ReleaseVarDesc(IntPtr pVarDesc); ITypeInfoFunctionCollection Funcs { get; } ITypeInfoVariablesCollection Vars { get; } ITypeInfoImplementedInterfacesCollection ImplementedInterfaces { get; } diff --git a/Rubberduck.VBEEditor/VbeRuntime/VbeNativeApiAccessor.cs b/Rubberduck.VBEEditor/VbeRuntime/VbeNativeApiAccessor.cs index b6fb0a168a..6dffee776b 100644 --- a/Rubberduck.VBEEditor/VbeRuntime/VbeNativeApiAccessor.cs +++ b/Rubberduck.VBEEditor/VbeRuntime/VbeNativeApiAccessor.cs @@ -10,14 +10,7 @@ namespace Rubberduck.VBEditor.VbeRuntime public class VbeNativeApiAccessor : IVbeNativeApi { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - - private static readonly DllVersion Version; - private IVbeNativeApi _runtime; - - static VbeNativeApiAccessor() - { - Version = DllVersion.Unknown; - } + private IVbeNativeApi _runtime; private static readonly List<(string Name, Type ApiType, DllVersion Version)> VbeApis =new List<(string Dll, Type ApiType, DllVersion Version)> { diff --git a/Rubberduck.VBEditor.VBA/SafeComWrappers/Application/ExcelApp.cs b/Rubberduck.VBEditor.VBA/SafeComWrappers/Application/ExcelApp.cs index deff1bbbcf..cca1d2b4d2 100644 --- a/Rubberduck.VBEditor.VBA/SafeComWrappers/Application/ExcelApp.cs +++ b/Rubberduck.VBEditor.VBA/SafeComWrappers/Application/ExcelApp.cs @@ -6,12 +6,7 @@ namespace Rubberduck.VBEditor.SafeComWrappers.VBA { public class ExcelApp : HostApplicationBase { - private IEnumerable<(ComponentType componentType, string moduleName, string procedureName)> - _autoMacroIdentifiers; - - public ExcelApp(IVBE vbe) : base(vbe, "Excel", true) - { - } + public ExcelApp(IVBE vbe) : base(vbe, "Excel", true) { } public override IEnumerable AutoMacroIdentifiers => new HostAutoMacro[] { diff --git a/Rubberduck.VBEditor.VBA/SafeComWrappers/VB/VBE.cs b/Rubberduck.VBEditor.VBA/SafeComWrappers/VB/VBE.cs index 3790e6c8d2..b9c24aafbd 100644 --- a/Rubberduck.VBEditor.VBA/SafeComWrappers/VB/VBE.cs +++ b/Rubberduck.VBEditor.VBA/SafeComWrappers/VB/VBE.cs @@ -207,7 +207,7 @@ private static bool ComponentHasName(IVBComponent c, string name) {"SLDWORKS.EXE", typeof(SolidWorksApp)}, }; - private static IHostApplication _host; + private static IHostApplication _host = null; /// Returns the type of Office Application that is hosting the VBE. public IHostApplication HostApplication() @@ -222,21 +222,21 @@ public IHostApplication HostApplication() if (HostAppMap.ContainsKey(host)) { - return (IHostApplication)Activator.CreateInstance(HostAppMap[host], this); + _host = (IHostApplication)Activator.CreateInstance(HostAppMap[host], this); + return _host; } //Guessing the above will work like 99.9999% of the time for supported applications. using (var project = ActiveVBProject) { + IHostApplication result = null; if (project.IsWrappingNullReference) { const int ctlViewHost = 106; - using (var commandBars = CommandBars) { var hostAppControl = commandBars.FindControl(ControlType.Button, ctlViewHost); { - IHostApplication result; if (hostAppControl.IsWrappingNullReference) { result = null; @@ -286,6 +286,11 @@ public IHostApplication HostApplication() } } } + if (result != null) + { + _host = result; + return result; + } var references = project.References; { @@ -294,33 +299,48 @@ public IHostApplication HostApplication() switch (reference.Name) { case "Excel": - return new ExcelApp(this); + result = new ExcelApp(this); + break; case "Access": - return new AccessApp(this); + result = new AccessApp(this); + break; case "Word": - return new WordApp(this); + result = new WordApp(this); + break; case "PowerPoint": - return new PowerPointApp(this); + result = new PowerPointApp(this); + break; case "Outlook": - return new OutlookApp(this); + result = new OutlookApp(this); + break; case "MSProject": - return new ProjectApp(this); + result = new ProjectApp(this); + break; case "Publisher": - return new PublisherApp(this); + result = new PublisherApp(this); + break; case "Visio": - return new VisioApp(this); + result = new VisioApp(this); + break; case "AutoCAD": - return new AutoCADApp(this); + result = new AutoCADApp(this); + break; case "CorelDRAW": - return new CorelDRAWApp(this); + result = new CorelDRAWApp(this); + break; case "SolidWorks": - return new SolidWorksApp(this); + result = new SolidWorksApp(this); + break; + default: + result = null; + break; } } } - } - return null; + _host = result; + return result; + } } /// Returns the topmost MDI child window. diff --git a/Rubberduck.sln b/Rubberduck.sln index cb2cb931c0..3a01a709a0 100644 --- a/Rubberduck.sln +++ b/Rubberduck.sln @@ -10,6 +10,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rubberduck.Parsing", "Rubbe EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{07952BD8-646C-4494-965C-E80F3CDE3485}" ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig appveyor.yml = appveyor.yml libs\Autodesk.AutoCAD.Interop.Common.dll = libs\Autodesk.AutoCAD.Interop.Common.dll libs\Autodesk.AutoCAD.Interop.dll = libs\Autodesk.AutoCAD.Interop.dll diff --git a/RubberduckTests/CodeExplorer/MockedCodeExplorer.cs b/RubberduckTests/CodeExplorer/MockedCodeExplorer.cs index 19239633f9..c43a48b353 100644 --- a/RubberduckTests/CodeExplorer/MockedCodeExplorer.cs +++ b/RubberduckTests/CodeExplorer/MockedCodeExplorer.cs @@ -34,7 +34,6 @@ using Rubberduck.VBEditor.SourceCodeHandling; using Rubberduck.VBEditor.Utility; using RubberduckTests.Settings; -using Rubberduck.Refactorings; using System.IO.Abstractions; namespace RubberduckTests.CodeExplorer @@ -120,11 +119,11 @@ public MockedCodeExplorer(ProjectType projectType, ComponentType componentType = var item = componentTypes[index]; if (item == ComponentType.UserForm) { - project.MockUserFormBuilder($"{item.ToString()}{index}", code is null ? string.Empty : code[index]).AddFormToProjectBuilder(); + project.MockUserFormBuilder($"{item}{index}", code is null ? string.Empty : code[index]).AddFormToProjectBuilder(); } else { - project.AddComponent($"{item.ToString()}{index}", item, code is null ? string.Empty : code[index]); + project.AddComponent($"{item}{index}", item, code is null ? string.Empty : code[index]); } } diff --git a/RubberduckTests/Inspections/UseMeaningfulNameInspectionTests.cs b/RubberduckTests/Inspections/UseMeaningfulNameInspectionTests.cs index 27f2372e4c..7f00600c07 100644 --- a/RubberduckTests/Inspections/UseMeaningfulNameInspectionTests.cs +++ b/RubberduckTests/Inspections/UseMeaningfulNameInspectionTests.cs @@ -159,7 +159,7 @@ internal static Mock> GetInspectio return settings; } - private IEnumerable InspectionResultsForModules(params (string name, string content, ComponentType componentType)[] modules) + private new IEnumerable InspectionResultsForModules(params (string name, string content, ComponentType componentType)[] modules) { var vbe = MockVbeBuilder.BuildFromModules("TestProject", modules, Enumerable.Empty()); return InspectionResults(vbe.Object); diff --git a/RubberduckTests/Mocks/MockVbeBuilder.cs b/RubberduckTests/Mocks/MockVbeBuilder.cs index 0ac5e3a961..ec703b631e 100644 --- a/RubberduckTests/Mocks/MockVbeBuilder.cs +++ b/RubberduckTests/Mocks/MockVbeBuilder.cs @@ -34,7 +34,6 @@ public static class ReferenceLibraryExtensions /// /// Builds a mock . /// - [SuppressMessage("Microsoft.Design", "CA1001")] //CA1001 is complaining about RubberduckTests.Mocks.Windows, which doesn't need to be disposed in this context. public class MockVbeBuilder { public const string TestProjectName = "TestProject1"; diff --git a/RubberduckTests/ParserState/ParserStateTests.cs b/RubberduckTests/ParserState/ParserStateTests.cs index 74be0829f6..b83fd7bc6a 100644 --- a/RubberduckTests/ParserState/ParserStateTests.cs +++ b/RubberduckTests/ParserState/ParserStateTests.cs @@ -14,7 +14,7 @@ namespace RubberduckTests.ParserStateTests [TestFixture] public class ParserStateTests { - private static IEnumerable AllowedRunStates = new [] {ParserState.Ready}; + private static readonly IEnumerable AllowedRunStates = new [] {ParserState.Ready}; [SetUp] public void SetUp() @@ -158,7 +158,6 @@ public void Test_RPS_SuspendParser_Canceled() public void Test_RPS_SuspendParser_IncompatibleState() { var result = SuspensionOutcome.Pending; - var wasRun = false; var wasSuspended = false; var vbe = MockVbeBuilder.BuildFromSingleModule("", ComponentType.StandardModule, out var _); diff --git a/RubberduckTests/Refactoring/ExtractMethod/ExtractMethodModelTests.cs b/RubberduckTests/Refactoring/ExtractMethod/ExtractMethodModelTests.cs index b8a4f79c8a..76cdf68b20 100644 --- a/RubberduckTests/Refactoring/ExtractMethod/ExtractMethodModelTests.cs +++ b/RubberduckTests/Refactoring/ExtractMethod/ExtractMethodModelTests.cs @@ -16,7 +16,7 @@ public class ExtractMethodModelTests { #region variableInternalAndOnlyUsedInternally - string internalVariable = @" + private readonly string internalVariable = @" Option explicit Public Sub CodeWithDeclaration() Dim x as long @@ -39,33 +39,24 @@ End Sub '21: "; - string selectedCode = @" + private readonly string selectedCode = @" y = x + 1 x = 2 Debug.Print y"; - - string outputCode = @" -Public Sub NewVal( byval x as long, byval y as long) - DebugPrint ""something"" - y = x + 1 - x = 2 - DebugPrint y -End Sub"; #endregion - List emRules = new List(){ - new ExtractMethodRuleInSelection(), - new ExtractMethodRuleIsAssignedInSelection(), - new ExtractMethodRuleUsedBefore(), - new ExtractMethodRuleUsedAfter(), - new ExtractMethodRuleExternalReference()}; + //private readonly List emRules = new List(){ + // new ExtractMethodRuleInSelection(), + // new ExtractMethodRuleIsAssignedInSelection(), + // new ExtractMethodRuleUsedBefore(), + // new ExtractMethodRuleUsedAfter(), + // new ExtractMethodRuleExternalReference()}; [Test] [Category("ExtractMethodModelTests")] - public void shouldClassifyDeclarations() + public void ShouldClassifyDeclarations() { - QualifiedModuleName qualifiedModuleName; - using (var state = MockParser.ParseString(internalVariable, out qualifiedModuleName)) + using (var state = MockParser.ParseString(internalVariable, out QualifiedModuleName qualifiedModuleName)) { var declarations = state.AllDeclarations; @@ -88,9 +79,7 @@ public void shouldClassifyDeclarations() [TestFixture] public class WhenExtractingFromASelection : ExtractedMethodTests { - - #region hard coded data - string inputCode = @" + private readonly string inputCode = @" Option explicit Public Sub CodeWithDeclaration() Dim x as long @@ -112,35 +101,25 @@ End Sub "; - string selectedCode = @" + private readonly string selectedCode = @" y = x + 1 x = 2 Debug.Print y"; - string outputCode = @" -Public Sub NewVal( byval x as long) - Dim y as long - y = x + 1 - x = 2 - DebugPrint y -End Sub"; - #endregion - [TestFixture] public class WhenTheSelectionIsNotWithinAMethod : WhenExtractingFromASelection { [Test] [Category("ExtractMethodModelTests")] - public void shouldThrowAnException() + public void ShouldThrowAnException() { - QualifiedModuleName qualifiedModuleName; - using (var state = MockParser.ParseString(inputCode, out qualifiedModuleName)) + using (var state = MockParser.ParseString(inputCode, out QualifiedModuleName qualifiedModuleName)) { var declarations = state.AllDeclarations; var selection = new Selection(21, 1, 22, 17); QualifiedSelection? qSelection = new QualifiedSelection(qualifiedModuleName, selection); - + var extractedMethod = new Mock(); var paramClassify = new Mock(); var SUT = new ExtractMethodModel(extractedMethod.Object, paramClassify.Object); @@ -154,10 +133,9 @@ public void shouldThrowAnException() [Test] [Category("ExtractMethodModelTests")] - public void shouldProvideAListOfDimsNoLongerNeededInTheContainingMethod() + public void ShouldProvideAListOfDimsNoLongerNeededInTheContainingMethod() { - QualifiedModuleName qualifiedModuleName; - using (var state = MockParser.ParseString(inputCode, out qualifiedModuleName)) + using (var state = MockParser.ParseString(inputCode, out QualifiedModuleName qualifiedModuleName)) { var declarations = state.AllDeclarations; @@ -180,10 +158,9 @@ public void shouldProvideAListOfDimsNoLongerNeededInTheContainingMethod() [Test] [Category("ExtractMethodModelTests")] - public void shouldProvideTheSelectionOfLinesOfToRemove() + public void ShouldProvideTheSelectionOfLinesOfToRemove() { - QualifiedModuleName qualifiedModuleName; - using (var state = MockParser.ParseString(inputCode, out qualifiedModuleName)) + using (var state = MockParser.ParseString(inputCode, out QualifiedModuleName qualifiedModuleName)) { var declarations = state.AllDeclarations; @@ -218,10 +195,9 @@ public void shouldProvideTheSelectionOfLinesOfToRemove() [Test] [Category("ExtractMethodModelTests")] - public void shouldProvideTheExtractMethodCaller() + public void ShouldProvideTheExtractMethodCaller() { - QualifiedModuleName qualifiedModuleName; - using (var state = MockParser.ParseString(inputCode, out qualifiedModuleName)) + using (var state = MockParser.ParseString(inputCode, out QualifiedModuleName qualifiedModuleName)) { var declarations = state.AllDeclarations; @@ -244,10 +220,9 @@ public void shouldProvideTheExtractMethodCaller() [Test] [Category("ExtractMethodModelTests")] - public void shouldProvideThePositionForTheMethodCall() + public void ShouldProvideThePositionForTheMethodCall() { - QualifiedModuleName qualifiedModuleName; - using (var state = MockParser.ParseString(inputCode, out qualifiedModuleName)) + using (var state = MockParser.ParseString(inputCode, out QualifiedModuleName qualifiedModuleName)) { var declarations = state.AllDeclarations; @@ -269,10 +244,9 @@ public void shouldProvideThePositionForTheMethodCall() [Test] [Category("ExtractMethodModelTests")] - public void shouldProvideThePositionForTheNewMethod() + public void ShouldProvideThePositionForTheNewMethod() { - QualifiedModuleName qualifiedModuleName; - using (var state = MockParser.ParseString(inputCode, out qualifiedModuleName)) + using (var state = MockParser.ParseString(inputCode, out QualifiedModuleName qualifiedModuleName)) { var declarations = state.AllDeclarations; @@ -304,7 +278,7 @@ public class WhenLocalVariableConstantIsInternal [Test] [Category("ExtractMethodModelTests")] - public void shouldExcludeVariableInSignature() + public void ShouldExcludeVariableInSignature() { #region inputCode @@ -335,10 +309,10 @@ End Sub y = x + 1 x = 2 Debug.Print y"; + #endregion - QualifiedModuleName qualifiedModuleName; - using (var state = MockParser.ParseString(inputCode, out qualifiedModuleName)) + using (var state = MockParser.ParseString(inputCode, out QualifiedModuleName qualifiedModuleName)) { var declarations = state.AllDeclarations; @@ -370,7 +344,7 @@ public class WhenSplittingSelection [Test] [Category("ExtractMethodModelTests")] - public void shouldSplitTheCodeAroundTheDefinition() + public void ShouldSplitTheCodeAroundTheDefinition() { #region inputCode @@ -397,12 +371,6 @@ End Sub "; - var selectedCode = @" - DebugPrint x '8 - y = x + 1 - Dim z as long '10 - z = x - DebugPrint z '12"; #endregion #region whatItShouldLookLike @@ -417,8 +385,7 @@ end sub */ #endregion - QualifiedModuleName qualifiedModuleName; - using (var state = MockParser.ParseString(inputCode, out qualifiedModuleName)) + using (var state = MockParser.ParseString(inputCode, out QualifiedModuleName qualifiedModuleName)) { var declarations = state.AllDeclarations; var selection = new Selection(8, 1, 12, 50); @@ -428,7 +395,7 @@ end sub var yDecl = declarations.Where(decl => decl.IdentifierName.Equals("z")); var SUT = new ExtractMethodModel(extractedMethod.Object, paramClassify.Object); //Act - var actual = SUT.splitSelection(selection, declarations); + var actual = SUT.SplitSelection(selection, declarations); //Assert var selection1 = new Selection(8, 1, 9, 1); var selection2 = new Selection(11, 1, 12, 1); @@ -448,7 +415,7 @@ public class GroupByConsecutiveTests [Test] [Category("ExtractMethodModelTests")] - public void testSelection() + public void TestSelection() { IEnumerable list = new List { 2, 3, 4, 6, 8, 9, 10, 12, 13, 15 }; var grouped = list.GroupByMissing(x => (x + 1), (x, y) => new Selection(x, 1, y, 1), (x, y) => y - x); @@ -456,7 +423,7 @@ public void testSelection() [Test] [Category("ExtractMethodModelTests")] - public void isUnordered() + public void IsUnordered() { IEnumerable list = new List { 2, 3, 4, 6, 7, 9, 8, 12, 13, 15 }; @@ -466,7 +433,7 @@ public void isUnordered() [Test] [Category("ExtractMethodModelTests")] - public void emptyList() + public void EmptyList() { IEnumerable list = new List { }; var grouped = list.GroupByMissing(x => (x + 1), (x, y) => Tuple.Create(x, y), (x, y) => y - x).ToList(); @@ -475,7 +442,7 @@ public void emptyList() [Test] [Category("ExtractMethodModelTests")] - public void listOfSingleItem() + public void ListOfSingleItem() { IEnumerable list = new List { 2 }; var grouped = list.GroupByMissing(x => (x + 1), (x, y) => Tuple.Create(x, y), (x, y) => y - x).ToList(); @@ -490,7 +457,7 @@ public void listOfSingleItem() [Test] [Category("ExtractMethodModelTests")] - public void testingUsefulList() + public void TestingUsefulList() { IEnumerable list = new List { 2, 3, 4, 6, 8, 9, 10, 12, 13, 15 }; var grouped = list.GroupByMissing(x => (x + 1), (x, y) => Tuple.Create(x, y), (x, y) => y - x).ToList(); diff --git a/RubberduckTests/Rewriter/RewriteSessionTestBase.cs b/RubberduckTests/Rewriter/RewriteSessionTestBase.cs index 4536979f81..2f9d6f8b7f 100644 --- a/RubberduckTests/Rewriter/RewriteSessionTestBase.cs +++ b/RubberduckTests/Rewriter/RewriteSessionTestBase.cs @@ -54,10 +54,8 @@ public void TheInvalidationStatusCannotBeChanged() [Category("Rewriter")] public void StatusChangesToInvalidStateStaleParseTreeIfADirtyRewriterGetsCheckedOut() { - var isCalled = false; var rewriteSession = RewriteSession(session => { - isCalled = true; return true; }, out _, rewritersAreDirty: true); var module = new QualifiedModuleName("TestProject", string.Empty, "TestModule"); From 7086c4c13c8fe746351ba83effaba36760291ea0 Mon Sep 17 00:00:00 2001 From: IvenBach Date: Tue, 20 Apr 2021 13:27:48 -0700 Subject: [PATCH 2/6] Add collapse/expand all commands to CodeExplorer --- .../CodeExplorer/CodeExplorerViewModel.cs | 23 ++++++++++++++++++- .../UI/CodeExplorer/CodeExplorerControl.xaml | 17 +++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs b/Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs index e6073f476d..e5c77b0be0 100644 --- a/Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs +++ b/Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs @@ -77,6 +77,8 @@ public sealed class CodeExplorerViewModel : ViewModelBase CollapseAllSubnodesCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCollapseNodes, EvaluateCanSwitchNodeState); ExpandAllSubnodesCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteExpandNodes, EvaluateCanSwitchNodeState); ClearSearchCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteClearSearchCommand); + CollapseAllCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCollapseAllCommand); + ExpandAllCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteExpandAllCommand); if (_externalRemoveCommand != null) { RemoveCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRemoveCommand, _externalRemoveCommand.CanExecute); @@ -345,6 +347,22 @@ private void ExecuteClearSearchCommand(object parameter) } } + private void ExecuteCollapseAllCommand(object parameter) + { + foreach (var project in Projects) + { + ExecuteCollapseNodes(project); + } + } + + private void ExecuteExpandAllCommand(object parameter) + { + foreach (var project in Projects) + { + ExecuteExpandNodes(project); + } + } + private bool EvaluateCanSwitchNodeState(object parameter) { return SelectedItem?.Children?.Any() ?? false; @@ -420,7 +438,10 @@ private void ExecuteRemoveCommand(object param) public CodeExplorerMoveToFolderDragAndDropCommand MoveToFolderDragAndDropCommand { get; set; } - public ICodeExplorerNode FindVisibleNodeForDeclaration(Declaration declaration) + public CommandBase CollapseAllCommand { get; } + public CommandBase ExpandAllCommand { get; } + + public ICodeExplorerNode FindVisibleNodeForDeclaration(Declaration declaration) { if (declaration == null) { diff --git a/Rubberduck.Core/UI/CodeExplorer/CodeExplorerControl.xaml b/Rubberduck.Core/UI/CodeExplorer/CodeExplorerControl.xaml index 8c9edba14c..a13f146922 100644 --- a/Rubberduck.Core/UI/CodeExplorer/CodeExplorerControl.xaml +++ b/Rubberduck.Core/UI/CodeExplorer/CodeExplorerControl.xaml @@ -21,7 +21,7 @@ - + @@ -47,6 +47,8 @@ + + @@ -381,6 +383,19 @@ + + + + + + + From 34dc9f481f320ebd8c9b507b37c4addab7be772b Mon Sep 17 00:00:00 2001 From: IvenBach Date: Tue, 20 Apr 2021 13:40:56 -0700 Subject: [PATCH 3/6] Opportunistic edits Discard variable Simplify string interpolation Suppress remove unused parameter message Suppress remove unread private member message Suppress naming rule violation message --- .../UnreachableCaseEvaluation/UnreachableCaseInspector.cs | 2 +- .../Navigation/CodeExplorer/CodeExplorerViewModel.cs | 6 +++++- Rubberduck.Core/UI/UnitTesting/TestExplorerViewModel.cs | 2 ++ RubberduckTests/CodeExplorer/MockedCodeExplorer.cs | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/UnreachableCaseEvaluation/UnreachableCaseInspector.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/UnreachableCaseEvaluation/UnreachableCaseInspector.cs index 552c84d3c0..5d1d30ca61 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/UnreachableCaseEvaluation/UnreachableCaseInspector.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/UnreachableCaseEvaluation/UnreachableCaseInspector.cs @@ -225,7 +225,7 @@ private string GetBaseTypeForDeclaration(Declaration declaration) VBAParser.SelectCaseStmtContext selectStmt, IParseTreeVisitorResults parseTreeValues) { - var (typeName, value) = SelectExpressionTypeNameAndValue(selectStmt, parseTreeValues); + var (typeName, _) = SelectExpressionTypeNameAndValue(selectStmt, parseTreeValues); return typeName; } diff --git a/Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs b/Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs index e5c77b0be0..8270aa709f 100644 --- a/Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs +++ b/Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs @@ -39,13 +39,15 @@ public enum CodeExplorerSortOrder public sealed class CodeExplorerViewModel : ViewModelBase { // ReSharper disable NotAccessedField.Local - The settings providers aren't used, but several enhancement requests will need them. +#pragma warning disable IDE0052 // Remove unread private members private readonly RubberduckParserState _state; private readonly RemoveCommand _externalRemoveCommand; - private readonly IConfigurationService _generalSettingsProvider; + private readonly IConfigurationService _generalSettingsProvider; private readonly IConfigurationService _windowSettingsProvider; private readonly IUiDispatcher _uiDispatcher; private readonly IVBE _vbe; private readonly ITemplateProvider _templateProvider; +#pragma warning restore IDE0052 // Remove unread private members // ReSharper restore NotAccessedField.Local public CodeExplorerViewModel( @@ -94,7 +96,9 @@ public sealed class CodeExplorerViewModel : ViewModelBase public ObservableCollection Projects { get; } = new ObservableCollection(); +#pragma warning disable IDE1006 // Naming Styles private ObservableCollection