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 25c11f4492..7e9c75ec09 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) { @@ -219,9 +221,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/ImplicitActiveSheetReferenceInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitActiveSheetReferenceInspection.cs index c9e2d34d6c..f7369c6930 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitActiveSheetReferenceInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitActiveSheetReferenceInspection.cs @@ -9,11 +9,11 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete { /// - /// Locates unqualified Worksheet.Range/Cells/Columns/Rows member calls inside worksheet modules. + /// Locates unqualified Worksheet.Range/Cells/Columns/Rows member calls implicitly referring to ActiveSheet. /// /// /// - /// Implicit references to the active worksheet rarely mean to be working with *whatever worksheet is currently active*. + /// Implicit references to the active worksheet (ActiveSheet) rarely mean to be working with *whatever worksheet is currently active*. /// By explicitly qualifying these member calls with a specific Worksheet object, the assumptions are removed, the code /// is more robust, and will be less likely to throw run-time error 1004 or produce unexpected results /// when the active sheet isn't the expected one. diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorkbookReferenceInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorkbookReferenceInspection.cs index c96e2433c6..d66560d6ca 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorkbookReferenceInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorkbookReferenceInspection.cs @@ -13,12 +13,12 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete { /// - /// Locates unqualified Workbook.Worksheets/Sheets/Names member calls inside workbook document modules that implicitly refer to the containing workbook. + /// Locates unqualified Workbook.Worksheets/Sheets/Names member calls inside workbook document modules, that implicitly refer to the host workbook. /// - /// + /// /// - /// Implicit references inside a workbook document module can be mistakes for implicit references to the active workbook, which is the behavior in all other modules - /// By explicitly qualifying these member calls with Me, the ambiguity can be resolved. + /// Implicit references inside a workbook document module can easily be mistaken for implicit references to the active workbook (ActiveWorkbook), which is the behavior in all other module types. + /// By explicitly qualifying these member calls with 'Me', the ambiguity can be resolved. If the intent is to actually refer to the active workbook, qualify with 'ActiveWorkbook' to prevent a bug. /// /// /// @@ -40,7 +40,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete /// ]]> /// /// - [RequiredLibrary("Excel")] + [RequiredHost("Excel")] internal sealed class ImplicitContainingWorkbookReferenceInspection : ImplicitWorkbookReferenceInspectionBase { public ImplicitContainingWorkbookReferenceInspection(IDeclarationFinderProvider declarationFinderProvider) diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorksheetReferenceInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorksheetReferenceInspection.cs index 9f1df67391..d7e3e47a69 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorksheetReferenceInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorksheetReferenceInspection.cs @@ -10,12 +10,12 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete { /// - /// Locates unqualified Worksheet.Range/Cells/Columns/Rows member calls inside worksheet modules that implicitly refer to the containing sheet. + /// Locates unqualified Worksheet.Range/Cells/Columns/Rows member calls inside worksheet modules, that implicitly refer to the containing sheet component. /// - /// + /// /// - /// Implicit references inside a worksheet document module can be mistakes for implicit references to the active worksheet, which is the behavior in all other places. - /// By explicitly qualifying these member calls with Me, the ambiguity can be resolved. + /// Implicit references inside a worksheet document module can easily be mistaken for implicit references to the active worksheet (ActiveSheet), which is the behavior in all other module types. + /// By explicitly qualifying these member calls with 'Me', the ambiguity can be resolved. If the intent is to refer to the active worksheet, qualify with 'ActiveSheet' to prevent a bug. /// /// /// @@ -37,7 +37,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete /// ]]> /// /// - [RequiredLibrary("Excel")] + [RequiredHost("Excel")] internal sealed class ImplicitContainingWorksheetReferenceInspection : ImplicitSheetReferenceInspectionBase { public ImplicitContainingWorksheetReferenceInspection(IDeclarationFinderProvider declarationFinderProvider) 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 8e0c3fdbc6..e4db4f955b 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs @@ -193,8 +193,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/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.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/Navigation/CodeExplorer/CodeExplorerViewModel.cs b/Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs index e6073f476d..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( @@ -77,6 +79,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); @@ -92,7 +96,9 @@ public sealed class CodeExplorerViewModel : ViewModelBase public ObservableCollection Projects { get; } = new ObservableCollection(); +#pragma warning disable IDE1006 // Naming Styles private ObservableCollection