diff --git a/Rubberduck.CodeAnalysis/CodeAnalysisUI.Designer.cs b/Rubberduck.CodeAnalysis/CodeAnalysisUI.Designer.cs index 8d9c5740a6..18acea2c26 100644 --- a/Rubberduck.CodeAnalysis/CodeAnalysisUI.Designer.cs +++ b/Rubberduck.CodeAnalysis/CodeAnalysisUI.Designer.cs @@ -161,6 +161,15 @@ public static string CodeInspectionSettingsPage_Misc { } } + /// + /// Looks up a localized string similar to Ignore Hungarian Notation for UserForm controls. + /// + public static string CodeInspectionSettingsPage_Misc_IgnoreFormControlHungarianNotation { + get { + return ResourceManager.GetString("CodeInspectionSettingsPage_Misc_IgnoreFormControlHungarianNotation", resourceCulture); + } + } + /// /// Looks up a localized string similar to Run inspections automatically on successful parse. /// @@ -493,5 +502,14 @@ public static string GroupingGrid_Filter { return ResourceManager.GetString("GroupingGrid_Filter", resourceCulture); } } + + /// + /// Looks up a localized string similar to Parameter array '{0}' is zero-based.. + /// + public static string InconsistentArrayBaseInspection_ParamArray { + get { + return ResourceManager.GetString("InconsistentArrayBaseInspection_ParamArray", resourceCulture); + } + } } } diff --git a/Rubberduck.CodeAnalysis/CodeAnalysisUI.fr.resx b/Rubberduck.CodeAnalysis/CodeAnalysisUI.fr.resx index d647d3adef..adcac16634 100644 --- a/Rubberduck.CodeAnalysis/CodeAnalysisUI.fr.resx +++ b/Rubberduck.CodeAnalysis/CodeAnalysisUI.fr.resx @@ -263,4 +263,10 @@ Sévérité: + + Ignorer la notation hongroise pour les contrôles des UserForm + + + Le tableau de paramètres (ParamArray) '{0}' a zéro pour base. + \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/CodeAnalysisUI.resx b/Rubberduck.CodeAnalysis/CodeAnalysisUI.resx index 33bba664e2..3d5bc16189 100644 --- a/Rubberduck.CodeAnalysis/CodeAnalysisUI.resx +++ b/Rubberduck.CodeAnalysis/CodeAnalysisUI.resx @@ -1,76 +1,96 @@  + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + + + + + + + + + + + + + + + + + + - + + @@ -89,13 +109,13 @@ text/microsoft-resx - 1.3 + 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Type @@ -245,4 +265,10 @@ Severity: + + Ignore Hungarian Notation for UserForm controls + + + Parameter array '{0}' is zero-based. + \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Abstract/InvalidAnnotationInspectionBase.cs b/Rubberduck.CodeAnalysis/Inspections/Abstract/InvalidAnnotationInspectionBase.cs new file mode 100644 index 0000000000..d04eec59f0 --- /dev/null +++ b/Rubberduck.CodeAnalysis/Inspections/Abstract/InvalidAnnotationInspectionBase.cs @@ -0,0 +1,63 @@ +using Rubberduck.CodeAnalysis.Inspections.Results; +using Rubberduck.Parsing; +using Rubberduck.Parsing.Annotations; +using Rubberduck.Parsing.Symbols; +using Rubberduck.Parsing.VBA; +using Rubberduck.Parsing.VBA.DeclarationCaching; +using Rubberduck.VBEditor; +using System.Collections.Generic; +using System.Linq; + +namespace Rubberduck.CodeAnalysis.Inspections.Abstract +{ + /// + /// An inspection that flags invalid annotation comments. + /// + internal abstract class InvalidAnnotationInspectionBase : InspectionBase + { + protected InvalidAnnotationInspectionBase(IDeclarationFinderProvider declarationFinderProvider) + : base(declarationFinderProvider) { } + + protected QualifiedContext Context(IParseTreeAnnotation pta) => + new QualifiedContext(pta.QualifiedSelection.QualifiedName, pta.Context); + + protected sealed override IEnumerable DoGetInspectionResults(DeclarationFinder finder) + { + return finder.UserDeclarations(DeclarationType.Module) +.Where(module => module != null) +.SelectMany(module => DoGetInspectionResults(module.QualifiedModuleName, finder)); + } + + protected IInspectionResult InspectionResult(IParseTreeAnnotation pta) => + new QualifiedContextInspectionResult(this, ResultDescription(pta), Context(pta)); + + /// + /// Gets all invalid annotations covered by this inspection. + /// + /// All user code annotations. + /// All user declarations. + /// All identifier references in user code. + /// + protected abstract IEnumerable GetInvalidAnnotations( + IEnumerable annotations, + IEnumerable userDeclarations, + IEnumerable identifierReferences); + + /// + /// Gets an annotation-specific description for an inspection result. + /// + /// The invalid annotation. + /// + protected abstract string ResultDescription(IParseTreeAnnotation pta); + + protected sealed override IEnumerable DoGetInspectionResults(QualifiedModuleName module, DeclarationFinder finder) + { + var annotations = finder.FindAnnotations(module); + var userDeclarations = finder.Members(module).ToList(); + var identifierReferences = finder.IdentifierReferences(module).ToList(); + + var invalidAnnotations = GetInvalidAnnotations(annotations, userDeclarations, identifierReferences); + return invalidAnnotations.Select(InspectionResult).ToList(); + } + } +} \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/AnnotationInIncompatibleComponentTypeInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/AnnotationInIncompatibleComponentTypeInspection.cs new file mode 100644 index 0000000000..9e38d568a4 --- /dev/null +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/AnnotationInIncompatibleComponentTypeInspection.cs @@ -0,0 +1,80 @@ +using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.Parsing; +using Rubberduck.Parsing.Annotations; +using Rubberduck.Parsing.Symbols; +using Rubberduck.Parsing.VBA; +using Rubberduck.Resources.Inspections; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; + +namespace Rubberduck.CodeAnalysis.Inspections.Concrete +{ + /// + /// Flags Rubberduck annotations used in a component type that is incompatible with that annotation. + /// + /// + /// Some annotations can only be used in a specific type of module; others cannot be used in certain types of modules. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + internal sealed class AnnotationInIncompatibleComponentTypeInspection : InvalidAnnotationInspectionBase + { + public AnnotationInIncompatibleComponentTypeInspection(IDeclarationFinderProvider declarationFinderProvider) + : base(declarationFinderProvider) { } + + protected override IEnumerable GetInvalidAnnotations( + IEnumerable annotations, + IEnumerable userDeclarations, + IEnumerable identifierReferences) + { + foreach (var pta in annotations) + { + var annotation = pta.Annotation; + var componentType = pta.QualifiedSelection.QualifiedName.ComponentType; + if (annotation.RequiredComponentType.HasValue && annotation.RequiredComponentType != componentType + || annotation.IncompatibleComponentTypes.Contains(componentType)) + { + yield return pta; + } + } + + yield break; + } + + protected override string ResultDescription(IParseTreeAnnotation pta) + { + if (pta.Annotation.RequiredComponentType.HasValue) + { + return string.Format(InspectionResults.ResourceManager.GetString($"{nameof(InvalidAnnotationInspection)}_NotInRequiredComponentType", CultureInfo.CurrentUICulture), + pta.Annotation.Name, // annotation... + pta.QualifiedSelection.QualifiedName.ComponentType, // is used in a... + pta.Annotation.RequiredComponentType); // but is only valid in a... + } + else + { + return string.Format(InspectionResults.ResourceManager.GetString($"{nameof(InvalidAnnotationInspection)}_IncompatibleComponentType", CultureInfo.CurrentUICulture), + pta.Annotation.Name, // annotation... + pta.QualifiedSelection.QualifiedName.ComponentType); // cannot be used in a... + } + } + } +} \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ApplicationWorksheetFunctionInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ApplicationWorksheetFunctionInspection.cs index e0f56beaf8..0cecc1f05c 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ApplicationWorksheetFunctionInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ApplicationWorksheetFunctionInspection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Attributes; using Rubberduck.InternalApi.Extensions; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -60,7 +61,7 @@ internal class ApplicationWorksheetFunctionInspection : IdentifierReferenceInspe { public ApplicationWorksheetFunctionInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override IEnumerable ObjectionableDeclarations(DeclarationFinder finder) { @@ -91,7 +92,7 @@ protected override IEnumerable ObjectionableDeclarations(Declaratio protected override string ResultDescription(IdentifierReference reference) { - return string.Format(InspectionResults.ApplicationWorksheetFunctionInspection, reference.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ApplicationWorksheetFunctionInspection), CultureInfo.CurrentUICulture), reference.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ArgumentWithIncompatibleObjectTypeInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ArgumentWithIncompatibleObjectTypeInspection.cs index 807e65598e..9d4dd00abb 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ArgumentWithIncompatibleObjectTypeInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ArgumentWithIncompatibleObjectTypeInspection.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.TypeResolvers; @@ -8,6 +6,9 @@ using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -125,7 +126,7 @@ private string SetTypeNameOfExpression(VBAParser.ExpressionContext expression, Q return _setTypeResolver.SetTypeName(expression, containingModule); } - private bool ArgumentPossiblyLegal(Declaration parameterDeclaration , string assignedTypeName) + private bool ArgumentPossiblyLegal(Declaration parameterDeclaration, string assignedTypeName) { return assignedTypeName == parameterDeclaration.FullAsTypeName || assignedTypeName == Tokens.Variant @@ -163,7 +164,7 @@ protected override string ResultDescription(IdentifierReference reference, strin var parameterName = reference.Declaration.IdentifierName; var parameterTypeName = reference.Declaration.FullAsTypeName; var argumentExpression = reference.Context.GetText(); - return string.Format(InspectionResults.SetAssignmentWithIncompatibleObjectTypeInspection, parameterName, parameterTypeName, argumentExpression, argumentTypeName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(SetAssignmentWithIncompatibleObjectTypeInspection), CultureInfo.CurrentUICulture), parameterName, parameterTypeName, argumentExpression, argumentTypeName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/AssignedByValParameterInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/AssignedByValParameterInspection.cs index 3d350c7d6e..04d1533379 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/AssignedByValParameterInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/AssignedByValParameterInspection.cs @@ -1,9 +1,10 @@ -using System.Linq; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -41,19 +42,19 @@ internal sealed class AssignedByValParameterInspection : DeclarationInspectionBa { public AssignedByValParameterInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Parameter) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { - return declaration is ParameterDeclaration parameter - && !parameter.IsByRef + return declaration is ParameterDeclaration parameter + && !parameter.IsByRef && parameter.References .Any(reference => reference.IsAssignment); } protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.AssignedByValParameterInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(AssignedByValParameterInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/AssignmentNotUsedInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/AssignmentNotUsedInspection.cs index e487e4a47d..51c9455a21 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/AssignmentNotUsedInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/AssignmentNotUsedInspection.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Linq; using Antlr4.Runtime; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Extensions; @@ -12,6 +10,8 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.VBEditor; +using System.Collections.Generic; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -187,7 +187,7 @@ private static bool IsPotentiallyUsedViaJump(IdentifierReference resultCandidate || JumpStmtPotentiallyUsesVariable(resultCandidate, labelIdLineNumberPairs); } - private static bool JumpStmtPotentiallyUsesVariable(IdentifierReference resultCandidate, Dictionary labelIdLineNumberPairs) where T: ParserRuleContext + private static bool JumpStmtPotentiallyUsesVariable(IdentifierReference resultCandidate, Dictionary labelIdLineNumberPairs) where T : ParserRuleContext { if (TryGetRelevantJumpContext(resultCandidate, out var jumpStmt)) { diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/AttributeValueOutOfSyncInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/AttributeValueOutOfSyncInspection.cs index 836b21946b..a6ecadf53f 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/AttributeValueOutOfSyncInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/AttributeValueOutOfSyncInspection.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Attributes; using Rubberduck.Parsing.Annotations; using Rubberduck.Parsing.Symbols; @@ -8,6 +6,9 @@ using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor.SafeComWrappers; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -45,7 +46,7 @@ internal sealed class AttributeValueOutOfSyncInspection : DeclarationInspectionM { public AttributeValueOutOfSyncInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override IEnumerable<(IParseTreeAnnotation Annotation, string AttributeName, IReadOnlyList AttributeValues)> ResultProperties(Declaration declaration, DeclarationFinder finder) { @@ -61,7 +62,7 @@ public AttributeValueOutOfSyncInspection(IDeclarationFinderProvider declarationF { foreach (var pta in declaration.Annotations) { - if (!(pta.Annotation is IAttributeAnnotation annotation) + if (!(pta.Annotation is IAttributeAnnotation annotation) || !HasDifferingAttributeValues(declaration, pta, out var attributeValues)) { continue; @@ -101,7 +102,7 @@ protected override string ResultDescription(Declaration declaration, (IParseTree { var (pta, attributeName, attributeValues) = properties; var annotationName = pta.Annotation.Name; - return string.Format(InspectionResults.AttributeValueOutOfSyncInspection, + return string.Format(InspectionResults.ResourceManager.GetString(nameof(AttributeValueOutOfSyncInspection), CultureInfo.CurrentUICulture), attributeName, string.Join(", ", attributeValues), annotationName); diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/BooleanAssignedInIfElseInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/BooleanAssignedInIfElseInspection.cs index 9ce326bad9..49cb0bdd91 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/BooleanAssignedInIfElseInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/BooleanAssignedInIfElseInspection.cs @@ -1,9 +1,10 @@ -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing; using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -46,7 +47,7 @@ public BooleanAssignedInIfElseInspection(IDeclarationFinderProvider declarationF { ContextListener = new BooleanAssignedInIfElseListener(); } - + protected override IInspectionListener ContextListener { get; } protected override string ResultDescription(QualifiedContext context) @@ -57,9 +58,7 @@ protected override string ResultDescription(QualifiedContext diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ConstantNotUsedInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ConstantNotUsedInspection.cs index 2c8508de95..10292f0d8c 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ConstantNotUsedInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ConstantNotUsedInspection.cs @@ -1,10 +1,11 @@ -using System.Linq; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Extensions; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -40,11 +41,11 @@ internal sealed class ConstantNotUsedInspection : DeclarationInspectionBase { public ConstantNotUsedInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Constant) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { - return declaration?.Context != null + return declaration?.Context != null && !declaration.References.Any() && !IsPublicInExposedClass(declaration); } @@ -70,7 +71,7 @@ protected override string ResultDescription(Declaration declaration) var declarationType = declaration.DeclarationType.ToLocalizedString(); var declarationName = declaration.IdentifierName; return string.Format( - InspectionResults.IdentifierNotUsedInspection, + InspectionResults.ResourceManager.GetString(nameof(InspectionResults.IdentifierNotUsedInspection), CultureInfo.CurrentUICulture), declarationType, declarationName); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/DefTypeStatementInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/DefTypeStatementInspection.cs index 3d141b32f6..6b697912cc 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/DefTypeStatementInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/DefTypeStatementInspection.cs @@ -1,10 +1,11 @@ -using System.Collections.Generic; -using Antlr4.Runtime.Misc; +using Antlr4.Runtime.Misc; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing; using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Collections.Generic; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -34,7 +35,7 @@ public DefTypeStatementInspection(IDeclarationFinderProvider declarationFinderPr { ContextListener = new DefTypeStatementInspectionListener(); } - + protected override IInspectionListener ContextListener { get; } protected override string ResultDescription(QualifiedContext context) @@ -43,7 +44,7 @@ protected override string ResultDescription(QualifiedContext internal sealed class DuplicatedAnnotationInspection : DeclarationInspectionMultiResultBase { - public DuplicatedAnnotationInspection(IDeclarationFinderProvider declarationFinderProvider) + public DuplicatedAnnotationInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override IEnumerable ResultProperties(Declaration declaration, DeclarationFinder finder) { @@ -54,7 +55,7 @@ protected override IEnumerable ResultProperties(Declaration declara protected override string ResultDescription(Declaration declaration, IAnnotation annotation) { - return string.Format(InspectionResults.DuplicatedAnnotationInspection, annotation); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(DuplicatedAnnotationInspection), CultureInfo.CurrentUICulture), annotation); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyCaseBlockInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyCaseBlockInspection.cs index c37d80c2ef..44032a4cee 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyCaseBlockInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyCaseBlockInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -52,7 +53,7 @@ public EmptyCaseBlockInspection(IDeclarationFinderProvider declarationFinderProv protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.EmptyCaseBlockInspection; + return InspectionResults.ResourceManager.GetString(nameof(EmptyCaseBlockInspection), CultureInfo.CurrentUICulture); } private class EmptyCaseBlockListener : EmptyBlockInspectionListenerBase diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyDoWhileBlockInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyDoWhileBlockInspection.cs index b012c09cbe..3268e6e605 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyDoWhileBlockInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyDoWhileBlockInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -47,7 +48,7 @@ public EmptyDoWhileBlockInspection(IDeclarationFinderProvider declarationFinderP protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.EmptyDoWhileBlockInspection; + return InspectionResults.ResourceManager.GetString(nameof(EmptyDoWhileBlockInspection), CultureInfo.CurrentUICulture); } private class EmptyDoWhileBlockListener : EmptyBlockInspectionListenerBase diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyElseBlockInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyElseBlockInspection.cs index e981a13f56..6f73663c1f 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyElseBlockInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyElseBlockInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -49,7 +50,7 @@ public EmptyElseBlockInspection(IDeclarationFinderProvider declarationFinderProv protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.EmptyElseBlockInspection; + return InspectionResults.ResourceManager.GetString(nameof(EmptyElseBlockInspection), CultureInfo.CurrentUICulture); } private class EmptyElseBlockListener : EmptyBlockInspectionListenerBase diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyForEachBlockInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyForEachBlockInspection.cs index f649339fa1..2d8773f8dd 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyForEachBlockInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyForEachBlockInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -49,7 +50,7 @@ public EmptyForEachBlockInspection(IDeclarationFinderProvider declarationFinderP protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.EmptyForEachBlockInspection; + return InspectionResults.ResourceManager.GetString(nameof(EmptyForEachBlockInspection), CultureInfo.CurrentUICulture); } private class EmptyForEachBlockListener : EmptyBlockInspectionListenerBase diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyForLoopBlockInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyForLoopBlockInspection.cs index 3c90df6791..d63c20b4cb 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyForLoopBlockInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyForLoopBlockInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -49,7 +50,7 @@ public EmptyForLoopBlockInspection(IDeclarationFinderProvider declarationFinderP protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.EmptyForLoopBlockInspection; + return InspectionResults.ResourceManager.GetString(nameof(EmptyForLoopBlockInspection), CultureInfo.CurrentUICulture); } private class EmptyForLoopBlockListener : EmptyBlockInspectionListenerBase diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyIfBlockInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyIfBlockInspection.cs index c0c16f3fd9..8bc2d1855d 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyIfBlockInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyIfBlockInspection.cs @@ -5,6 +5,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -47,7 +48,7 @@ public EmptyIfBlockInspection(IDeclarationFinderProvider declarationFinderProvid protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.EmptyIfBlockInspection; + return InspectionResults.ResourceManager.GetString(nameof(EmptyIfBlockInspection), CultureInfo.CurrentUICulture); } protected override IInspectionListener ContextListener { get; } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyMethodInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyMethodInspection.cs index baaf3d6688..d93060481c 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyMethodInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyMethodInspection.cs @@ -1,10 +1,11 @@ using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Extensions; +using Rubberduck.Parsing; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; -using Rubberduck.Parsing; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -37,12 +38,12 @@ internal sealed class EmptyMethodInspection : DeclarationInspectionBase { public EmptyMethodInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Member) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { - return declaration is ModuleBodyElementDeclaration member - && !member.IsInterfaceMember + return declaration is ModuleBodyElementDeclaration member + && !member.IsInterfaceMember && !member.Block.ContainsExecutableStatements(); } @@ -52,7 +53,7 @@ protected override string ResultDescription(Declaration member) var declarationType = member.DeclarationType.ToLocalizedString(); return string.Format( - InspectionResults.EmptyMethodInspection, + InspectionResults.ResourceManager.GetString(nameof(EmptyMethodInspection), CultureInfo.CurrentUICulture), declarationType, identifierName); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyModuleInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyModuleInspection.cs index fc99597114..5c87dd8473 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyModuleInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyModuleInspection.cs @@ -1,11 +1,12 @@ -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Parsing.VBA.Parsing; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -21,7 +22,7 @@ internal sealed class EmptyModuleInspection : DeclarationInspectionBase private readonly IParseTreeProvider _parseTreeProvider; public EmptyModuleInspection(IDeclarationFinderProvider declarationFinderProvider, IParseTreeProvider parseTreeProvider) - : base(declarationFinderProvider, new []{DeclarationType.Module}, new []{DeclarationType.Document}) + : base(declarationFinderProvider, new[] { DeclarationType.Module }, new[] { DeclarationType.Document }) { _emptyModuleVisitor = new EmptyModuleVisitor(); _parseTreeProvider = parseTreeProvider; @@ -37,7 +38,7 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.EmptyModuleInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(EmptyModuleInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyStringLiteralInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyStringLiteralInspection.cs index 98868b1c06..5fbae40e7c 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyStringLiteralInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyStringLiteralInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -10,7 +11,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete /// Flags uses of an empty string literal (""). /// /// - /// Treating an empty string literal as equal to the 'vbNullString' constant + /// In the context of a unit test, treating an empty string literal as equal to the 'vbNullString' constant /// requires using the PermissiveAssertClass. The default AssertClass is more strict about data types, and tells them apart. /// /// @@ -53,7 +54,7 @@ public EmptyStringLiteralInspection(IDeclarationFinderProvider declarationFinder protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.EmptyStringLiteralInspection; + return InspectionResults.ResourceManager.GetString(nameof(EmptyStringLiteralInspection), CultureInfo.CurrentUICulture); } private class EmptyStringLiteralListener : InspectionListenerBase diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyWhileWendBlockInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyWhileWendBlockInspection.cs index 8952b539db..41f293e5b0 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyWhileWendBlockInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyWhileWendBlockInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -47,7 +48,7 @@ public EmptyWhileWendBlockInspection(IDeclarationFinderProvider declarationFinde protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.EmptyWhileWendBlockInspection; + return InspectionResults.ResourceManager.GetString(nameof(EmptyWhileWendBlockInspection), CultureInfo.CurrentUICulture); } private class EmptyWhileWendBlockListener : EmptyBlockInspectionListenerBase diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/EncapsulatePublicFieldInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/EncapsulatePublicFieldInspection.cs index 125c8de40f..6d3633c682 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/EncapsulatePublicFieldInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/EncapsulatePublicFieldInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -35,7 +36,7 @@ internal sealed class EncapsulatePublicFieldInspection : DeclarationInspectionBa { public EncapsulatePublicFieldInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Variable) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -47,7 +48,7 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.EncapsulatePublicFieldInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(EncapsulatePublicFieldInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ExcelMemberMayReturnNothingInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ExcelMemberMayReturnNothingInspection.cs index 36558288fd..dca278261f 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ExcelMemberMayReturnNothingInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ExcelMemberMayReturnNothingInspection.cs @@ -1,11 +1,12 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Attributes; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -47,7 +48,7 @@ internal class ExcelMemberMayReturnNothingInspection : MemberAccessMayReturnNoth { public ExcelMemberMayReturnNothingInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } private static readonly List<(string className, string memberName)> ExcelMembers = new List<(string className, string memberName)> { @@ -77,6 +78,6 @@ public override IEnumerable MembersUnderTest(DeclarationFinder find .Where(member => ExcelMembers.Contains((member.ComponentName, member.IdentifierName))); } - public override string ResultTemplate => InspectionResults.ExcelMemberMayReturnNothingInspection; + public override string ResultTemplate => InspectionResults.ResourceManager.GetString(nameof(ExcelMemberMayReturnNothingInspection), CultureInfo.CurrentUICulture); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ExcelUdfNameIsValidCellReferenceInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ExcelUdfNameIsValidCellReferenceInspection.cs index 3d2ecca94b..a0a3edb9ac 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ExcelUdfNameIsValidCellReferenceInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ExcelUdfNameIsValidCellReferenceInspection.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Attributes; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; @@ -10,6 +6,11 @@ using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; using Rubberduck.VBEditor.SafeComWrappers; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text.RegularExpressions; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -41,8 +42,8 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete internal class ExcelUdfNameIsValidCellReferenceInspection : DeclarationInspectionUsingGlobalInformationBase { public ExcelUdfNameIsValidCellReferenceInspection(IDeclarationFinderProvider declarationFinderProvider) - : base(declarationFinderProvider, new []{DeclarationType.Function}, new []{DeclarationType.PropertyGet, DeclarationType.LibraryFunction}) - {} + : base(declarationFinderProvider, new[] { DeclarationType.Function }, new[] { DeclarationType.PropertyGet, DeclarationType.LibraryFunction }) + { } protected override IEnumerable DoGetInspectionResults(QualifiedModuleName module, DeclarationFinder finder, bool excelIsReferenced) { @@ -96,7 +97,7 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.ExcelUdfNameIsValidCellReferenceInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ExcelUdfNameIsValidCellReferenceInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/FunctionReturnValueAlwaysDiscardedInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/FunctionReturnValueAlwaysDiscardedInspection.cs index 46fc854b83..79b98de9e1 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/FunctionReturnValueAlwaysDiscardedInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/FunctionReturnValueAlwaysDiscardedInspection.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using Antlr4.Runtime; +using Antlr4.Runtime; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.InternalApi.Extensions; using Rubberduck.Parsing; @@ -9,6 +7,9 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -55,7 +56,7 @@ internal sealed class FunctionReturnValueAlwaysDiscardedInspection : Declaration { public FunctionReturnValueAlwaysDiscardedInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Function) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -168,7 +169,7 @@ private static bool IsCalledAsProcedure(ParserRuleContext context) protected override string ResultDescription(Declaration declaration) { var functionName = declaration.QualifiedName.ToString(); - return string.Format(InspectionResults.FunctionReturnValueAlwaysDiscardedInspection, functionName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(FunctionReturnValueAlwaysDiscardedInspection), CultureInfo.CurrentUICulture), functionName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/FunctionReturnValueDiscardedInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/FunctionReturnValueDiscardedInspection.cs index 2ac32ca6b4..4ba1cd7923 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/FunctionReturnValueDiscardedInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/FunctionReturnValueDiscardedInspection.cs @@ -6,6 +6,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -91,7 +92,7 @@ private static bool IsCalledAsProcedure(ParserRuleContext context) //This case is necessary if the context is itself the unrestricted identifier in a member access. var furtherMemberAccessParent = memberAccessParent.GetAncestor(); if (furtherMemberAccessParent != null) - { + { return false; } } @@ -104,7 +105,7 @@ private static bool IsCalledAsProcedure(ParserRuleContext context) protected override string ResultDescription(IdentifierReference reference) { var functionName = reference.Declaration.QualifiedName.ToString(); - return string.Format(InspectionResults.FunctionReturnValueDiscardedInspection, functionName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(FunctionReturnValueDiscardedInspection), CultureInfo.CurrentUICulture), functionName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/HostSpecificExpressionInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/HostSpecificExpressionInspection.cs index 01dea2befd..06f84d06b1 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/HostSpecificExpressionInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/HostSpecificExpressionInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -35,7 +36,7 @@ internal sealed class HostSpecificExpressionInspection : DeclarationInspectionBa { public HostSpecificExpressionInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.BracketedExpression) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -44,7 +45,7 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.HostSpecificExpressionInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(HostSpecificExpressionInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/HungarianNotationInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/HungarianNotationInspection.cs index fb699e51a5..8a1a783808 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/HungarianNotationInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/HungarianNotationInspection.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Extensions; using Rubberduck.CodeAnalysis.Settings; using Rubberduck.Common; @@ -8,6 +6,9 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.SettingsProvider; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -49,7 +50,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete /// internal sealed class HungarianNotationInspection : DeclarationInspectionUsingGlobalInformationBase> { - private static readonly DeclarationType[] TargetDeclarationTypes = new [] + private static readonly DeclarationType[] TargetDeclarationTypes = new[] { DeclarationType.Parameter, DeclarationType.Constant, @@ -65,7 +66,7 @@ internal sealed class HungarianNotationInspection : DeclarationInspectionUsingGl DeclarationType.Variable }; - private static readonly DeclarationType[] IgnoredProcedureTypes = new [] + private static readonly DeclarationType[] IgnoredProcedureTypes = new[] { DeclarationType.LibraryFunction, DeclarationType.LibraryProcedure @@ -79,19 +80,22 @@ public HungarianNotationInspection(IDeclarationFinderProvider declarationFinderP _settings = settings; } + private CodeInspectionSettings _configuration; + protected override List GlobalInformation(DeclarationFinder finder) { - var settings = _settings.Read(); - return settings.WhitelistedIdentifiers + _configuration = _settings.Read(); + return _configuration.WhitelistedIdentifiers .Select(s => s.Identifier) .ToList(); } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder, List whitelistedNames) { - return !whitelistedNames.Contains(declaration.IdentifierName) - && !IgnoredProcedureTypes.Contains(declaration.ParentDeclaration.DeclarationType) - && declaration.IdentifierName.TryMatchHungarianNotationCriteria(out _); + return (_configuration.IgnoreFormControlsHungarianNotation && declaration.DeclarationType == DeclarationType.Control) || + (!whitelistedNames.Contains(declaration.IdentifierName) + && !IgnoredProcedureTypes.Contains(declaration.ParentDeclaration.DeclarationType) + && declaration.IdentifierName.TryMatchHungarianNotationCriteria(out _)); } protected override string ResultDescription(Declaration declaration) @@ -99,7 +103,7 @@ protected override string ResultDescription(Declaration declaration) var declarationType = declaration.DeclarationType.ToLocalizedString(); var declarationName = declaration.IdentifierName; return string.Format( - Resources.Inspections.InspectionResults.IdentifierNameInspection, + Resources.Inspections.InspectionResults.ResourceManager.GetString(nameof(Resources.Inspections.InspectionResults.IdentifierNameInspection), CultureInfo.CurrentUICulture), declarationType, declarationName); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/IIfSideEffectInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/IIfSideEffectInspection.cs index 8c0908c631..153c892475 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/IIfSideEffectInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/IIfSideEffectInspection.cs @@ -8,6 +8,7 @@ using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; using System.Collections.Generic; +using System.Globalization; using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete @@ -119,7 +120,7 @@ public IIfSideEffectInspection(IDeclarationFinderProvider declarationFinderProvi protected override IEnumerable DoGetInspectionResults(QualifiedModuleName module, DeclarationFinder finder) { var iifReferences = _declarationFinderProvider.DeclarationFinder.BuiltInDeclarations(DeclarationType.Function) - .SingleOrDefault(d => string.Compare( d.IdentifierName, "IIf", System.StringComparison.InvariantCultureIgnoreCase) == 0) + .SingleOrDefault(d => string.Compare(d.IdentifierName, "IIf", System.StringComparison.InvariantCultureIgnoreCase) == 0) .References.Where(rf => rf.QualifiedModuleName == module); if (!iifReferences.Any()) @@ -178,7 +179,7 @@ private static VBAParser.ArgumentContext ExtractArgumentContext(IEnumerable ctxt.children.OfType()) //'ToUpperInvariant' in case the user has (at some point) entered a declaration that re-cased any IIf parameter names .ToDictionary(ch => ch.GetText().ToUpperInvariant()); - + if (unrestrictedIDContextsByName.TryGetValue(partParam.Identifier.ToUpperInvariant(), out var expressionUnrestrictedIDContext)) { return expressionUnrestrictedIDContext.Parent.Parent as VBAParser.ArgumentContext; @@ -190,7 +191,7 @@ private static VBAParser.ArgumentContext ExtractArgumentContext(IEnumerable @@ -199,7 +200,7 @@ protected override string ResultDescription(IdentifierReference reference) /// private static Dictionary CreateLibraryFunctionIdentifiersToIgnore() { - return LoadLibraryFunctionIdentifiersToIgnore( new Dictionary(), + return LoadLibraryFunctionIdentifiersToIgnore(new Dictionary(), //MS-VBAL 6.1.2.3 Conversion Module /*Excluded for potential of raising errors: * "CBool", "CByte", "CCur", "CDate", "CVDate", "CDbl", "CDec", "CInt", "CLng", "CLngLng", "ClngPtr", @@ -224,7 +225,7 @@ private static Dictionary CreateLibraryFunctionIdentifiersToIgno */ //MS-VBAL 6.1.2.7 Information - "IMEStatus", "IsArray", "IsDate", "IsEmpty", "IsError", "IsMissing", "IsNull", "IsNumeric", "IsObject", + "IMEStatus", "IsArray", "IsDate", "IsEmpty", "IsError", "IsMissing", "IsNull", "IsNumeric", "IsObject", "QBColor", "RGB", "TypeName", "VarType", //MS-VBAL 6.1.2.8 Interaction @@ -248,7 +249,7 @@ private static Dictionary CreateLibraryFunctionIdentifiersToIgno * "Right$", "RightB$", "Asc", "AscW", "AscB", "Chr", "Chr$", "ChB", "ChB$", "ChrW", "ChrW$", "Filter", * "MonthName", "WeekdayName", "Space", "Space$", "Split","StrConv", "String", "String$" */ - "LCase", "LCase$", "Len", "LenB", "Trim", "LTrim", "RTrim", "Trim$", "LTrim$", "RTrim$", "StrComp", + "LCase", "LCase$", "Len", "LenB", "Trim", "LTrim", "RTrim", "Trim$", "LTrim$", "RTrim$", "StrComp", "StrReverse", "UCase", "UCase$" ); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplementedInterfaceMemberInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplementedInterfaceMemberInspection.cs index 0ceadcaaf0..2081790bb6 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplementedInterfaceMemberInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplementedInterfaceMemberInspection.cs @@ -1,5 +1,4 @@ -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Common; using Rubberduck.Parsing; using Rubberduck.Parsing.Annotations.Concrete; @@ -7,6 +6,8 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -44,7 +45,7 @@ internal sealed class ImplementedInterfaceMemberInspection : DeclarationInspecti { public ImplementedInterfaceMemberInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.ClassModule) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -74,12 +75,12 @@ protected override string ResultDescription(Declaration declaration) { var qualifiedName = declaration.QualifiedModuleName.ToString(); var declarationType = CodeAnalysisUI.ResourceManager - .GetString("DeclarationType_" + declaration.DeclarationType) + .GetString("DeclarationType_" + declaration.DeclarationType, CultureInfo.CurrentUICulture) .Capitalize(); var identifierName = declaration.IdentifierName; return string.Format( - InspectionResults.ImplementedInterfaceMemberInspection, + InspectionResults.ResourceManager.GetString(nameof(ImplementedInterfaceMemberInspection), CultureInfo.CurrentUICulture), qualifiedName, declarationType, identifierName); diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitActiveSheetReferenceInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitActiveSheetReferenceInspection.cs index f7369c6930..6a0f3f8ac6 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitActiveSheetReferenceInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitActiveSheetReferenceInspection.cs @@ -1,10 +1,11 @@ -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Attributes; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -45,7 +46,7 @@ internal sealed class ImplicitActiveSheetReferenceInspection : ImplicitSheetRefe { public ImplicitActiveSheetReferenceInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override string[] GlobalObjectClassNames => new[] { "Global", "_Global", }; @@ -58,7 +59,7 @@ protected override bool IsResultReference(IdentifierReference reference, Declara protected override string ResultDescription(IdentifierReference reference) { return string.Format( - InspectionResults.ImplicitActiveSheetReferenceInspection, + InspectionResults.ResourceManager.GetString(nameof(ImplicitActiveSheetReferenceInspection), CultureInfo.CurrentUICulture), reference.Declaration.IdentifierName); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitActiveWorkbookReferenceInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitActiveWorkbookReferenceInspection.cs index 61279d1e08..f4a3e28318 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitActiveWorkbookReferenceInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitActiveWorkbookReferenceInspection.cs @@ -1,10 +1,11 @@ -using System.Linq; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Attributes; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -67,8 +68,8 @@ protected override bool IsResultReference(IdentifierReference reference, Declara var excelProjectId = Excel(finder).ProjectId; var applicationCandidates = finder.MatchName("Application") - .Where(m => m.ProjectId.Equals(excelProjectId) - && ( m.DeclarationType == DeclarationType.PropertyGet + .Where(m => m.ProjectId.Equals(excelProjectId) + && (m.DeclarationType == DeclarationType.PropertyGet || m.DeclarationType == DeclarationType.ClassModule)); var qualifyingDeclaration = reference.QualifyingReference.Declaration; @@ -80,7 +81,7 @@ protected override bool IsResultReference(IdentifierReference reference, Declara protected override string ResultDescription(IdentifierReference reference) { var referenceText = reference.Context.GetText(); - return string.Format(InspectionResults.ImplicitActiveWorkbookReferenceInspection, referenceText); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ImplicitActiveWorkbookReferenceInspection), CultureInfo.CurrentUICulture), referenceText); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitByRefModifierInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitByRefModifierInspection.cs index 9c968f697a..c3433b553d 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitByRefModifierInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitByRefModifierInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete @@ -49,7 +50,7 @@ internal sealed class ImplicitByRefModifierInspection : DeclarationInspectionBas { public ImplicitByRefModifierInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Parameter) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -70,14 +71,14 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration private static bool IsPropertyMutatorRHSParameter(ModuleBodyElementDeclaration enclosingMethod, ParameterDeclaration implicitByRefParameter) { return (enclosingMethod.DeclarationType.HasFlag(DeclarationType.PropertyLet) - || enclosingMethod.DeclarationType.HasFlag(DeclarationType.PropertySet)) + || enclosingMethod.DeclarationType.HasFlag(DeclarationType.PropertySet)) && enclosingMethod.Parameters.Last().Equals(implicitByRefParameter); } protected override string ResultDescription(Declaration declaration) { return string.Format( - InspectionResults.ImplicitByRefModifierInspection, + InspectionResults.ResourceManager.GetString(nameof(ImplicitByRefModifierInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorkbookReferenceInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorkbookReferenceInspection.cs index 0c705b86de..5212c0b9ad 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorkbookReferenceInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorkbookReferenceInspection.cs @@ -1,11 +1,12 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Attributes; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -67,7 +68,7 @@ protected override string ResultDescription(IdentifierReference reference) { var referenceText = reference.Context.GetText(); return string.Format( - InspectionResults.ImplicitContainingWorkbookReferenceInspection, + InspectionResults.ResourceManager.GetString(nameof(ImplicitContainingWorkbookReferenceInspection), CultureInfo.CurrentUICulture), referenceText); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorksheetReferenceInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorksheetReferenceInspection.cs index 0ce1d79361..c902e9421c 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorksheetReferenceInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitContainingWorksheetReferenceInspection.cs @@ -1,10 +1,11 @@ -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Attributes; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -41,7 +42,7 @@ internal sealed class ImplicitContainingWorksheetReferenceInspection : ImplicitS { public ImplicitContainingWorksheetReferenceInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override bool IsResultReference(IdentifierReference reference, DeclarationFinder finder) { @@ -53,7 +54,7 @@ protected override bool IsResultReference(IdentifierReference reference, Declara protected override string ResultDescription(IdentifierReference reference) { return string.Format( - InspectionResults.ImplicitContainingWorksheetReferenceInspection, + InspectionResults.ResourceManager.GetString(nameof(ImplicitContainingWorksheetReferenceInspection), CultureInfo.CurrentUICulture), reference.Declaration.IdentifierName); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitDefaultMemberAccessInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitDefaultMemberAccessInspection.cs index e59feed6d0..e502ac69da 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitDefaultMemberAccessInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitDefaultMemberAccessInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -75,7 +76,7 @@ protected override string ResultDescription(IdentifierReference reference) { var expression = reference.IdentifierName; var defaultMember = reference.Declaration.QualifiedName.ToString(); - return string.Format(InspectionResults.ImplicitDefaultMemberAccessInspection, expression, defaultMember); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ImplicitDefaultMemberAccessInspection), CultureInfo.CurrentUICulture), expression, defaultMember); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitPublicMemberInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitPublicMemberInspection.cs index 6bee81f94c..304ceaf678 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitPublicMemberInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitPublicMemberInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -36,7 +37,7 @@ internal sealed class ImplicitPublicMemberInspection : DeclarationInspectionBase public ImplicitPublicMemberInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, ProcedureTypes) { } - private static readonly DeclarationType[] ProcedureTypes = + private static readonly DeclarationType[] ProcedureTypes = { DeclarationType.Function, DeclarationType.Procedure, @@ -54,7 +55,7 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.ImplicitPublicMemberInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ImplicitPublicMemberInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitRecursiveDefaultMemberAccessInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitRecursiveDefaultMemberAccessInspection.cs index f7e76471d1..f4536c1ef1 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitRecursiveDefaultMemberAccessInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitRecursiveDefaultMemberAccessInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -87,7 +88,7 @@ protected override string ResultDescription(IdentifierReference reference) { var expression = reference.IdentifierName; var defaultMember = reference.Declaration.QualifiedName.ToString(); - return string.Format(InspectionResults.ImplicitRecursiveDefaultMemberAccessInspection, expression, defaultMember); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ImplicitRecursiveDefaultMemberAccessInspection), CultureInfo.CurrentUICulture), expression, defaultMember); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitUnboundDefaultMemberAccessInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitUnboundDefaultMemberAccessInspection.cs index 4d5fae59a4..c037f16694 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitUnboundDefaultMemberAccessInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitUnboundDefaultMemberAccessInspection.cs @@ -1,11 +1,12 @@ -using System.Collections.Generic; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Extensions; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; +using System.Collections.Generic; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -81,7 +82,7 @@ protected override bool IsResultReference(IdentifierReference reference, Declara protected override string ResultDescription(IdentifierReference reference) { var expression = reference.IdentifierName; - return string.Format(InspectionResults.ImplicitUnboundDefaultMemberAccessInspection, expression); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ImplicitUnboundDefaultMemberAccessInspection), CultureInfo.CurrentUICulture), expression); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitVariantReturnTypeInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitVariantReturnTypeInspection.cs index 1130c7d5c0..797258908c 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitVariantReturnTypeInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitVariantReturnTypeInspection.cs @@ -2,6 +2,7 @@ using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -33,11 +34,11 @@ internal sealed class ImplicitVariantReturnTypeInspection : ImplicitTypeInspecti { public ImplicitVariantReturnTypeInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Function) - {} + { } protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.ImplicitVariantReturnTypeInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ImplicitVariantReturnTypeInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitlyTypedConstInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitlyTypedConstInspection.cs index 5696f45c33..5cb307dd95 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitlyTypedConstInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitlyTypedConstInspection.cs @@ -2,6 +2,7 @@ using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -36,11 +37,11 @@ internal sealed class ImplicitlyTypedConstInspection : ImplicitTypeInspectionBas { public ImplicitlyTypedConstInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Constant) - {} + { } protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.ImplicitlyTypedConstInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ImplicitlyTypedConstInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/InconsistentArrayBaseInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/InconsistentArrayBaseInspection.cs new file mode 100644 index 0000000000..ffb3392a45 --- /dev/null +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/InconsistentArrayBaseInspection.cs @@ -0,0 +1,83 @@ +using Rubberduck.CodeAnalysis.Inspections.Abstract; +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 System.Globalization; + +namespace Rubberduck.CodeAnalysis.Inspections.Concrete +{ + /// + /// Warns about inconsistent implicit lower bounds of VBA.Array arrays when 'Option Base 1' is specified. + /// + /// + /// The base of an array obtained from a qualified 'VBA.Array' function call is always zero, regardless of any 'Option Base' setting. + /// + /// + /// + /// + /// + /// + /// + /// + /// + internal class InconsistentArrayBaseInspection : IdentifierReferenceInspectionBase + { + public InconsistentArrayBaseInspection(IDeclarationFinderProvider declarationFinderProvider) + : base(declarationFinderProvider) + { + } + + protected override bool IsResultReference(IdentifierReference reference, DeclarationFinder finder) + { + var hasOptionBase1 = reference.Context + .GetAncestor() + .GetDescendent()? + .numberLiteral()?.GetText() == "1"; + + if (hasOptionBase1 && reference.Declaration.ProjectName == "VBA" && reference.Declaration.IdentifierName == "Array") + { + if (reference.QualifyingReference?.Declaration.IdentifierName == "VBA") + { + return true; + } + } + + return false; + } + + protected override string ResultDescription(IdentifierReference reference) + { + // reference.Declaration is the VBA.Array function + // we could inspect the context to find a possible LHS variable being assigned, but VBA.Array could also be an argument + // so it's not a given that there's a relevant identifier to call out, so the resource string does not have any placeholders. + return InspectionResults.ResourceManager.GetString(nameof(InconsistentArrayBaseInspection), CultureInfo.CurrentUICulture); + } + } +} diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/InconsistentParamArrayBaseInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/InconsistentParamArrayBaseInspection.cs new file mode 100644 index 0000000000..807fafb4bf --- /dev/null +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/InconsistentParamArrayBaseInspection.cs @@ -0,0 +1,87 @@ +using Rubberduck.CodeAnalysis.Inspections.Abstract; +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 System.Globalization; + +namespace Rubberduck.CodeAnalysis.Inspections.Concrete +{ + + /// + /// Warns about inconsistent implicit lower bounds of ParamArray arrays when 'Option Base 1' is specified. + /// + /// + /// The base of a ParamArray is always zero, regardless of any 'Option Base' setting. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + internal sealed class InconsistentParamArrayBaseInspection : DeclarationInspectionBase + { + public InconsistentParamArrayBaseInspection(IDeclarationFinderProvider declarationFinderProvider) + : base(declarationFinderProvider) + { + } + + protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) + { + var hasOptionBase1 = declaration.Context + .GetAncestor() + .GetDescendent()? + .numberLiteral()?.GetText() == "1"; + + + if (hasOptionBase1 && declaration is ParameterDeclaration parameter) + { + return parameter.IsParamArray; + } + + return false; + } + + protected override string ResultDescription(Declaration declaration) + { + // declaration is the ParamArray parameter + return string.Format(InspectionResults.ResourceManager.GetString(nameof(InconsistentParamArrayBaseInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); + } + } +} diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedDefaultMemberAccessInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedDefaultMemberAccessInspection.cs index 096e98853b..57f8ccf842 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedDefaultMemberAccessInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedDefaultMemberAccessInspection.cs @@ -5,6 +5,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -54,7 +55,7 @@ protected override string ResultDescription(IdentifierReference reference) { var expression = reference.IdentifierName; var defaultMember = reference.Declaration.QualifiedName.ToString(); - return string.Format(InspectionResults.IndexedDefaultMemberAccessInspection, expression, defaultMember); + return string.Format(InspectionResults.ResourceManager.GetString("IndexedDefaultMemberAccessInspection", CultureInfo.CurrentUICulture), expression, defaultMember); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedRecursiveDefaultMemberAccessInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedRecursiveDefaultMemberAccessInspection.cs index 679d8e3caf..e6b7961047 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedRecursiveDefaultMemberAccessInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedRecursiveDefaultMemberAccessInspection.cs @@ -5,6 +5,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -54,7 +55,7 @@ protected override string ResultDescription(IdentifierReference reference) { var expression = reference.IdentifierName; var defaultMember = reference.Declaration.QualifiedName.ToString(); - return string.Format(InspectionResults.IndexedRecursiveDefaultMemberAccessInspection, expression, defaultMember); + return string.Format(InspectionResults.ResourceManager.GetString("IndexedRecursiveDefaultMemberAccessInspection", CultureInfo.CurrentUICulture), expression, defaultMember); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedUnboundDefaultMemberAccessInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedUnboundDefaultMemberAccessInspection.cs index 78686793e6..73bc3f5105 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedUnboundDefaultMemberAccessInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedUnboundDefaultMemberAccessInspection.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Extensions; using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.Symbols; @@ -7,6 +6,8 @@ using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; +using System.Collections.Generic; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -60,7 +61,7 @@ protected override bool IsResultReference(IdentifierReference reference, Declara protected override string ResultDescription(IdentifierReference reference) { var expression = reference.IdentifierName; - return string.Format(InspectionResults.IndexedUnboundDefaultMemberAccessInspection, expression); + return string.Format(InspectionResults.ResourceManager.GetString("IndexedUnboundDefaultMemberAccessInspection", CultureInfo.CurrentUICulture), expression); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/IntegerDataTypeInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/IntegerDataTypeInspection.cs index df7771681a..4f015fa855 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/IntegerDataTypeInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/IntegerDataTypeInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -38,7 +39,7 @@ internal sealed class IntegerDataTypeInspection : DeclarationInspectionBase { public IntegerDataTypeInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -82,7 +83,7 @@ protected override string ResultDescription(Declaration declaration) var declarationType = declaration.DeclarationType.ToLocalizedString(); var declarationName = declaration.IdentifierName; return string.Format( - Resources.Inspections.InspectionResults.IntegerDataTypeInspection, + Resources.Inspections.InspectionResults.ResourceManager.GetString(nameof(IntegerDataTypeInspection), CultureInfo.CurrentUICulture), declarationType, declarationName); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/InvalidAnnotationInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/InvalidAnnotationInspection.cs index 9b53d9ab4c..78f107d05d 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/InvalidAnnotationInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/InvalidAnnotationInspection.cs @@ -1,180 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; using Rubberduck.CodeAnalysis.Inspections.Abstract; -using Rubberduck.CodeAnalysis.Inspections.Results; using Rubberduck.InternalApi.Extensions; -using Rubberduck.Parsing; using Rubberduck.Parsing.Annotations; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; -using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; -using Rubberduck.VBEditor; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { - /// - /// An inspection that flags invalid annotation comments. - /// - internal abstract class InvalidAnnotationInspectionBase : InspectionBase - { - protected InvalidAnnotationInspectionBase(IDeclarationFinderProvider declarationFinderProvider) - : base(declarationFinderProvider) { } - - protected QualifiedContext Context(IParseTreeAnnotation pta) => - new QualifiedContext(pta.QualifiedSelection.QualifiedName, pta.Context); - - protected sealed override IEnumerable DoGetInspectionResults(DeclarationFinder finder) - { - return finder.UserDeclarations(DeclarationType.Module) -.Where(module => module != null) -.SelectMany(module => DoGetInspectionResults(module.QualifiedModuleName, finder)); - } - - protected IInspectionResult InspectionResult(IParseTreeAnnotation pta) => - new QualifiedContextInspectionResult(this, ResultDescription(pta), Context(pta)); - - /// - /// Gets all invalid annotations covered by this inspection. - /// - /// All user code annotations. - /// All user declarations. - /// All identifier references in user code. - /// - protected abstract IEnumerable GetInvalidAnnotations( - IEnumerable annotations, - IEnumerable userDeclarations, - IEnumerable identifierReferences); - - /// - /// Gets an annotation-specific description for an inspection result. - /// - /// The invalid annotation. - /// - protected abstract string ResultDescription(IParseTreeAnnotation pta); - - protected sealed override IEnumerable DoGetInspectionResults(QualifiedModuleName module, DeclarationFinder finder) - { - var annotations = finder.FindAnnotations(module); - var userDeclarations = finder.Members(module).ToList(); - var identifierReferences = finder.IdentifierReferences(module).ToList(); - - var invalidAnnotations = GetInvalidAnnotations(annotations, userDeclarations, identifierReferences); - return invalidAnnotations.Select(InspectionResult).ToList(); - } - } - - /// - /// Flags comments that parsed like Rubberduck annotations, but were not recognized as such. - /// - /// - /// Other add-ins may support similar-looking annotations that Rubberduck does not recognize; this inspection can be used to spot a typo in Rubberduck annotations. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - internal sealed class UnrecognizedAnnotationInspection : InvalidAnnotationInspectionBase - { - public UnrecognizedAnnotationInspection(IDeclarationFinderProvider declarationFinderProvider) - : base(declarationFinderProvider) { } - - protected override IEnumerable GetInvalidAnnotations( - IEnumerable annotations, - IEnumerable userDeclarations, - IEnumerable identifierReferences) - { - return annotations.Where(pta => pta.Annotation is NotRecognizedAnnotation).ToList(); - } - - protected override string ResultDescription(IParseTreeAnnotation pta) => - string.Format(InspectionResults.UnrecognizedAnnotationInspection, pta.Context.GetText()); - } - - /// - /// Flags Rubberduck annotations used in a component type that is incompatible with that annotation. - /// - /// - /// Some annotations can only be used in a specific type of module; others cannot be used in certain types of modules. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - internal sealed class AnnotationInIncompatibleComponentTypeInspection : InvalidAnnotationInspectionBase - { - public AnnotationInIncompatibleComponentTypeInspection(IDeclarationFinderProvider declarationFinderProvider) - : base(declarationFinderProvider) { } - - protected override IEnumerable GetInvalidAnnotations( - IEnumerable annotations, - IEnumerable userDeclarations, - IEnumerable identifierReferences) - { - foreach (var pta in annotations) - { - var annotation = pta.Annotation; - var componentType = pta.QualifiedSelection.QualifiedName.ComponentType; - if (annotation.RequiredComponentType.HasValue && annotation.RequiredComponentType != componentType - || annotation.IncompatibleComponentTypes.Contains(componentType)) - { - yield return pta; - } - } - - yield break; - } - - protected override string ResultDescription(IParseTreeAnnotation pta) - { - if (pta.Annotation.RequiredComponentType.HasValue) - { - return string.Format(InspectionResults.InvalidAnnotationInspection_NotInRequiredComponentType, - pta.Annotation.Name, // annotation... - pta.QualifiedSelection.QualifiedName.ComponentType, // is used in a... - pta.Annotation.RequiredComponentType); // but is only valid in a... - } - else - { - return string.Format(InspectionResults.InvalidAnnotationInspection_IncompatibleComponentType, - pta.Annotation.Name, // annotation... - pta.QualifiedSelection.QualifiedName.ComponentType); // cannot be used in a... - } - } - } /// /// Flags invalid or misplaced Rubberduck annotation comments. @@ -210,10 +45,10 @@ internal sealed class InvalidAnnotationInspection : InvalidAnnotationInspectionB { public InvalidAnnotationInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override string ResultDescription(IParseTreeAnnotation pta) => - string.Format(InspectionResults.InvalidAnnotationInspection, pta.Annotation.Name); + string.Format(InspectionResults.ResourceManager.GetString(nameof(InvalidAnnotationInspection), CultureInfo.CurrentUICulture), pta.Annotation.Name); protected override IEnumerable GetInvalidAnnotations( IEnumerable annotations, diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/IsMissingOnInappropriateArgumentInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/IsMissingOnInappropriateArgumentInspection.cs index a4baac3aff..d89a038117 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/IsMissingOnInappropriateArgumentInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/IsMissingOnInappropriateArgumentInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -38,7 +39,7 @@ internal class IsMissingOnInappropriateArgumentInspection : IsMissingInspectionB { public IsMissingOnInappropriateArgumentInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override (bool isResult, ParameterDeclaration properties) IsUnsuitableArgumentWithAdditionalProperties(ArgumentReference reference, DeclarationFinder finder) { @@ -54,7 +55,7 @@ protected override (bool isResult, ParameterDeclaration properties) IsUnsuitable protected override string ResultDescription(IdentifierReference reference, ParameterDeclaration parameter) { - return InspectionResults.IsMissingOnInappropriateArgumentInspection; + return InspectionResults.ResourceManager.GetString(nameof(IsMissingOnInappropriateArgumentInspection), CultureInfo.CurrentUICulture); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/IsMissingWithNonArgumentParameterInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/IsMissingWithNonArgumentParameterInspection.cs index 8143f50bcb..ec05267cba 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/IsMissingWithNonArgumentParameterInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/IsMissingWithNonArgumentParameterInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -38,7 +39,7 @@ internal class IsMissingWithNonArgumentParameterInspection : IsMissingInspection { public IsMissingWithNonArgumentParameterInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override (bool isResult, ParameterDeclaration properties) IsUnsuitableArgumentWithAdditionalProperties(ArgumentReference reference, DeclarationFinder finder) { @@ -49,7 +50,7 @@ protected override (bool isResult, ParameterDeclaration properties) IsUnsuitable protected override string ResultDescription(IdentifierReference reference, ParameterDeclaration properties) { - return InspectionResults.IsMissingWithNonArgumentParameterInspection; + return InspectionResults.ResourceManager.GetString(nameof(IsMissingWithNonArgumentParameterInspection), CultureInfo.CurrentUICulture); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/LineLabelNotUsedInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/LineLabelNotUsedInspection.cs index d92513da55..8ad183f1d8 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/LineLabelNotUsedInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/LineLabelNotUsedInspection.cs @@ -1,4 +1,3 @@ -using System.Linq; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Extensions; using Rubberduck.Parsing.Grammar; @@ -6,6 +5,8 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -46,7 +47,7 @@ internal sealed class LineLabelNotUsedInspection : DeclarationInspectionBase { public LineLabelNotUsedInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.LineLabel) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -61,8 +62,8 @@ protected override string ResultDescription(Declaration declaration) var declarationType = declaration.DeclarationType.ToLocalizedString(); var declarationName = declaration.IdentifierName; return string.Format( - InspectionResults.IdentifierNotUsedInspection, - declarationType, + InspectionResults.ResourceManager.GetString(nameof(InspectionResults.IdentifierNotUsedInspection), CultureInfo.CurrentUICulture), + declarationType, declarationName); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/MemberNotOnInterfaceInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/MemberNotOnInterfaceInspection.cs index 2a28f1e885..7a94dd61a0 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/MemberNotOnInterfaceInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/MemberNotOnInterfaceInspection.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing; using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.Symbols; @@ -8,6 +6,9 @@ using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -45,7 +46,7 @@ internal sealed class MemberNotOnInterfaceInspection : DeclarationInspectionBase { public MemberNotOnInterfaceInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override IEnumerable RelevantDeclarationsInModule(QualifiedModuleName module, DeclarationFinder finder) { @@ -94,7 +95,7 @@ protected override string ResultDescription(Declaration declaration, Declaration var memberName = declaration.IdentifierName; var typeName = typeDeclaration?.IdentifierName ?? string.Empty; return string.Format( - InspectionResults.MemberNotOnInterfaceInspection, + InspectionResults.ResourceManager.GetString(nameof(MemberNotOnInterfaceInspection), CultureInfo.CurrentUICulture), memberName, typeName); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/MisleadingByRefParameterInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/MisleadingByRefParameterInspection.cs index 7b88433fc7..65d5691cfc 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/MisleadingByRefParameterInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/MisleadingByRefParameterInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete @@ -58,14 +59,14 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration && parameter.IsByRef && !parameter.IsImplicitByRef; } - private static bool IsAlwaysByRef(Declaration parameter) + private static bool IsAlwaysByRef(Declaration parameter) => parameter.IsArray || (parameter.AsTypeDeclaration?.DeclarationType.HasFlag(DeclarationType.UserDefinedType) ?? false); protected override string ResultDescription(Declaration declaration) { return string.Format( - InspectionResults.MisleadingByRefParameterInspection, + InspectionResults.ResourceManager.GetString(nameof(MisleadingByRefParameterInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName, declaration.ParentDeclaration.QualifiedName.MemberName); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingAnnotationArgumentInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingAnnotationArgumentInspection.cs index f6664a961d..ee8430598f 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingAnnotationArgumentInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingAnnotationArgumentInspection.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Linq; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Results; using Rubberduck.Parsing; @@ -9,6 +7,9 @@ using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -42,7 +43,7 @@ internal sealed class MissingAnnotationArgumentInspection : InspectionBase { public MissingAnnotationArgumentInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override IEnumerable DoGetInspectionResults(DeclarationFinder finder) { @@ -79,7 +80,7 @@ private IInspectionResult InspectionResult(IParseTreeAnnotation pta) private static string ResultDescription(IParseTreeAnnotation pta) { return string.Format( - InspectionResults.MissingAnnotationArgumentInspection, + InspectionResults.ResourceManager.GetString(nameof(MissingAnnotationArgumentInspection), CultureInfo.CurrentUICulture), pta.Annotation.Name); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingAttributeInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingAttributeInspection.cs index 3e9bc58d5f..08758940b2 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingAttributeInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingAttributeInspection.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Linq; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Attributes; using Rubberduck.Parsing.Annotations; @@ -8,6 +6,9 @@ using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor.SafeComWrappers; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -44,7 +45,7 @@ internal sealed class MissingAttributeInspection : DeclarationInspectionMultiRes { public MissingAttributeInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override IEnumerable ResultProperties(Declaration declaration, DeclarationFinder finder) { @@ -60,8 +61,8 @@ protected override IEnumerable ResultProperties(Declaratio } protected override string ResultDescription(Declaration declaration, IParseTreeAnnotation pta) => - string.Format(InspectionResults.MissingAttributeInspection, declaration.IdentifierName, pta.Annotation.Name); - + string.Format(InspectionResults.ResourceManager.GetString(nameof(MissingAttributeInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName, pta.Annotation.Name); + private static bool MissesCorrespondingAttribute(Declaration declaration, IParseTreeAnnotation annotationInstance) { diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingMemberAnnotationInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingMemberAnnotationInspection.cs index 684d4bc447..58454e4e58 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingMemberAnnotationInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingMemberAnnotationInspection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing.Annotations; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor.SafeComWrappers; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -41,8 +42,8 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete internal sealed class MissingMemberAnnotationInspection : DeclarationInspectionMultiResultBase<(string AttributeName, IReadOnlyList AttriguteValues)> { public MissingMemberAnnotationInspection(IDeclarationFinderProvider declarationFinderProvider) - : base(declarationFinderProvider, new DeclarationType[0], new []{DeclarationType.Module }) - {} + : base(declarationFinderProvider, new DeclarationType[0], new[] { DeclarationType.Module }) + { } protected override IEnumerable<(string AttributeName, IReadOnlyList AttriguteValues)> ResultProperties(Declaration declaration, DeclarationFinder finder) { @@ -68,10 +69,11 @@ private static bool MissesCorrespondingMemberAnnotation(Declaration declaration, if (attributeBaseName == "VB_Ext_Key") { return !declaration.Annotations.Where(pta => pta.Annotation is IAttributeAnnotation) - .Any(pta => { - var annotation = (IAttributeAnnotation)pta.Annotation; - return annotation.Attribute(pta).Equals("VB_Ext_Key") && attribute.Values[0].Equals(annotation.AttributeValues(pta)[0]); - }); + .Any(pta => + { + var annotation = (IAttributeAnnotation)pta.Annotation; + return annotation.Attribute(pta).Equals("VB_Ext_Key") && attribute.Values[0].Equals(annotation.AttributeValues(pta)[0]); + }); } return !declaration.Annotations.Where(pta => pta.Annotation is IAttributeAnnotation) @@ -86,7 +88,7 @@ private static string AttributeBaseName(Declaration declaration, AttributeNode a protected override string ResultDescription(Declaration declaration, (string AttributeName, IReadOnlyList AttriguteValues) properties) { var (attributeBaseName, attributeValues) = properties; - return string.Format(InspectionResults.MissingMemberAnnotationInspection, + return string.Format(InspectionResults.ResourceManager.GetString(nameof(MissingMemberAnnotationInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName, attributeBaseName, string.Join(", ", attributeValues)); diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingModuleAnnotationInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingModuleAnnotationInspection.cs index fbd8edbe72..743c497639 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingModuleAnnotationInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/MissingModuleAnnotationInspection.cs @@ -1,11 +1,12 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing.Annotations; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -38,8 +39,8 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete internal sealed class MissingModuleAnnotationInspection : DeclarationInspectionMultiResultBase<(string AttributeName, IReadOnlyList AttributeValues)> { public MissingModuleAnnotationInspection(IDeclarationFinderProvider declarationFinderProvider) - : base(declarationFinderProvider, new []{DeclarationType.Module}, new []{DeclarationType.Document}) - {} + : base(declarationFinderProvider, new[] { DeclarationType.Module }, new[] { DeclarationType.Document }) + { } protected override IEnumerable<(string AttributeName, IReadOnlyList AttributeValues)> ResultProperties(Declaration declaration, DeclarationFinder finder) { @@ -50,7 +51,7 @@ public MissingModuleAnnotationInspection(IDeclarationFinderProvider declarationF private static bool IsResultAttribute(AttributeNode attribute, Declaration declaration) { - return !IsDefaultAttribute(declaration, attribute) + return !IsDefaultAttribute(declaration, attribute) && MissesCorrespondingModuleAnnotation(declaration, attribute); } @@ -74,7 +75,8 @@ private static bool MissesCorrespondingModuleAnnotation(Declaration declaration, if (attribute.Name == "VB_Ext_Key") { return !declaration.Annotations.Where(pta => pta.Annotation is IAttributeAnnotation) - .Any(pta => { + .Any(pta => + { var annotation = (IAttributeAnnotation)pta.Annotation; return annotation.Attribute(pta).Equals("VB_Ext_Key") && attribute.Values[0].Equals(annotation.AttributeValues(pta)[0]); }); @@ -86,7 +88,7 @@ private static bool MissesCorrespondingModuleAnnotation(Declaration declaration, protected override string ResultDescription(Declaration declaration, (string AttributeName, IReadOnlyList AttributeValues) properties) { - return string.Format(InspectionResults.MissingMemberAnnotationInspection, + return string.Format(InspectionResults.ResourceManager.GetString(nameof(MissingMemberAnnotationInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName, properties.AttributeName, string.Join(", ", properties.AttributeValues)); diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ModuleScopeDimKeywordInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ModuleScopeDimKeywordInspection.cs index c649215252..0608d2bcc2 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ModuleScopeDimKeywordInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ModuleScopeDimKeywordInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -46,7 +47,7 @@ protected override string ResultDescription(QualifiedContext !reference.ParentScoping.Equals(usageMember))) { return false; @@ -89,7 +90,7 @@ private static bool IsRubberduckAssertField(Declaration fieldDeclaration) protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.MoveFieldCloserToUsageInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(MoveFieldCloserToUsageInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/MultilineParameterInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/MultilineParameterInspection.cs index dd384592e3..8697b84f6b 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/MultilineParameterInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/MultilineParameterInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing; using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -39,7 +40,7 @@ public MultilineParameterInspection(IDeclarationFinderProvider declarationFinder { ContextListener = new ParameterListener(); } - + protected override IInspectionListener ContextListener { get; } protected override string ResultDescription(QualifiedContext context) @@ -47,8 +48,8 @@ protected override string ResultDescription(QualifiedContext 3 - ? CodeAnalysisUI.EasterEgg_Continuator - : Resources.Inspections.InspectionResults.MultilineParameterInspection, + ? CodeAnalysisUI.ResourceManager.GetString(nameof(CodeAnalysisUI.EasterEgg_Continuator), CultureInfo.CurrentUICulture) + : Resources.Inspections.InspectionResults.ResourceManager.GetString(nameof(MultilineParameterInspection), CultureInfo.CurrentUICulture), parameterText); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/MultipleDeclarationsInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/MultipleDeclarationsInspection.cs index ca975181e1..20eeab1748 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/MultipleDeclarationsInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/MultipleDeclarationsInspection.cs @@ -5,6 +5,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -50,7 +51,7 @@ public MultipleDeclarationsInspection(IDeclarationFinderProvider declarationFind protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.MultipleDeclarationsInspection; + return InspectionResults.ResourceManager.GetString(nameof(MultipleDeclarationsInspection), CultureInfo.CurrentUICulture); } private class ParameterListListener : InspectionListenerBase @@ -59,7 +60,7 @@ public override void ExitVariableListStmt([NotNull] VBAParser.VariableListStmtCo { if (context.variableSubStmt().Length > 1) { - SaveContext(context); + SaveContext(context); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/NonReturningFunctionInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/NonReturningFunctionInspection.cs index e496396a09..f73cb5413b 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/NonReturningFunctionInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/NonReturningFunctionInspection.cs @@ -1,4 +1,3 @@ -using System.Linq; using Antlr4.Runtime.Tree; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing; @@ -7,6 +6,8 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -42,7 +43,7 @@ internal sealed class NonReturningFunctionInspection : DeclarationInspectionBase { public NonReturningFunctionInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Function) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -59,7 +60,7 @@ private bool IsAssigned(Declaration member, DeclarationFinder finder) var inScopeIdentifierReferences = member.References .Where(reference => reference.ParentScoping.Equals(member)); return inScopeIdentifierReferences - .Any(reference => reference.IsAssignment + .Any(reference => reference.IsAssignment || IsAssignedByRefArgument(member, reference, finder)); } @@ -97,7 +98,7 @@ private static VBAParser.ArgumentExpressionContext ImmediateArgumentExpressionCo private static bool IsReturningUserDefinedType(Declaration member) { - return member.AsTypeDeclaration != null + return member.AsTypeDeclaration != null && member.AsTypeDeclaration.DeclarationType == DeclarationType.UserDefinedType; } @@ -114,7 +115,7 @@ private static bool IsUserDefinedTypeAssigned(Declaration member) protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.NonReturningFunctionInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(NonReturningFunctionInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } /// diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObjectVariableNotSetInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObjectVariableNotSetInspection.cs index 2a8457f0d8..836f4c3ce1 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObjectVariableNotSetInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObjectVariableNotSetInspection.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Antlr4.Runtime; +using Antlr4.Runtime; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing; using Rubberduck.Parsing.Grammar; @@ -10,6 +7,10 @@ using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -46,7 +47,7 @@ internal sealed class ObjectVariableNotSetInspection : IdentifierReferenceInspec { public ObjectVariableNotSetInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override IEnumerable ReferencesInModule(QualifiedModuleName module, DeclarationFinder finder) { @@ -89,7 +90,7 @@ private static IEnumerable PossiblyObjectNonSetAssignments( var assignments = finder.IdentifierReferences(module) .Where(reference => reference.IsAssignment && !reference.IsSetAssignment - && (reference.IsNonIndexedDefaultMemberAccess + && (reference.IsNonIndexedDefaultMemberAccess || Tokens.Variant.Equals(reference.Declaration.AsTypeName, StringComparison.InvariantCultureIgnoreCase))); var unboundAssignments = finder.UnboundDefaultMemberAccesses(module) .Where(reference => reference.IsAssignment); @@ -104,7 +105,7 @@ protected override bool IsResultReference(IdentifierReference reference, Declara protected override string ResultDescription(IdentifierReference reference) { - return string.Format(InspectionResults.ObjectVariableNotSetInspection, reference.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ObjectVariableNotSetInspection), CultureInfo.CurrentUICulture), reference.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObjectWhereProcedureIsRequiredInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObjectWhereProcedureIsRequiredInspection.cs index bad877aef6..e61f1ce89e 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObjectWhereProcedureIsRequiredInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObjectWhereProcedureIsRequiredInspection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Results; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -101,7 +102,7 @@ private static string BoundResultDescription(IdentifierReference reference) { var expression = reference.IdentifierName; var defaultMember = reference.Declaration.QualifiedName.ToString(); - return string.Format(InspectionResults.ObjectWhereProcedureIsRequiredInspection, expression, defaultMember); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ObjectWhereProcedureIsRequiredInspection), CultureInfo.CurrentUICulture), expression, defaultMember); } private IEnumerable UnboundInspectionResults(QualifiedModuleName module, DeclarationFinder finder) @@ -117,7 +118,7 @@ private IEnumerable UnboundInspectionResults(QualifiedModuleN private IInspectionResult UnboundInspectionResult(IdentifierReference reference, DeclarationFinder finder) { - var disabledQuickFixes = new List{ "ExpandDefaultMemberQuickFix" }; + var disabledQuickFixes = new List { "ExpandDefaultMemberQuickFix" }; return new IdentifierReferenceInspectionResult( this, UnboundResultDescription(reference), @@ -129,7 +130,7 @@ private IInspectionResult UnboundInspectionResult(IdentifierReference reference, private static string UnboundResultDescription(IdentifierReference reference) { var expression = reference.IdentifierName; - return string.Format(InspectionResults.ObjectWhereProcedureIsRequiredInspection_Unbound, expression); + return string.Format(InspectionResults.ResourceManager.GetString("ObjectWhereProcedureIsRequiredInspection_Unbound", CultureInfo.CurrentUICulture), expression); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteCallStatementInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteCallStatementInspection.cs index 55fbfb6f49..98fca0e223 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteCallStatementInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteCallStatementInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -51,7 +52,7 @@ public ObsoleteCallStatementInspection(IDeclarationFinderProvider declarationFin protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.ObsoleteCallStatementInspection; + return InspectionResults.ResourceManager.GetString(nameof(ObsoleteCallStatementInspection), CultureInfo.CurrentUICulture); } protected override bool IsResultContext(QualifiedContext context, DeclarationFinder finder) diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteCallingConventionInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteCallingConventionInspection.cs index 923df5ec31..a28360cc22 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteCallingConventionInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteCallingConventionInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -40,9 +41,9 @@ public ObsoleteCallingConventionInspection(IDeclarationFinderProvider declaratio protected override string ResultDescription(QualifiedContext context) { - var identifierName = ((VBAParser.DeclareStmtContext) context.Context).identifier().GetText(); + var identifierName = ((VBAParser.DeclareStmtContext)context.Context).identifier().GetText(); return string.Format( - InspectionResults.ObsoleteCallingConventionInspection, + InspectionResults.ResourceManager.GetString(nameof(ObsoleteCallingConventionInspection), CultureInfo.CurrentUICulture), identifierName); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteCommentSyntaxInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteCommentSyntaxInspection.cs index 3b7fc0af7a..8d80471076 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteCommentSyntaxInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteCommentSyntaxInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -42,7 +43,7 @@ public ObsoleteCommentSyntaxInspection(IDeclarationFinderProvider declarationFin protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.ObsoleteCommentSyntaxInspection; + return InspectionResults.ResourceManager.GetString(nameof(ObsoleteCommentSyntaxInspection), CultureInfo.CurrentUICulture); } private class ObsoleteCommentSyntaxListener : InspectionListenerBase diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteErrorSyntaxInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteErrorSyntaxInspection.cs index 73615bb07c..32cbeb25e3 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteErrorSyntaxInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteErrorSyntaxInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -42,7 +43,7 @@ public ObsoleteErrorSyntaxInspection(IDeclarationFinderProvider declarationFinde protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.ObsoleteErrorSyntaxInspection; + return InspectionResults.ResourceManager.GetString(nameof(ObsoleteErrorSyntaxInspection), CultureInfo.CurrentUICulture); } private class ObsoleteErrorSyntaxListener : InspectionListenerBase diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteGlobalInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteGlobalInspection.cs index 72fdc31898..b6ddfd2a49 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteGlobalInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteGlobalInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -33,11 +34,11 @@ internal sealed class ObsoleteGlobalInspection : DeclarationInspectionBase { public ObsoleteGlobalInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { - return declaration.Accessibility == Accessibility.Global + return declaration.Accessibility == Accessibility.Global && declaration.Context != null && declaration.DeclarationType != DeclarationType.BracketedExpression; } @@ -47,7 +48,7 @@ protected override string ResultDescription(Declaration declaration) var declarationType = declaration.DeclarationType.ToLocalizedString(); var declarationName = declaration.IdentifierName; return string.Format( - InspectionResults.ObsoleteGlobalInspection, + InspectionResults.ResourceManager.GetString(nameof(ObsoleteGlobalInspection), CultureInfo.CurrentUICulture), declarationType, declarationName); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteLetStatementInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteLetStatementInspection.cs index 249556a1fc..c23c0a04ac 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteLetStatementInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteLetStatementInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -39,12 +40,12 @@ public ObsoleteLetStatementInspection(IDeclarationFinderProvider declarationFind { ContextListener = new ObsoleteLetStatementListener(); } - + protected override IInspectionListener ContextListener { get; } protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.ObsoleteLetStatementInspection; + return InspectionResults.ResourceManager.GetString(nameof(ObsoleteLetStatementInspection), CultureInfo.CurrentUICulture); } private class ObsoleteLetStatementListener : InspectionListenerBase @@ -53,7 +54,7 @@ public override void ExitLetStmt(VBAParser.LetStmtContext context) { if (context.LET() != null) { - SaveContext(context); + SaveContext(context); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteMemberUsageInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteMemberUsageInspection.cs index 340f529e8a..01a8bdf5be 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteMemberUsageInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteMemberUsageInspection.cs @@ -1,10 +1,11 @@ -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing.Annotations; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -54,7 +55,7 @@ internal sealed class ObsoleteMemberUsageInspection : IdentifierReferenceInspect { public ObsoleteMemberUsageInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override bool IsResultReference(IdentifierReference reference, DeclarationFinder finder) { @@ -72,7 +73,7 @@ protected override string ResultDescription(IdentifierReference reference) .AnnotationArguments .FirstOrDefault() ?? string.Empty; return string.Format( - InspectionResults.ObsoleteMemberUsageInspection, + InspectionResults.ResourceManager.GetString(nameof(ObsoleteMemberUsageInspection), CultureInfo.CurrentUICulture), reference.IdentifierName, replacementDocumentation); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteTypeHintInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteTypeHintInspection.cs index cfc5898a90..b6b5c68236 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteTypeHintInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteTypeHintInspection.cs @@ -1,12 +1,14 @@ -using System.Collections.Generic; -using System.Linq; using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Extensions; using Rubberduck.CodeAnalysis.Inspections.Results; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -40,7 +42,7 @@ internal sealed class ObsoleteTypeHintInspection : InspectionBase { public ObsoleteTypeHintInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override IEnumerable DoGetInspectionResults(DeclarationFinder finder) { @@ -74,11 +76,11 @@ private IInspectionResult InspectionResult(Declaration declaration) private static string ResultDescription(Declaration declaration) { - var declarationTypeName = declaration.DeclarationType.ToString().ToLower(); + var declarationTypeName = declaration.DeclarationType.ToLocalizedString(); var identifierName = declaration.IdentifierName; return string.Format( - InspectionResults.ObsoleteTypeHintInspection, - InspectionsUI.Inspections_Declaration, + InspectionResults.ResourceManager.GetString("ObsoleteTypeHintInspection", CultureInfo.CurrentUICulture), + InspectionsUI.ResourceManager.GetString("Inspections_Declaration", CultureInfo.CurrentUICulture), declarationTypeName, identifierName); } @@ -104,10 +106,10 @@ private IInspectionResult InspectionResult(IdentifierReference reference, Declar private string ResultDescription(IdentifierReference reference) { - var declarationTypeName = reference.Declaration.DeclarationType.ToString().ToLower(); + var declarationTypeName = reference.Declaration.DeclarationType.ToLocalizedString(); var identifierName = reference.IdentifierName; - return string.Format(InspectionResults.ObsoleteTypeHintInspection, - InspectionsUI.Inspections_Usage, + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ObsoleteTypeHintInspection), CultureInfo.CurrentUICulture), + InspectionsUI.ResourceManager.GetString(nameof(InspectionsUI.Inspections_Usage), CultureInfo.CurrentUICulture), declarationTypeName, identifierName); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteWhileWendStatementInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteWhileWendStatementInspection.cs index 93f1623154..98259d2c75 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteWhileWendStatementInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteWhileWendStatementInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -47,7 +48,7 @@ public ObsoleteWhileWendStatementInspection(IDeclarationFinderProvider declarati protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.ObsoleteWhileWendStatementInspection; + return InspectionResults.ResourceManager.GetString(nameof(ObsoleteWhileWendStatementInspection), CultureInfo.CurrentUICulture); } private class ObsoleteWhileWendStatementListener : InspectionListenerBase diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/OnLocalErrorInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/OnLocalErrorInspection.cs index 3b7b0a371b..45a79af915 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/OnLocalErrorInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/OnLocalErrorInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -51,7 +52,7 @@ public OnLocalErrorInspection(IDeclarationFinderProvider declarationFinderProvid protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.OnLocalErrorInspection; + return InspectionResults.ResourceManager.GetString(nameof(OnLocalErrorInspection), CultureInfo.CurrentUICulture); } private class OnLocalErrorListener : InspectionListenerBase @@ -60,7 +61,7 @@ public override void ExitOnErrorStmt([NotNull] VBAParser.OnErrorStmtContext cont { if (context.ON_LOCAL_ERROR() != null) { - SaveContext(context); + SaveContext(context); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/OptionBaseInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/OptionBaseInspection.cs index cc4c9dd966..d9f360bc2f 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/OptionBaseInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/OptionBaseInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -46,14 +47,14 @@ public OptionBaseInspection(IDeclarationFinderProvider declarationFinderProvider { ContextListener = new OptionBaseStatementListener(); } - + protected override IInspectionListener ContextListener { get; } protected override string ResultDescription(QualifiedContext context) { var moduleName = context.ModuleName.ComponentName; return string.Format( - InspectionResults.OptionBaseInspection, + InspectionResults.ResourceManager.GetString(nameof(OptionBaseInspection), CultureInfo.CurrentUICulture), moduleName); } @@ -63,7 +64,7 @@ public override void ExitOptionBaseStmt(VBAParser.OptionBaseStmtContext context) { if (context.numberLiteral()?.INTEGERLITERAL().Symbol.Text == "1") { - SaveContext(context); + SaveContext(context); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/OptionExplicitInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/OptionExplicitInspection.cs index 175cc0f6f8..34f43a7db0 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/OptionExplicitInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/OptionExplicitInspection.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using Antlr4.Runtime.Misc; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing; @@ -7,6 +6,8 @@ using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; +using System.Collections.Generic; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -47,7 +48,7 @@ public OptionExplicitInspection(IDeclarationFinderProvider declarationFinderProv ContextListener = new MissingOptionExplicitListener(); } - protected override IInspectionListener ContextListener { get; } + protected override IInspectionListener ContextListener { get; } protected override bool IsResultContext(QualifiedContext context, DeclarationFinder finder) { @@ -59,7 +60,7 @@ protected override string ResultDescription(QualifiedContext ParameterAtIndexIsNotUsed(implementation, parameterIndex)); } @@ -136,13 +137,13 @@ private static bool ThereAreHandlersAndNoneUsesTheParameter(ParameterDeclaration var handlers = finder.FindEventHandlers(eventDeclaration).ToList(); //We do not want to report all parameters of not handled events. - return handlers.Any() + return handlers.Any() && handlers.All(handler => ParameterAtIndexIsNotUsed(handler, parameterIndex)); } protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.ParameterNotUsedInspection, declaration.IdentifierName).Capitalize(); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ParameterNotUsedInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName).Capitalize(); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ParameterlessCellsInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ParameterlessCellsInspection.cs new file mode 100644 index 0000000000..a0da3ac9ad --- /dev/null +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ParameterlessCellsInspection.cs @@ -0,0 +1,93 @@ +using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Attributes; +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 System.Collections.Generic; +using System.Globalization; +using System.Linq; + +namespace Rubberduck.CodeAnalysis.Inspections.Concrete +{ + /// + /// Identifies parameterless 'Range.Cells' member calls. + /// + /// + /// + /// Range.Cells is a parameterized Property Get procedure that accepts RowIndex and ColumnIndex parameters, both optional + /// to avoid requiring either when only one needs to be supplied. If no parameters are provided, + /// Cells simply returns a reference to the parent Range object, making a parameterless call entirely redundant. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + [RequiredLibrary("Excel")] + internal sealed class ParameterlessCellsInspection : IdentifierReferenceInspectionBase + { + public ParameterlessCellsInspection(IDeclarationFinderProvider declarationFinderProvider) + : base(declarationFinderProvider) + { + } + + protected override IEnumerable DoGetInspectionResults(DeclarationFinder finder) + { + var excel = finder.Projects.SingleOrDefault(item => !item.IsUserDefined && item.IdentifierName == "Excel"); + if (excel is null) + { + yield break; + } + + var range = finder.Classes.SingleOrDefault(item => !item.IsUserDefined && item.IdentifierName == "Range" && item.ProjectId == excel.ProjectId); + if (range is null) + { + yield break; + } + + var cells = finder.Members(range).SingleOrDefault(item => item.IdentifierName == "Cells" && item.DeclarationType == DeclarationType.PropertyGet); + if (cells is null) + { + yield break; + } + + foreach (var reference in cells.References.Where(reference => IsResultReference(reference, finder))) + { + yield return InspectionResult(reference, finder); + } + } + + protected override bool IsResultReference(IdentifierReference reference, DeclarationFinder finder) + { + var memberAccess = reference.Context.GetAncestor(); + var memberArgs = memberAccess?.GetAncestor()?.argumentList(); + + return memberAccess != null && !memberArgs.GetDescendents().Any(); + } + + protected override string ResultDescription(IdentifierReference reference) + { + return InspectionResults.ResourceManager.GetString(nameof(ParameterlessCellsInspection), CultureInfo.CurrentUICulture); + } + } +} diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureCanBeWrittenAsFunctionInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureCanBeWrittenAsFunctionInspection.cs index 24ebd6735d..e59aadfd5d 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureCanBeWrittenAsFunctionInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureCanBeWrittenAsFunctionInspection.cs @@ -1,11 +1,12 @@ -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; 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 System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -53,8 +54,8 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete internal sealed class ProcedureCanBeWrittenAsFunctionInspection : DeclarationInspectionBase { public ProcedureCanBeWrittenAsFunctionInspection(IDeclarationFinderProvider declarationFinderProvider) - : base(declarationFinderProvider, new []{DeclarationType.Procedure}, new []{DeclarationType.LibraryProcedure, DeclarationType.PropertyLet, DeclarationType.PropertySet}) - {} + : base(declarationFinderProvider, new[] { DeclarationType.Procedure }, new[] { DeclarationType.LibraryProcedure, DeclarationType.PropertyLet, DeclarationType.PropertySet }) + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -119,7 +120,7 @@ private static VBAParser.ArgumentExpressionContext ImmediateArgumentExpressionCo protected override string ResultDescription(Declaration declaration) { return string.Format( - InspectionResults.ProcedureCanBeWrittenAsFunctionInspection, + InspectionResults.ResourceManager.GetString(nameof(ProcedureCanBeWrittenAsFunctionInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureNotUsedInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureNotUsedInspection.cs index 14a795906c..59ca3e4b5d 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureNotUsedInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureNotUsedInspection.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Linq; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Extensions; using Rubberduck.Parsing.Annotations; @@ -8,6 +6,8 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -110,7 +110,7 @@ internal sealed class ProcedureNotUsedInspection : DeclarationInspectionBase { public ProcedureNotUsedInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, ProcedureTypes) - {} + { } private static readonly DeclarationType[] ProcedureTypes = { @@ -143,10 +143,10 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration .Any(reference => !reference.ParentScoping.Equals(declaration)) // ignore recursive/self-referential calls && !finder.FindEventHandlers().Contains(declaration) && !IsClassLifeCycleHandler(declaration) - && !(declaration is ModuleBodyElementDeclaration member + && !(declaration is ModuleBodyElementDeclaration member && member.IsInterfaceImplementation) && !declaration.Annotations - .Any(pta => pta.Annotation is ITestAnnotation) + .Any(pta => pta.Annotation is ITestAnnotation) && !IsDocumentEventHandler(declaration) && !IsEntryPoint(declaration) && !IsPublicInExposedClass(declaration); @@ -154,13 +154,13 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration private static bool IsPublicInExposedClass(Declaration procedure) { - if(!(procedure.Accessibility == Accessibility.Public + if (!(procedure.Accessibility == Accessibility.Public || procedure.Accessibility == Accessibility.Global)) { return false; } - if(!(Declaration.GetModuleParent(procedure) is ClassModuleDeclaration classParent)) + if (!(Declaration.GetModuleParent(procedure) is ClassModuleDeclaration classParent)) { return false; } @@ -168,7 +168,7 @@ private static bool IsPublicInExposedClass(Declaration procedure) return classParent.IsExposed; } - private static bool IsEntryPoint(Declaration procedure) => + private static bool IsEntryPoint(Declaration procedure) => procedure.Annotations.Any(pta => pta.Annotation is EntryPointAnnotation || pta.Annotation is ExcelHotKeyAnnotation); private static bool IsClassLifeCycleHandler(Declaration procedure) @@ -179,7 +179,7 @@ private static bool IsClassLifeCycleHandler(Declaration procedure) } var parent = Declaration.GetModuleParent(procedure); - return parent != null + return parent != null && parent.DeclarationType.HasFlag(DeclarationType.ClassModule); } @@ -195,8 +195,8 @@ protected override string ResultDescription(Declaration declaration) var declarationType = declaration.DeclarationType.ToLocalizedString(); var declarationName = declaration.IdentifierName; return string.Format( - InspectionResults.IdentifierNotUsedInspection, - declarationType, + InspectionResults.ResourceManager.GetString(nameof(InspectionResults.IdentifierNotUsedInspection), CultureInfo.CurrentUICulture), + declarationType, declarationName); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureRequiredInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureRequiredInspection.cs index 3566070fad..db1632b6c4 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureRequiredInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureRequiredInspection.cs @@ -1,10 +1,11 @@ -using System.Collections.Generic; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +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 System.Collections.Generic; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -74,7 +75,7 @@ protected override string ResultDescription(IdentifierReference failedCoercion) { var expression = failedCoercion.IdentifierName; var typeName = failedCoercion.Declaration?.FullAsTypeName; - return string.Format(InspectionResults.ProcedureRequiredInspection, expression, typeName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ProcedureRequiredInspection), CultureInfo.CurrentUICulture), expression, typeName); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/PublicControlFieldAccessInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/PublicControlFieldAccessInspection.cs index 9f2f983c32..3ee7ce0b52 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/PublicControlFieldAccessInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/PublicControlFieldAccessInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -156,7 +157,7 @@ protected override bool IsResultReference(IdentifierReference reference, Declara protected override string ResultDescription(IdentifierReference reference) { - return string.Format(InspectionResults.PublicControlFieldAccessInspection, reference.Declaration.ParentDeclaration.IdentifierName, reference.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(PublicControlFieldAccessInspection), CultureInfo.CurrentUICulture), reference.Declaration.ParentDeclaration.IdentifierName, reference.IdentifierName); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/PublicEnumerationDeclaredInWorksheetInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/PublicEnumerationDeclaredInWorksheetInspection.cs index ac5bbe60e4..24fb37be0f 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/PublicEnumerationDeclaredInWorksheetInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/PublicEnumerationDeclaredInWorksheetInspection.cs @@ -6,6 +6,7 @@ using Rubberduck.VBEditor.SafeComWrappers; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete @@ -44,7 +45,7 @@ internal sealed class PublicEnumerationDeclaredInWorksheetInspection : Declarati public PublicEnumerationDeclaredInWorksheetInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Enumeration) - {} + { } protected override bool IsResultDeclaration(Declaration enumeration, DeclarationFinder finder) { @@ -62,8 +63,7 @@ protected override bool IsResultDeclaration(Declaration enumeration, Declaration protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.PublicEnumerationDeclaredInWorksheetInspection, - declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(PublicEnumerationDeclaredInWorksheetInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } /// diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/PublicImplementationShouldBePrivateInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/PublicImplementationShouldBePrivateInspection.cs index 69e5166b39..d67dbb314f 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/PublicImplementationShouldBePrivateInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/PublicImplementationShouldBePrivateInspection.cs @@ -1,16 +1,12 @@ -using Rubberduck.CodeAnalysis.CodeMetrics; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Refactorings.Common; -using Rubberduck.Resources.Inspections; -using Rubberduck.VBEditor; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -78,7 +74,7 @@ internal sealed class PublicImplementationShouldBePrivateInspection : Declaratio { public PublicImplementationShouldBePrivateInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Member) - {} + { } //Overriding DoGetInspectionResults in order to dereference the DeclarationFinder FindXXX declaration //lists only once per inspections pass. @@ -109,11 +105,11 @@ protected override IEnumerable DoGetInspectionResults(Declara private static IEnumerable FindDocumentEventHandlers(IEnumerable publicMembers) { //Excel and Word - var docEventPrefixes = new List() - { - "Workbook", - "Worksheet", - "Document" + var docEventPrefixes = new List() + { + "Workbook", + "Worksheet", + "Document" }; //FindDocumentEventHandlers can be a source of False Positives if a Document's code @@ -125,7 +121,7 @@ private static IEnumerable FindDocumentEventHandlers(IEnumerable 2 //Excel and Word document events all have at least 3 characters && !splitup[1].Any(c => char.IsDigit(c)); //Excel and Word document event names do not contain numbers diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ReadOnlyPropertyAssignmentInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ReadOnlyPropertyAssignmentInspection.cs index 65ad96bb73..f88af4e98f 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ReadOnlyPropertyAssignmentInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ReadOnlyPropertyAssignmentInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete @@ -129,7 +130,7 @@ protected override string ResultDescription(IdentifierReference reference) { var identifierName = reference.IdentifierName; return string.Format( - InspectionResults.ReadOnlyPropertyAssignmentInspection, identifierName); + InspectionResults.ResourceManager.GetString(nameof(ReadOnlyPropertyAssignmentInspection), CultureInfo.CurrentUICulture), identifierName); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/RedundantByRefModifierInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/RedundantByRefModifierInspection.cs index 875577f770..18c8600f4c 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/RedundantByRefModifierInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/RedundantByRefModifierInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -40,7 +41,7 @@ internal sealed class RedundantByRefModifierInspection : DeclarationInspectionBa { public RedundantByRefModifierInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Parameter) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -66,9 +67,7 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration protected override string ResultDescription(Declaration declaration) { - return string.Format( - InspectionResults.RedundantByRefModifierInspection, - declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(RedundantByRefModifierInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/RedundantOptionInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/RedundantOptionInspection.cs index dc59e8e2b5..474d3e9a44 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/RedundantOptionInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/RedundantOptionInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -48,9 +49,7 @@ public RedundantOptionInspection(IDeclarationFinderProvider declarationFinderPro protected override string ResultDescription(QualifiedContext context) { - return string.Format( - InspectionResults.RedundantOptionInspection, - context.Context.GetText()); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(RedundantOptionInspection), CultureInfo.CurrentUICulture), context.Context.GetText()); } private class RedundantModuleOptionListener : InspectionListenerBase @@ -59,7 +58,7 @@ public override void ExitOptionBaseStmt(VBAParser.OptionBaseStmtContext context) { if (context.numberLiteral()?.INTEGERLITERAL().Symbol.Text == "0") { - SaveContext(context); + SaveContext(context); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/SelfAssignedDeclarationInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/SelfAssignedDeclarationInspection.cs index 2d7a3c37f9..2d68276d44 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/SelfAssignedDeclarationInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/SelfAssignedDeclarationInspection.cs @@ -1,10 +1,11 @@ -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -48,7 +49,7 @@ internal sealed class SelfAssignedDeclarationInspection : DeclarationInspectionB { public SelfAssignedDeclarationInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Variable) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -63,7 +64,7 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.SelfAssignedDeclarationInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(SelfAssignedDeclarationInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/SetAssignmentWithIncompatibleObjectTypeInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/SetAssignmentWithIncompatibleObjectTypeInspection.cs index 57208eb6b5..c4d864c0bb 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/SetAssignmentWithIncompatibleObjectTypeInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/SetAssignmentWithIncompatibleObjectTypeInspection.cs @@ -1,5 +1,4 @@ -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing; using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.Symbols; @@ -8,6 +7,8 @@ using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -93,7 +94,7 @@ protected override (bool isResult, string properties) IsResultReferenceWithAddit var assignedTypeName = AssignedTypeName(reference, finder); - if(assignedTypeName == null || SetAssignmentPossiblyLegal(reference.Declaration, assignedTypeName)) + if (assignedTypeName == null || SetAssignmentPossiblyLegal(reference.Declaration, assignedTypeName)) { return (false, null); } @@ -109,7 +110,7 @@ private static bool ToBeConsidered(IdentifierReference reference) } var declaration = reference.Declaration; - return declaration?.AsTypeDeclaration != null + return declaration?.AsTypeDeclaration != null && declaration.IsObject; } @@ -165,7 +166,7 @@ protected override string ResultDescription(IdentifierReference reference, strin { var declarationName = reference.Declaration.IdentifierName; var variableTypeName = reference.Declaration.FullAsTypeName; - return string.Format(InspectionResults.SetAssignmentWithIncompatibleObjectTypeInspection, declarationName, variableTypeName, assignedTypeName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(SetAssignmentWithIncompatibleObjectTypeInspection), CultureInfo.CurrentUICulture), declarationName, variableTypeName, assignedTypeName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ShadowedDeclarationInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ShadowedDeclarationInspection.cs index cd093dc744..5d3ffe9c6d 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ShadowedDeclarationInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ShadowedDeclarationInspection.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Extensions; using Rubberduck.InternalApi.Extensions; using Rubberduck.Parsing.Symbols; @@ -9,6 +6,10 @@ using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.VBEditor; using Rubberduck.VBEditor.SafeComWrappers; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -55,13 +56,13 @@ private enum DeclarationSite public ShadowedDeclarationInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override IDictionary> GlobalInformation(DeclarationFinder finder) { - return finder.UserDeclarations(DeclarationType.Project) - .OfType() - .ToDictionary(project => project.ProjectId, ReferencedProjectIds); + return finder.UserDeclarations(DeclarationType.Project) + .OfType() + .ToDictionary(project => project.ProjectId, ReferencedProjectIds); } protected override IDictionary> GlobalInformation(QualifiedModuleName module, DeclarationFinder finder) @@ -92,7 +93,7 @@ protected override (bool isResult, Declaration properties) IsResultDeclarationWi return (false, null); } - if(!referencedProjectIdsByProjectId.TryGetValue(userDeclaration.ProjectId, out var referencedProjectIds)) + if (!referencedProjectIdsByProjectId.TryGetValue(userDeclaration.ProjectId, out var referencedProjectIds)) { referencedProjectIds = new HashSet(); } @@ -129,8 +130,8 @@ private static DeclarationSite GetDeclarationSite(Declaration originalDeclaratio { if (originalDeclaration.ProjectId != userDeclaration.ProjectId) { - return referencedProjectIds.Contains(originalDeclaration.ProjectId) - ? DeclarationSite.ReferencedProject + return referencedProjectIds.Contains(originalDeclaration.ProjectId) + ? DeclarationSite.ReferencedProject : DeclarationSite.NotApplicable; } @@ -342,20 +343,20 @@ private static bool DeclarationInTheSameComponentCanBeShadowed(Declaration origi { return DeclarationIsLocal(userDeclaration); } - + // Shadowing between two enumerations or enumeration members is not possible inside one component. - if (((originalDeclaration.DeclarationType == DeclarationType.Enumeration + if (((originalDeclaration.DeclarationType == DeclarationType.Enumeration && userDeclaration.DeclarationType == DeclarationType.EnumerationMember) || (originalDeclaration.DeclarationType == DeclarationType.EnumerationMember && userDeclaration.DeclarationType == DeclarationType.Enumeration))) - { - var originalDeclarationIndex = originalDeclaration.Context.start.StartIndex; - var userDeclarationIndex = userDeclaration.Context.start.StartIndex; + { + var originalDeclarationIndex = originalDeclaration.Context.start.StartIndex; + var userDeclarationIndex = userDeclaration.Context.start.StartIndex; - // First declaration wins - return originalDeclarationIndex > userDeclarationIndex - // Enumeration member can have the same name as enclosing enumeration - && !userDeclaration.Equals(originalDeclaration.ParentDeclaration); + // First declaration wins + return originalDeclarationIndex > userDeclarationIndex + // Enumeration member can have the same name as enclosing enumeration + && !userDeclaration.Equals(originalDeclaration.ParentDeclaration); } // Events don't have a body, so their parameters can't be accessed @@ -364,7 +365,7 @@ private static bool DeclarationInTheSameComponentCanBeShadowed(Declaration origi return false; } - return SameComponentTypeShadowingRelations[originalDeclaration.DeclarationType].Contains(userDeclaration.DeclarationType); + return SameComponentTypeShadowingRelations[originalDeclaration.DeclarationType].Contains(userDeclaration.DeclarationType); } private static bool DeclarationAccessibilityCanBeShadowed(Declaration originalDeclaration) @@ -652,7 +653,7 @@ protected override string ResultDescription(Declaration declaration, Declaration var shadowedDeclarationType = shadowedDeclaration.DeclarationType.ToLocalizedString(); var shadowedDeclarationName = shadowedDeclaration.QualifiedName.ToString(); return string.Format( - Resources.Inspections.InspectionResults.ShadowedDeclarationInspection, + Resources.Inspections.InspectionResults.ResourceManager.GetString(nameof(ShadowedDeclarationInspection), CultureInfo.CurrentUICulture), declarationType, declarationName, shadowedDeclarationType, diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs index a1e98f2cfa..7a488380cd 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Attributes; using Rubberduck.Common; using Rubberduck.Parsing; @@ -12,6 +10,9 @@ using Rubberduck.VBEditor.ComManagement; using Rubberduck.VBEditor.SafeComWrappers; using Rubberduck.VBEditor.SafeComWrappers.Abstract; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -128,15 +129,15 @@ protected override (bool isResult, string properties) IsResultReferenceWithAddit var hostWorkbookDeclaration = GetHostWorkbookDeclaration(finder); - var context = reference.Context as VBAParser.MemberAccessExprContext + var context = reference.Context as VBAParser.MemberAccessExprContext ?? reference.Context.Parent as VBAParser.MemberAccessExprContext ?? reference.Context.Parent.Parent as VBAParser.MemberAccessExprContext; if (context is VBAParser.MemberAccessExprContext memberAccess) { var appObjectDeclaration = GetHostApplicationDeclaration(finder); - var isApplicationQualifier = appObjectDeclaration.References.Any(appRef => - context.GetSelection().Contains(appRef.Selection) + var isApplicationQualifier = appObjectDeclaration.References.Any(appRef => + context.GetSelection().Contains(appRef.Selection) && appRef.QualifiedModuleName.Equals(reference.QualifiedModuleName)); if (isApplicationQualifier) @@ -229,6 +230,7 @@ private static string ComponentPropertyValue(IVBComponent component, string prop return null; } - protected override string ResultDescription(IdentifierReference reference, string codeName) => InspectionResults.SheetAccessedUsingStringInspection; + protected override string ResultDescription(IdentifierReference reference, string codeName) => + InspectionResults.ResourceManager.GetString(nameof(SheetAccessedUsingStringInspection), CultureInfo.CurrentUICulture); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/StepIsNotSpecifiedInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/StepIsNotSpecifiedInspection.cs index d676e2c984..72548f2f09 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/StepIsNotSpecifiedInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/StepIsNotSpecifiedInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -50,7 +51,7 @@ public StepIsNotSpecifiedInspection(IDeclarationFinderProvider declarationFinder protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.StepIsNotSpecifiedInspection; + return InspectionResults.ResourceManager.GetString(nameof(StepIsNotSpecifiedInspection), CultureInfo.CurrentUICulture); } private class StepIsNotSpecifiedListener : InspectionListenerBase diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/StepOneIsRedundantInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/StepOneIsRedundantInspection.cs index e09cddeb38..355be3e659 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/StepOneIsRedundantInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/StepOneIsRedundantInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -50,7 +51,7 @@ public StepOneIsRedundantInspection(IDeclarationFinderProvider declarationFinder protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.StepOneIsRedundantInspection; + return InspectionResults.ResourceManager.GetString(nameof(StepOneIsRedundantInspection), CultureInfo.CurrentUICulture); } private class StepOneIsRedundantListener : InspectionListenerBase diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/StopKeywordInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/StopKeywordInspection.cs index d9e3b67de3..5199c67778 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/StopKeywordInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/StopKeywordInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -47,7 +48,7 @@ public StopKeywordInspection(IDeclarationFinderProvider declarationFinderProvide protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.StopKeywordInspection; + return InspectionResults.ResourceManager.GetString(nameof(StopKeywordInspection), CultureInfo.CurrentUICulture); } private class StopKeywordListener : InspectionListenerBase diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/SuperfluousAnnotationArgumentInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/SuperfluousAnnotationArgumentInspection.cs index b5d9bc2b15..bc2c6f47e4 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/SuperfluousAnnotationArgumentInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/SuperfluousAnnotationArgumentInspection.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Linq; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Results; using Rubberduck.Parsing; @@ -9,6 +7,9 @@ using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -42,7 +43,7 @@ internal sealed class SuperfluousAnnotationArgumentInspection : InspectionBase { public SuperfluousAnnotationArgumentInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override IEnumerable DoGetInspectionResults(DeclarationFinder finder) { @@ -80,7 +81,7 @@ private IInspectionResult InspectionResult(IParseTreeAnnotation pta) private static string ResultDescription(IParseTreeAnnotation pta) { return string.Format( - InspectionResults.SuperfluousAnnotationArgumentInspection, + InspectionResults.ResourceManager.GetString(nameof(SuperfluousAnnotationArgumentInspection), CultureInfo.CurrentUICulture), pta.Annotation.Name); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/SuspiciousLetAssignmentInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/SuspiciousLetAssignmentInspection.cs index 59479b8286..f78e5bced5 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/SuspiciousLetAssignmentInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/SuspiciousLetAssignmentInspection.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Extensions; using Rubberduck.CodeAnalysis.Inspections.Results; using Rubberduck.Parsing; @@ -10,6 +8,9 @@ using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -126,7 +127,7 @@ private bool IsImplicitDefaultMemberAssignment(IdentifierReference reference) private IInspectionResult InspectionResult(IdentifierReference lhsReference, IdentifierReference rhsReference, bool isUnbound, DeclarationFinder finder) { var disabledQuickFixes = isUnbound - ? new List {"ExpandDefaultMemberQuickFix"} + ? new List { "ExpandDefaultMemberQuickFix" } : new List(); return new IdentifierReferenceInspectionResult( this, @@ -141,7 +142,7 @@ private string ResultDescription(IdentifierReference lhsReference, IdentifierRef { var lhsExpression = lhsReference.IdentifierName; var rhsExpression = rhsReference.IdentifierName; - return string.Format(InspectionResults.SuspiciousLetAssignmentInspection, lhsExpression, rhsExpression); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(SuspiciousLetAssignmentInspection), CultureInfo.CurrentUICulture), lhsExpression, rhsExpression); } private IEnumerable UnboundLhsInspectionResults(QualifiedModuleName module, DeclarationFinder finder) diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/SuspiciousPredeclaredInstanceAccessInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/SuspiciousPredeclaredInstanceAccessInspection.cs index 4d02e070bd..53be460197 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/SuspiciousPredeclaredInstanceAccessInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/SuspiciousPredeclaredInstanceAccessInspection.cs @@ -5,6 +5,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; using Tokens = Rubberduck.Resources.Tokens; namespace Rubberduck.CodeAnalysis.Inspections.Concrete @@ -75,15 +76,15 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete /// internal sealed class SuspiciousPredeclaredInstanceAccessInspection : IdentifierReferenceInspectionBase { - public SuspiciousPredeclaredInstanceAccessInspection(IDeclarationFinderProvider declarationFinderProvider) + public SuspiciousPredeclaredInstanceAccessInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) { } protected override bool IsResultReference(IdentifierReference reference, DeclarationFinder finder) { - return - reference.Declaration is ClassModuleDeclaration module && + return + reference.Declaration is ClassModuleDeclaration module && module.HasPredeclaredId && reference.ParentScoping.ParentDeclaration.Equals(module) && reference.Context.TryGetAncestor(out var expression) && @@ -93,7 +94,7 @@ reference.Declaration is ClassModuleDeclaration module && protected override string ResultDescription(IdentifierReference reference) { reference.Context.TryGetAncestor(out var expression); - return string.Format(InspectionResults.SuspiciousPredeclaredInstanceAccessInspection, reference.IdentifierName, expression.GetText()); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(SuspiciousPredeclaredInstanceAccessInspection), CultureInfo.CurrentUICulture), reference.IdentifierName, expression.GetText()); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/KeywordsUsedAsMemberInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/KeywordsUsedAsMemberInspection.cs index b80fb257e8..b48eaa2fd3 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/KeywordsUsedAsMemberInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/KeywordsUsedAsMemberInspection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.InternalApi.Extensions; using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete.ThunderCode { @@ -23,7 +24,7 @@ internal sealed class KeywordsUsedAsMemberInspection : DeclarationInspectionBase { public KeywordsUsedAsMemberInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.EnumerationMember, DeclarationType.UserDefinedTypeMember) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -33,11 +34,11 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration protected override string ResultDescription(Declaration declaration) { - return InspectionResults.KeywordsUsedAsMemberInspection.ThunderCodeFormat(declaration.IdentifierName); + return InspectionResults.ResourceManager.GetString("KeywordsUsedAsMemberInspection", CultureInfo.CurrentUICulture).ThunderCodeFormat(declaration.IdentifierName); } // MS-VBAL 3.3.5.2 Reserved Identifiers and IDENTIFIER - private static readonly IEnumerable ReservedKeywords = new [] + private static readonly IEnumerable ReservedKeywords = new[] { /* Statement-keyword = "Call" / "Case" /"Close" / "Const"/ "Declare" / "DefBool" / "DefByte" / diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/LineContinuationBetweenKeywordsInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/LineContinuationBetweenKeywordsInspection.cs index 575e726ab5..112b21e3d8 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/LineContinuationBetweenKeywordsInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/LineContinuationBetweenKeywordsInspection.cs @@ -5,6 +5,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete.ThunderCode { @@ -32,7 +33,7 @@ public LineContinuationBetweenKeywordsInspection(IDeclarationFinderProvider decl protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.LineContinuationBetweenKeywordsInspection.ThunderCodeFormat(); + return InspectionResults.ResourceManager.GetString("LineContinuationBetweenKeywordsInspection", CultureInfo.CurrentUICulture).ThunderCodeFormat(); } private class LineContinuationBetweenKeywordsListener : InspectionListenerBase diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/NegativeLineNumberInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/NegativeLineNumberInspection.cs index 76c391197a..4bf5b0a47d 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/NegativeLineNumberInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/NegativeLineNumberInspection.cs @@ -1,5 +1,4 @@ -using System.Linq; -using Antlr4.Runtime; +using Antlr4.Runtime; using Antlr4.Runtime.Tree; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing; @@ -8,6 +7,8 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete.ThunderCode { @@ -31,12 +32,12 @@ public NegativeLineNumberInspection(IDeclarationFinderProvider declarationFinder protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.NegativeLineNumberInspection.ThunderCodeFormat(); + return InspectionResults.ResourceManager.GetString("NegativeLineNumberInspection", CultureInfo.CurrentUICulture).ThunderCodeFormat(); } protected override bool IsResultContext(QualifiedContext context, DeclarationFinder finder) { - return !IsOnErrorGotoMinusOne(context.Context) + return !IsOnErrorGotoMinusOne(context.Context) || ProcedureHasMinusOneLabel(finder, context); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/NonBreakingSpaceIdentifierInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/NonBreakingSpaceIdentifierInspection.cs index 4987df727c..ca806acab7 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/NonBreakingSpaceIdentifierInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/NonBreakingSpaceIdentifierInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete.ThunderCode { @@ -14,13 +15,16 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete.ThunderCode /// code our friend Andrew Jackson would have written to confuse Rubberduck's parser and/or resolver. /// This inspection may accidentally reveal non-breaking spaces in code copied and pasted from a website. /// + /// + /// You may have discovered this inspection by pasting code directly from a web page, which often contains such non-printable characters. + /// internal sealed class NonBreakingSpaceIdentifierInspection : DeclarationInspectionBase { private const string Nbsp = "\u00A0"; public NonBreakingSpaceIdentifierInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -29,7 +33,7 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration protected override string ResultDescription(Declaration declaration) { - return InspectionResults.NonBreakingSpaceIdentifierInspection.ThunderCodeFormat(declaration.IdentifierName); + return InspectionResults.ResourceManager.GetString("NonBreakingSpaceIdentifierInspection", CultureInfo.CurrentUICulture).ThunderCodeFormat(declaration.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/OnErrorGoToMinusOneInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/OnErrorGoToMinusOneInspection.cs index 81b1dc4a98..d1f436f130 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/OnErrorGoToMinusOneInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/OnErrorGoToMinusOneInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete.ThunderCode { @@ -27,7 +28,7 @@ public OnErrorGoToMinusOneInspection(IDeclarationFinderProvider declarationFinde protected override string ResultDescription(QualifiedContext context) { - return InspectionResults.OnErrorGoToMinusOneInspection.ThunderCodeFormat(); + return InspectionResults.ResourceManager.GetString("OnErrorGoToMinusOneInspection", CultureInfo.CurrentUICulture).ThunderCodeFormat(); } private class OnErrorGoToMinusOneListener : InspectionListenerBase @@ -37,13 +38,13 @@ public override void EnterOnErrorStmt(VBAParser.OnErrorStmtContext context) CheckContext(context, context.expression()); base.EnterOnErrorStmt(context); } - + private void CheckContext(VBAParser.OnErrorStmtContext context, IParseTree expression) { var target = expression?.GetText().Trim() ?? string.Empty; if (target.StartsWith("-") && int.TryParse(target.Substring(1), out var result) && result == 1) { - SaveContext(context); + SaveContext(context); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/ThunderCodeFormatExtension.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/ThunderCodeFormatExtension.cs index b5ff336283..77c16b6179 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/ThunderCodeFormatExtension.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ThunderCode/ThunderCodeFormatExtension.cs @@ -1,4 +1,5 @@ using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete.ThunderCode { @@ -6,7 +7,7 @@ internal static class ThunderCodeFormatExtension { public static string ThunderCodeFormat(this string inspectionBase, params object[] args) { - return string.Format(InspectionResults.ThunderCode_Base, string.Format(inspectionBase, args)); + return string.Format(InspectionResults.ResourceManager.GetString("ThunderCode_Base", CultureInfo.CurrentUICulture), string.Format(inspectionBase, args)); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/UDTMemberNotUsedInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/UDTMemberNotUsedInspection.cs index 9857359cdd..92ed528fc3 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/UDTMemberNotUsedInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/UDTMemberNotUsedInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete @@ -62,7 +63,7 @@ internal sealed class UDTMemberNotUsedInspection : DeclarationInspectionBase { public UDTMemberNotUsedInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.UserDefinedTypeMember) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -75,7 +76,7 @@ protected override string ResultDescription(Declaration declaration) var declarationType = declaration.DeclarationType.ToLocalizedString(); var declarationName = declaration.IdentifierName; return string.Format( - InspectionResults.IdentifierNotUsedInspection, + InspectionResults.ResourceManager.GetString(nameof(InspectionResults.IdentifierNotUsedInspection), CultureInfo.CurrentUICulture), declarationType, declarationName); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/UnassignedVariableUsageInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/UnassignedVariableUsageInspection.cs index a6cae19f80..47c298853b 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/UnassignedVariableUsageInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/UnassignedVariableUsageInspection.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Linq; using Antlr4.Runtime.Misc; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.InternalApi.Extensions; @@ -11,6 +8,11 @@ using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -50,7 +52,7 @@ internal sealed class UnassignedVariableUsageInspection : IdentifierReferenceIns { public UnassignedVariableUsageInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } //See https://github.com/rubberduck-vba/Rubberduck/issues/2010 for why these are being excluded. private static readonly List IgnoredFunctions = new List @@ -68,6 +70,7 @@ protected override IEnumerable ObjectionableDeclarations(Declaratio && !declaration.IsSelfAssigned && finder.MatchName(declaration.AsTypeName) .All(d => d.DeclarationType != DeclarationType.UserDefinedType) + && !declaration.IdentifierName.StartsWith("out", StringComparison.InvariantCultureIgnoreCase) && !declaration.References .Any(reference => reference.IsAssignment) && !declaration.References @@ -136,7 +139,7 @@ private static IEnumerable SingleVariableArgumentSelections( protected override bool IsResultReference(IdentifierReference reference, DeclarationFinder finder) { return reference != null - && !IsArraySubscriptAssignment(reference) + && !IsArraySubscriptAssignment(reference) && !IsArrayReDim(reference); } @@ -144,7 +147,7 @@ protected override string ResultDescription(IdentifierReference reference) { var identifierName = reference.IdentifierName; return string.Format( - InspectionResults.UnassignedVariableUsageInspection, + InspectionResults.ResourceManager.GetString(nameof(UnassignedVariableUsageInspection), CultureInfo.CurrentUICulture), identifierName); } @@ -190,7 +193,7 @@ private static bool IsArraySubscriptAssignment(IdentifierReference reference) var callingExpression = indexExpression.Parent; - return callingExpression is VBAParser.SetStmtContext + return callingExpression is VBAParser.SetStmtContext || callingExpression is VBAParser.LetStmtContext; } @@ -215,7 +218,7 @@ private bool IsRedimedVariantArrayReference(IdentifierReference reference) return false; } - if(!reference.Context.TryGetAncestor(out var containingMember)) + if (!reference.Context.TryGetAncestor(out var containingMember)) { return false; } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/UndeclaredVariableInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/UndeclaredVariableInspection.cs index debadc340d..280a9a0706 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/UndeclaredVariableInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/UndeclaredVariableInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -37,7 +38,7 @@ internal sealed class UndeclaredVariableInspection : DeclarationInspectionBase { public UndeclaredVariableInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Variable) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -46,7 +47,7 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.UndeclaredVariableInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(UndeclaredVariableInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/UnderscoreInPublicClassModuleMemberInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/UnderscoreInPublicClassModuleMemberInspection.cs index 739a0543f0..206d568105 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/UnderscoreInPublicClassModuleMemberInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/UnderscoreInPublicClassModuleMemberInspection.cs @@ -3,6 +3,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -37,13 +38,13 @@ internal sealed class UnderscoreInPublicClassModuleMemberInspection : Declaratio { public UnderscoreInPublicClassModuleMemberInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Member) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { - return declaration.IdentifierName.Contains("_") - && (declaration.Accessibility == Accessibility.Public - || declaration.Accessibility == Accessibility.Implicit) + return declaration.IdentifierName.Contains("_") + && (declaration.Accessibility == Accessibility.Public + || declaration.Accessibility == Accessibility.Implicit) && declaration.ParentDeclaration.DeclarationType.HasFlag(DeclarationType.ClassModule) && !finder.FindEventHandlers().Contains(declaration) && !(declaration is ModuleBodyElementDeclaration member && member.IsInterfaceImplementation); @@ -51,7 +52,7 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.UnderscoreInPublicClassModuleMemberInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(UnderscoreInPublicClassModuleMemberInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/UnhandledOnErrorResumeNextInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/UnhandledOnErrorResumeNextInspection.cs index d1888fe94c..91b3f19a9b 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/UnhandledOnErrorResumeNextInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/UnhandledOnErrorResumeNextInspection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing; using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -45,13 +46,13 @@ internal sealed class UnhandledOnErrorResumeNextInspection : ParseTreeInspection public UnhandledOnErrorResumeNextInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } protected override IInspectionListener ContextListener => _listener; protected override string ResultDescription(QualifiedContext context, IReadOnlyList properties) { - return InspectionResults.UnhandledOnErrorResumeNextInspection; + return InspectionResults.ResourceManager.GetString(nameof(UnhandledOnErrorResumeNextInspection), CultureInfo.CurrentUICulture); } protected override (bool isResult, IReadOnlyList properties) IsResultContextWithAdditionalProperties(QualifiedContext context, DeclarationFinder finder) diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/UnreachableCaseInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/UnreachableCaseInspection.cs index 9e4a45e64b..4685ed1991 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/UnreachableCaseInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/UnreachableCaseInspection.cs @@ -1,9 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Antlr4.Runtime; +using Antlr4.Runtime; using Antlr4.Runtime.Misc; using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Concrete.UnreachableCaseEvaluation; using Rubberduck.CodeAnalysis.Inspections.Extensions; using Rubberduck.CodeAnalysis.Inspections.Results; using Rubberduck.Parsing; @@ -14,7 +12,10 @@ using Rubberduck.Parsing.VBA.Parsing; using Rubberduck.Resources.Inspections; using Rubberduck.VBEditor; -using Rubberduck.CodeAnalysis.Inspections.Concrete.UnreachableCaseEvaluation; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -136,10 +137,16 @@ public enum CaseInspectionResultType CaseElse } + public UnreachableCaseInspection(IDeclarationFinderProvider declarationFinderProvider) + : this(declarationFinderProvider, null, null) + { + /* for reflection / default settings */ + } + public UnreachableCaseInspection( - IDeclarationFinderProvider declarationFinderProvider, - IUnreachableCaseInspector inspector, - IParseTreeValueVisitor parseTreeValueVisitor) + IDeclarationFinderProvider declarationFinderProvider, + IUnreachableCaseInspector inspector, + IParseTreeValueVisitor parseTreeValueVisitor) : base(declarationFinderProvider) { _inspector = inspector; @@ -194,15 +201,15 @@ private static string ResultMessage(CaseInspectionResultType resultType) switch (resultType) { case CaseInspectionResultType.Unreachable: - return InspectionResults.UnreachableCaseInspection_Unreachable; + return InspectionResults.ResourceManager.GetString(nameof(InspectionResults.UnreachableCaseInspection_Unreachable), CultureInfo.CurrentUICulture); case CaseInspectionResultType.InherentlyUnreachable: - return InspectionResults.UnreachableCaseInspection_InherentlyUnreachable; + return InspectionResults.ResourceManager.GetString(nameof(InspectionResults.UnreachableCaseInspection_InherentlyUnreachable), CultureInfo.CurrentUICulture); case CaseInspectionResultType.MismatchType: - return InspectionResults.UnreachableCaseInspection_TypeMismatch; + return InspectionResults.ResourceManager.GetString(nameof(InspectionResults.UnreachableCaseInspection_TypeMismatch), CultureInfo.CurrentUICulture); case CaseInspectionResultType.Overflow: - return InspectionResults.UnreachableCaseInspection_Overflow; + return InspectionResults.ResourceManager.GetString(nameof(InspectionResults.UnreachableCaseInspection_Overflow), CultureInfo.CurrentUICulture); case CaseInspectionResultType.CaseElse: - return InspectionResults.UnreachableCaseInspection_CaseElse; + return InspectionResults.ResourceManager.GetString(nameof(InspectionResults.UnreachableCaseInspection_CaseElse), CultureInfo.CurrentUICulture); default: throw new ArgumentOutOfRangeException(nameof(resultType), resultType, null); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/UnrecognizedAnnotationInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/UnrecognizedAnnotationInspection.cs new file mode 100644 index 0000000000..26e129a6e5 --- /dev/null +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/UnrecognizedAnnotationInspection.cs @@ -0,0 +1,54 @@ +using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.Parsing.Annotations; +using Rubberduck.Parsing.Symbols; +using Rubberduck.Parsing.VBA; +using Rubberduck.Resources.Inspections; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; + +namespace Rubberduck.CodeAnalysis.Inspections.Concrete +{ + /// + /// Flags comments that parsed like Rubberduck annotations, but were not recognized as such. + /// + /// + /// Other add-ins may support similar-looking annotations that Rubberduck does not recognize; this inspection can be used to spot a typo in Rubberduck annotations. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + internal sealed class UnrecognizedAnnotationInspection : InvalidAnnotationInspectionBase + { + public UnrecognizedAnnotationInspection(IDeclarationFinderProvider declarationFinderProvider) + : base(declarationFinderProvider) { } + + protected override IEnumerable GetInvalidAnnotations( + IEnumerable annotations, + IEnumerable userDeclarations, + IEnumerable identifierReferences) + { + return annotations.Where(pta => pta.Annotation is NotRecognizedAnnotation).ToList(); + } + + protected override string ResultDescription(IParseTreeAnnotation pta) => + string.Format(InspectionResults.ResourceManager.GetString(nameof(UnrecognizedAnnotationInspection), CultureInfo.CurrentUICulture), pta.Context.GetText()); + } +} \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/UntypedFunctionUsageInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/UntypedFunctionUsageInspection.cs index bf32b7a867..73e3e119e9 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/UntypedFunctionUsageInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/UntypedFunctionUsageInspection.cs @@ -1,11 +1,12 @@ -using System.Collections.Generic; -using System.Linq; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -38,7 +39,7 @@ internal sealed class UntypedFunctionUsageInspection : IdentifierReferenceInspec { public UntypedFunctionUsageInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider) - {} + { } private readonly HashSet _tokens = new HashSet{ Tokens.Error, @@ -75,7 +76,7 @@ private IEnumerable BuiltInVariantStringFunctionsWithStringTypedVer { return finder .BuiltInDeclarations(DeclarationType.Member) - .Where(item => item.Scope.StartsWith("VBE7.DLL;") + .Where(item => item.Scope.StartsWith("VBE7.DLL;") && (_tokens.Contains(item.IdentifierName) || item.IdentifierName.StartsWith("_B_var_") && _tokens.Contains(item.IdentifierName.Substring("_B_var_".Length)))); @@ -85,7 +86,7 @@ protected override string ResultDescription(IdentifierReference reference) { var declarationName = reference.Declaration.IdentifierName; return string.Format( - InspectionResults.UntypedFunctionUsageInspection, + InspectionResults.ResourceManager.GetString(nameof(UntypedFunctionUsageInspection), CultureInfo.CurrentUICulture), declarationName); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/UseMeaningfulNameInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/UseMeaningfulNameInspection.cs index 9a4d450541..4ca574b2e6 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/UseMeaningfulNameInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/UseMeaningfulNameInspection.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Extensions; using Rubberduck.CodeAnalysis.Settings; using Rubberduck.Parsing.Grammar; @@ -9,6 +7,9 @@ using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Refactorings.Common; using Rubberduck.SettingsProvider; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -47,11 +48,11 @@ public UseMeaningfulNameInspection(IDeclarationFinderProvider declarationFinderP _settings = settings; } - private static readonly DeclarationType[] IgnoreDeclarationTypes = + private static readonly DeclarationType[] IgnoreDeclarationTypes = { - DeclarationType.BracketedExpression, + DeclarationType.BracketedExpression, DeclarationType.LibraryFunction, - DeclarationType.LibraryProcedure, + DeclarationType.LibraryProcedure, }; protected override string[] GlobalInformation(DeclarationFinder finder) @@ -79,7 +80,7 @@ protected override string ResultDescription(Declaration declaration) var declarationType = declaration.DeclarationType.ToLocalizedString(); var declarationName = declaration.IdentifierName; return string.Format( - Resources.Inspections.InspectionResults.IdentifierNameInspection, + Resources.Inspections.InspectionResults.ResourceManager.GetString(nameof(Resources.Inspections.InspectionResults.IdentifierNameInspection), CultureInfo.CurrentUICulture), declarationType, declarationName); } @@ -89,7 +90,7 @@ protected override ICollection DisabledQuickFixes(Declaration declaratio return declaration.DeclarationType.HasFlag(DeclarationType.Module) || declaration.DeclarationType.HasFlag(DeclarationType.Project) || declaration.DeclarationType.HasFlag(DeclarationType.Control) - ? new List {nameof(QuickFixes.Concrete.IgnoreOnceQuickFix)} + ? new List { nameof(QuickFixes.Concrete.IgnoreOnceQuickFix) } : new List(); } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/UseOfBangNotationInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/UseOfBangNotationInspection.cs index a60f47dd47..04270251e9 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/UseOfBangNotationInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/UseOfBangNotationInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -80,7 +81,7 @@ protected override bool IsResultReference(IdentifierReference reference, Declara protected override string ResultDescription(IdentifierReference reference) { var expression = reference.IdentifierName; - return string.Format(InspectionResults.UseOfBangNotationInspection, expression); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(UseOfBangNotationInspection), CultureInfo.CurrentUICulture), expression); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/UseOfRecursiveBangNotationInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/UseOfRecursiveBangNotationInspection.cs index 3deb5e6004..588a0a42aa 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/UseOfRecursiveBangNotationInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/UseOfRecursiveBangNotationInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -90,7 +91,7 @@ protected override bool IsResultReference(IdentifierReference reference, Declara protected override string ResultDescription(IdentifierReference reference) { var expression = reference.IdentifierName; - return string.Format(InspectionResults.UseOfRecursiveBangNotationInspection, expression); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(UseOfRecursiveBangNotationInspection), CultureInfo.CurrentUICulture), expression); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/UseOfUnboundBangNotationInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/UseOfUnboundBangNotationInspection.cs index 3da28ab22f..f9f6ee21ef 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/UseOfUnboundBangNotationInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/UseOfUnboundBangNotationInspection.cs @@ -1,11 +1,12 @@ -using System.Collections.Generic; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +using Rubberduck.CodeAnalysis.Inspections.Abstract; 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 System.Collections.Generic; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -87,7 +88,7 @@ protected override bool IsResultReference(IdentifierReference reference, Declara protected override string ResultDescription(IdentifierReference reference) { var expression = reference.IdentifierName; - return string.Format(InspectionResults.UseOfRecursiveBangNotationInspection, expression); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(UseOfRecursiveBangNotationInspection), CultureInfo.CurrentUICulture), expression); } } } \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/ValueRequiredInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/ValueRequiredInspection.cs index 24004c3bb5..a3c1200884 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/ValueRequiredInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/ValueRequiredInspection.cs @@ -1,10 +1,11 @@ -using System.Collections.Generic; -using Rubberduck.CodeAnalysis.Inspections.Abstract; +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 System.Collections.Generic; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -77,7 +78,7 @@ protected override string ResultDescription(IdentifierReference failedLetCoercio { var expression = failedLetCoercion.IdentifierName; var typeName = failedLetCoercion.Declaration?.FullAsTypeName; - return string.Format(InspectionResults.ValueRequiredInspection, expression, typeName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(ValueRequiredInspection), CultureInfo.CurrentUICulture), expression, typeName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/VariableNotAssignedInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/VariableNotAssignedInspection.cs index a24942a16a..3a5663d3f5 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/VariableNotAssignedInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/VariableNotAssignedInspection.cs @@ -1,4 +1,3 @@ -using System.Linq; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.Parsing; using Rubberduck.Parsing.Grammar; @@ -6,6 +5,8 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -42,7 +43,7 @@ internal sealed class VariableNotAssignedInspection : DeclarationInspectionBase { public VariableNotAssignedInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Variable) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { @@ -51,7 +52,7 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration && !declaration.IsWithEvents && !declaration.IsSelfAssigned && !HasUdtType(declaration, finder) // UDT variables don't need to be assigned - && !declaration.References.Any(reference => reference.IsAssignment + && !declaration.References.Any(reference => reference.IsAssignment || reference.IsReDim //Ignores Variants used as arrays without assignment of an existing one. || IsAssignedByRefArgument(reference.ParentScoping, reference, finder)) && !IsPublicInExposedClass(declaration); @@ -113,7 +114,7 @@ private static VBAParser.ArgumentExpressionContext ImmediateArgumentExpressionCo protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.VariableNotAssignedInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(VariableNotAssignedInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/VariableNotUsedInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/VariableNotUsedInspection.cs index 03827a1836..e164a109aa 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/VariableNotUsedInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/VariableNotUsedInspection.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Linq; using Antlr4.Runtime; using Rubberduck.CodeAnalysis.Inspections.Abstract; using Rubberduck.CodeAnalysis.Inspections.Extensions; @@ -10,6 +8,8 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -49,12 +49,12 @@ internal sealed class VariableNotUsedInspection : DeclarationInspectionBase /// public VariableNotUsedInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.Variable) - {} + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { // exclude undeclared, see #5439 - return !declaration.IsWithEvents + return !declaration.IsWithEvents && !declaration.IsUndeclared && declaration.References.All(reference => reference.IsAssignment) && !declaration.References.Any(IsForLoopAssignment) @@ -79,7 +79,7 @@ private static bool IsPublicInExposedClass(Declaration procedure) private bool IsForLoopAssignment(IdentifierReference reference) { - if(!reference.IsAssignment) + if (!reference.IsAssignment) { return false; } @@ -104,8 +104,8 @@ protected override string ResultDescription(Declaration declaration) var declarationType = declaration.DeclarationType.ToLocalizedString(); var declarationName = declaration.IdentifierName; return string.Format( - InspectionResults.IdentifierNotUsedInspection, - declarationType, + InspectionResults.ResourceManager.GetString(nameof(InspectionResults.IdentifierNotUsedInspection), CultureInfo.CurrentUICulture), + declarationType, declarationName); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/VariableTypeNotDeclaredInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/VariableTypeNotDeclaredInspection.cs index 3e0850cff4..1a5ee4fbd2 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/VariableTypeNotDeclaredInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/VariableTypeNotDeclaredInspection.cs @@ -4,6 +4,7 @@ using Rubberduck.Parsing.VBA; using Rubberduck.Parsing.VBA.DeclarationCaching; using Rubberduck.Resources.Inspections; +using System.Globalization; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -38,14 +39,14 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete internal sealed class VariableTypeNotDeclaredInspection : ImplicitTypeInspectionBase { public VariableTypeNotDeclaredInspection(IDeclarationFinderProvider declarationFinderProvider) - : base(declarationFinderProvider, new []{DeclarationType.Parameter, DeclarationType.Variable}, new[]{DeclarationType.Control}) - {} + : base(declarationFinderProvider, new[] { DeclarationType.Parameter, DeclarationType.Variable }, new[] { DeclarationType.Control }) + { } protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) { return base.IsResultDeclaration(declaration, finder) && !declaration.IsUndeclared - && (declaration.DeclarationType != DeclarationType.Parameter + && (declaration.DeclarationType != DeclarationType.Parameter || declaration is ParameterDeclaration parameter && !parameter.IsParamArray); } @@ -54,7 +55,7 @@ protected override string ResultDescription(Declaration declaration) var declarationType = declaration.DeclarationType.ToLocalizedString(); var declarationName = declaration.IdentifierName; return string.Format( - InspectionResults.ImplicitVariantDeclarationInspection, + InspectionResults.ResourceManager.GetString(nameof(InspectionResults.ImplicitVariantDeclarationInspection), CultureInfo.CurrentUICulture), declarationType, declarationName); } diff --git a/Rubberduck.CodeAnalysis/Inspections/Concrete/WriteOnlyPropertyInspection.cs b/Rubberduck.CodeAnalysis/Inspections/Concrete/WriteOnlyPropertyInspection.cs index 7267a9b1dc..23c6d4ae3a 100644 --- a/Rubberduck.CodeAnalysis/Inspections/Concrete/WriteOnlyPropertyInspection.cs +++ b/Rubberduck.CodeAnalysis/Inspections/Concrete/WriteOnlyPropertyInspection.cs @@ -1,11 +1,12 @@ -using System.Collections.Generic; -using System.Linq; 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 System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace Rubberduck.CodeAnalysis.Inspections.Concrete { @@ -46,7 +47,7 @@ internal sealed class WriteOnlyPropertyInspection : DeclarationInspectionBase { public WriteOnlyPropertyInspection(IDeclarationFinderProvider declarationFinderProvider) : base(declarationFinderProvider, DeclarationType.PropertyLet, DeclarationType.PropertySet) { } - + protected override IEnumerable DoGetInspectionResults(QualifiedModuleName module, DeclarationFinder finder) { var setters = RelevantDeclarationsInModule(module, finder) @@ -71,7 +72,7 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration protected override string ResultDescription(Declaration declaration) { - return string.Format(InspectionResults.WriteOnlyPropertyInspection, declaration.IdentifierName); + return string.Format(InspectionResults.ResourceManager.GetString(nameof(WriteOnlyPropertyInspection), CultureInfo.CurrentUICulture), declaration.IdentifierName); } } } diff --git a/Rubberduck.CodeAnalysis/Properties/CodeInspectionDefaults.Designer.cs b/Rubberduck.CodeAnalysis/Properties/CodeInspectionDefaults.Designer.cs index 8a159534e8..c9be4d29e2 100644 --- a/Rubberduck.CodeAnalysis/Properties/CodeInspectionDefaults.Designer.cs +++ b/Rubberduck.CodeAnalysis/Properties/CodeInspectionDefaults.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// Este código fue generado por una herramienta. -// Versión de runtime:4.0.30319.42000 +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 // -// Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si -// se vuelve a generar el código. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. // //------------------------------------------------------------------------------ @@ -12,7 +12,7 @@ namespace Rubberduck.CodeAnalysis.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.12.0.0")] public sealed partial class CodeInspectionDefaults : global::System.Configuration.ApplicationSettingsBase { private static CodeInspectionDefaults defaultInstance = ((CodeInspectionDefaults)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new CodeInspectionDefaults()))); @@ -25,129 +25,211 @@ public static CodeInspectionDefaults Default { [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n " + - " \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n " + - "\r\n \r\n \r\n \r\n \r\n " + - " \r\n " + - "\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n <" + - "CodeInspection Name=\"SelfAssignedDeclarationInspection\" Severity=\"Suggestion\" In" + - "spectionType=\"CodeQualityIssues\" />\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n " + + " \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n " + + " \r\n \r\n \r\n \r\n" + + " \r\n \r\n " + + " \r\n \r\n " + + " \r\n \r\n \r\n \r\n " + + " \r\n \r\n \r\n \r\n " + + " \r\n \r\n \r\n " + + " \r\n \r\n " + + " \r\n \r\n \r\n \r\n \r\n \r\n \r\n <" + + "CodeInspection Name=\"ImplicitPublicMemberInspection\" Severity=\"Hint\" InspectionT" + + "ype=\"NamingAndConventionsIssues\" />\r\n \r\n " + + "\r\n \r\n \r\n \r\n " + + " \r\n \r\n \r\n " + + "\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n " + + " \r\n \r\n \r\n " + + " \r\n \r\n \r\n \r\n \r\n <" + - "CodeInspection Name=\"AssignmentNotUsedInspection\" Severity=\"Suggestion\" Inspecti" + - "onType=\"CodeQualityIssues\" />\r\n " + - "\r\n \r\n \r\n " + - " \r\n \r\n \r\n \r\n true\r\n")] + "duckOpportunities\" />\r\n \r\n \r\n \r\n \r\n " + + " \r\n \r\n \r\n \r\n \r\n " + + " \r\n \r\n \r\n " + + " \r\n \r\n \r\n " + + " \r\n \r\n \r\n " + + " \r\n \r\n " + + " \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n " + + " \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n " + + " \r\n \r\n \r\n " + + "\r\n \r\n " + + " \r\n \r\n \r\n " + + " \r\n \r\n \r\n \r\n \r\n \r\n " + + " \r\n \r\n " + + " \r\n \r\n \r\n \r\n \r\n true\r\n true\r\n " + + " \r\n ")] public global::Rubberduck.CodeAnalysis.Settings.CodeInspectionSettings CodeInspectionSettings { get { return ((global::Rubberduck.CodeAnalysis.Settings.CodeInspectionSettings)(this["CodeInspectionSettings"])); diff --git a/Rubberduck.CodeAnalysis/Properties/CodeInspectionDefaults.settings b/Rubberduck.CodeAnalysis/Properties/CodeInspectionDefaults.settings index 2112d95f10..e4e74c75ba 100644 --- a/Rubberduck.CodeAnalysis/Properties/CodeInspectionDefaults.settings +++ b/Rubberduck.CodeAnalysis/Properties/CodeInspectionDefaults.settings @@ -3,92 +3,136 @@ - <?xml version="1.0" encoding="utf-16"?> -<CodeInspectionSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> - <CodeInspections> - <CodeInspection Name="BooleanAssignedInIfElseInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="ObsoleteErrorSyntaxInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="StopKeywordInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="UnhandledOnErrorResumeNextInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="EmptyStringLiteralInspection" Severity="Warning" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="ImplicitByRefModifierInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="FunctionReturnValueNotUsedInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="RedundantByRefModifierInspection" Severity="DoNotShow" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="MissingAttributeInspection" Severity="Warning" InspectionType="RubberduckOpportunities" /> - <CodeInspection Name="AttributeOutOfSyncInspection" Severity="Warning" InspectionType="RubberduckOpportunities" /> - <CodeInspection Name="MissingAnnotationArgumentInspection" Severity="Error" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="ModuleScopeDimKeywordInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="MultilineParameterInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="MultipleDeclarationsInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="ObsoleteCallStatementInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="ObsoleteCommentSyntaxInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="ObsoleteLetStatementInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="OptionBaseInspection" Severity="Hint" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="RedundantOptionInspection" Severity="Hint" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="OptionExplicitInspection" Severity="Error" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="ProcedureCanBeWrittenAsFunctionInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="ApplicationWorksheetFunctionInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="AssignedByValParameterInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="EmptyModuleInspection" Severity="Hint" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="LineLabelNotUsedInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="IntegerDataTypeInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="ShadowedDeclarationInspection" Severity="DoNotShow" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="ConstantNotUsedInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="DefaultProjectNameInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="EmptyCaseBlockInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="EmptyDoWhileBlockInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="EmptyElseBlockInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="EmptyForEachBlockInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="EmptyForLoopBlockInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="EmptyIfBlockInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="EmptyWhileWendBlockInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="EncapsulatePublicFieldInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="HostSpecificExpressionInspection" Severity="Warning" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="HungarianNotationInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="ImplicitActiveSheetReferenceInspection" Severity="Warning" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="ImplicitActiveWorkbookReferenceInspection" Severity="Warning" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="ImplicitDefaultMemberAssignmentInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="ImplicitPublicMemberInspection" Severity="Hint" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="ImplicitVariantReturnTypeInspection" Severity="Hint" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="MemberNotOnInterfaceInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="MoveFieldCloserToUsageInspection" Severity="Hint" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="NonReturningFunctionInspection" Severity="Error" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="ObjectVariableNotSetInspection" Severity="Error" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="ObsoleteGlobalInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="ObsoleteTypeHintInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="ParameterCanBeByValInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="ParameterNotUsedInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="ProcedureNotUsedInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="SelfAssignedDeclarationInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="UnassignedVariableUsageInspection" Severity="Error" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="UndeclaredVariableInspection" Severity="Error" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="UntypedFunctionUsageInspection" Severity="Hint" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="UseMeaningfulNameInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="VariableNotAssignedInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="VariableNotUsedInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="VariableTypeNotDeclaredInspection" Severity="Warning" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="WriteOnlyPropertyInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="DefTypeStatementInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="StepIsNotSpecifiedInspection" Severity="DoNotShow" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="StepOneIsRedundantInspection" Severity="Hint" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="SheetAccessedUsingStringInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="ObsoleteMemberUsageInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> - <CodeInspection Name="ObsoleteCallingConventionInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="DuplicatedAnnotationInspection" Severity="Error" InspectionType="RubberduckOpportunities" /> - <CodeInspection Name="ModuleWithoutFolderInspection" Severity="Suggestion" InspectionType="RubberduckOpportunities" /> - <CodeInspection Name="OnLocalErrorInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> - <CodeInspection Name="IsMissingOnInappropriateArgumentInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="IsMissingWithNonArgumentParameterInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="AssignmentNotUsedInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="UnderscoreInPublicClassModuleMemberInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="ExcelUdfNameIsValidCellReferenceInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="EmptyMethodInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="ImplementedInterfaceMemberInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> - <CodeInspection Name="PublicControlFieldAccessInspection" Severity="Hint" InspectionType="LanguageOpportunities" /> - </CodeInspections> - <WhitelistedIdentifiers /> - <RunInspectionsOnSuccessfulParse>true</RunInspectionsOnSuccessfulParse> -</CodeInspectionSettings> + + <CodeInspectionSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <CodeInspections> + <CodeInspection Name="AnnotationInIncompatibleComponentTypeInspection" Severity="Warning" InspectionType="RubberduckOpportunities" /> + <CodeInspection Name="ApplicationWorksheetFunctionInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="ArgumentWithIncompatibleObjectTypeInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="AssignedByValParameterInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="AssignmentNotUsedInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="AttributeValueOutOfSyncInspection" Severity="Error" InspectionType="RubberduckOpportunities" /> + <CodeInspection Name="BooleanAssignedInIfElseInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ConstantNotUsedInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="DefaultMemberRequiredInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="DefaultProjectNameInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="DefTypeStatementInspection" Severity="Warning" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="DuplicatedAnnotationInspection" Severity="Error" InspectionType="RubberduckOpportunities" /> + <CodeInspection Name="EmptyCaseBlockInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="EmptyDoWhileBlockInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="EmptyElseBlockInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="EmptyForEachBlockInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="EmptyForLoopBlockInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="EmptyIfBlockInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="EmptyMethodInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="EmptyModuleInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="EmptyStringLiteralInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="EmptyWhileWendBlockInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="EncapsulatePublicFieldInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="ExcelMemberMayReturnNothingInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ExcelUdfNameIsValidCellReferenceInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="FunctionReturnValueAlwaysDiscardedInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="FunctionReturnValueDiscardedInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="HostSpecificExpressionInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="HungarianNotationInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="IIfSideEffectInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ImplementedInterfaceMemberInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ImplicitActiveSheetReferenceInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ImplicitActiveWorkbookReferenceInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ImplicitByRefModifierInspection" Severity="Hint" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="ImplicitContainingWorkbookReferenceInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ImplicitContainingWorksheetReferenceInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ImplicitDefaultMemberAccessInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ImplicitlyTypedConstInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ImplicitPublicMemberInspection" Severity="Hint" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="ImplicitRecursiveDefaultMemberAccessInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ImplicitUnboundDefaultMemberAccessInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ImplicitVariantReturnTypeInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="InconsistentArrayBaseInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="InconsistentParamArrayBaseInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="IndexedDefaultMemberAccessInspection" Severity="Hint" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="IndexedRecursiveDefaultMemberAccessInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="IndexedUnboundDefaultMemberAccessInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="IntegerDataTypeInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="InvalidAnnotationInspection" Severity="Warning" InspectionType="RubberduckOpportunities" /> + <CodeInspection Name="IsMissingOnInappropriateArgumentInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="IsMissingWithNonArgumentParameterInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="KeywordsUsedAsMemberInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="LineContinuationBetweenKeywordsInspection" Severity="Error" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="LineLabelNotUsedInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="MemberNotOnInterfaceInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="MisleadingByRefInspection" Severity="Warning" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="MissingAnnotationArgumentInspection" Severity="Error" InspectionType="RubberduckOpportunities" /> + <CodeInspection Name="MissingAttributeInspection" Severity="Error" InspectionType="RubberduckOpportunities" /> + <CodeInspection Name="MissingMemberAnnotationInspection" Severity="Warning" InspectionType="RubberduckOpportunities" /> + <CodeInspection Name="MissingModuleAnnotationInspection" Severity="Warning" InspectionType="RubberduckOpportunities" /> + <CodeInspection Name="ModuleScopeDimKeywordInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="ModuleWithoutFolderInspection" Severity="Suggestion" InspectionType="RubberduckOpportunities" /> + <CodeInspection Name="MoveFieldCloserToUsageInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="MultilineParameterInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="MultipleDeclarationsInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="NegativeLineNumberInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="NonBreakingSpaceIdentifierInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="NonReturningFunctionInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ObjectVariableNotSetInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ObjectWhereProcedureIsRequiredInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ObsoleteCallingConventionInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ObsoleteCallStatementInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="ObsoleteCommentSyntaxInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="ObsoleteErrorSyntaxInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="ObsoleteGlobalInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="ObsoleteLetStatementInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="ObsoleteMemberUsageInspection" Severity="Warning" InspectionType="RubberduckOpportunities" /> + <CodeInspection Name="ObsoleteTypeHintInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="ObsoleteWhileWendStatementInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="OnErrorGoToMinusOneInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="OnLocalErrorInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="OptionBaseInspection" Severity="Hint" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="OptionExplicitInspection" Severity="Error" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="ParameterCanBeByValInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="ParameterlessCellsInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ParameterNotUsedInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ProcedureCanBeWrittenAsFunctionInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="ProcedureNotUsedInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ProcedureRequiredInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="PublicControlFieldAccessInspection" Severity="Hint" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="PublicEnumerationDeclaredInWorksheetInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="ReadOnlyPropertyAssignmentInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="RedundantByRefModifierInspection" Severity="DoNotShow" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="RedundantOptionInspection" Severity="Hint" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="SelfAssignedDeclarationInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="SetAssignmentWithIncompatibleObjectTypeInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="ShadowedDeclarationInspection" Severity="DoNotShow" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="SheetAccessedUsingStringInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="StepIsNotSpecifiedInspection" Severity="DoNotShow" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="StepOneIsRedundantInspection" Severity="Hint" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="StopKeywordInspection" Severity="Hint" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="SuperfluousAnnotationArgumentInspection" Severity="Warning" InspectionType="RubberduckOpportunities" /> + <CodeInspection Name="SuspiciousLetAssignmentInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="SuspiciousPredeclaredInstanceAccessInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="UDTMemberNotUsedInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="UnassignedVariableUsageInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="UndeclaredVariableInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="UnderscoreInPublicClassModuleMemberInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="UnhandledOnErrorResumeNextInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="UnreachableCaseInspection" Severity="Warning" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="UnrecognizedAnnotationInspection" Severity="Warning" InspectionType="RubberduckOpportunities" /> + <CodeInspection Name="UntypedFunctionUsageInspection" Severity="Hint" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="UseMeaningfulNameInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="UseOfBangNotationInspection" Severity="Hint" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="UseOfRecursiveBangNotationInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="UseOfUnboundBangNotationInspection" Severity="Warning" InspectionType="NamingAndConventionsIssues" /> + <CodeInspection Name="ValueRequiredInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="VariableNotAssignedInspection" Severity="Error" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="VariableNotUsedInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /> + <CodeInspection Name="VariableTypeNotDeclaredInspection" Severity="Warning" InspectionType="LanguageOpportunities" /> + <CodeInspection Name="WriteOnlyPropertyInspection" Severity="Suggestion" InspectionType="NamingAndConventionsIssues" /> + </CodeInspections> + <WhitelistedIdentifiers /> + <RunInspectionsOnSuccessfulParse>true</RunInspectionsOnSuccessfulParse> + <IgnoreFormControlsHungarianNotation>true</IgnoreFormControlsHungarianNotation> + </CodeInspectionSettings> + \ No newline at end of file diff --git a/Rubberduck.CodeAnalysis/Rubberduck.CodeAnalysis.csproj b/Rubberduck.CodeAnalysis/Rubberduck.CodeAnalysis.csproj index b39c0b1b32..d49b481a9b 100644 --- a/Rubberduck.CodeAnalysis/Rubberduck.CodeAnalysis.csproj +++ b/Rubberduck.CodeAnalysis/Rubberduck.CodeAnalysis.csproj @@ -45,7 +45,7 @@ - 4.6.4 + 4.6.6 4.5.10 diff --git a/Rubberduck.CodeAnalysis/Settings/CodeInspectionSettings.cs b/Rubberduck.CodeAnalysis/Settings/CodeInspectionSettings.cs index e0e5b8f434..e006103f6e 100644 --- a/Rubberduck.CodeAnalysis/Settings/CodeInspectionSettings.cs +++ b/Rubberduck.CodeAnalysis/Settings/CodeInspectionSettings.cs @@ -1,10 +1,10 @@ -using System; +using Rubberduck.CodeAnalysis.Inspections; +using System; using System.Collections.Generic; using System.Configuration; using System.Globalization; using System.Linq; using System.Xml.Serialization; -using Rubberduck.CodeAnalysis.Inspections; namespace Rubberduck.CodeAnalysis.Settings { @@ -13,6 +13,8 @@ public interface ICodeInspectionSettings HashSet CodeInspections { get; set; } WhitelistedIdentifierSetting[] WhitelistedIdentifiers { get; set; } bool RunInspectionsOnSuccessfulParse { get; set; } + + bool IgnoreFormControlsHungarianNotation { get; set; } } [SettingsSerializeAs(SettingsSerializeAs.Xml)] @@ -26,16 +28,18 @@ public class CodeInspectionSettings : ICodeInspectionSettings, IEquatable(), new WhitelistedIdentifierSetting[] { }, true) + public CodeInspectionSettings() : this(Enumerable.Empty(), new WhitelistedIdentifierSetting[] { }, true, false) { } - public CodeInspectionSettings(IEnumerable inspections, WhitelistedIdentifierSetting[] whitelistedNames, bool runInspectionsOnParse) + public CodeInspectionSettings(IEnumerable inspections, WhitelistedIdentifierSetting[] whitelistedNames, bool runInspectionsOnParse, bool ignoreFormControlsHungarian) { CodeInspections = new HashSet(inspections); WhitelistedIdentifiers = whitelistedNames; RunInspectionsOnSuccessfulParse = runInspectionsOnParse; + IgnoreFormControlsHungarianNotation = ignoreFormControlsHungarian; } public CodeInspectionSetting GetSetting() where TInspection : IInspection @@ -53,7 +57,7 @@ public CodeInspectionSetting GetSetting(Type inspectionType) { return existing; } - var proto = Convert.ChangeType(Activator.CreateInstance(inspectionType, new object[]{null}), inspectionType); + var proto = Convert.ChangeType(Activator.CreateInstance(inspectionType, new object[] { null }), inspectionType); var setting = new CodeInspectionSetting(proto as IInspectionModel); CodeInspections.Add(setting); return setting; @@ -69,7 +73,8 @@ public bool Equals(CodeInspectionSettings other) return other != null && CodeInspections.SequenceEqual(other.CodeInspections) && WhitelistedIdentifiers.SequenceEqual(other.WhitelistedIdentifiers) && - RunInspectionsOnSuccessfulParse == other.RunInspectionsOnSuccessfulParse; + RunInspectionsOnSuccessfulParse == other.RunInspectionsOnSuccessfulParse && + IgnoreFormControlsHungarianNotation == other.IgnoreFormControlsHungarianNotation; } } diff --git a/Rubberduck.CodeAnalysis/app.config b/Rubberduck.CodeAnalysis/app.config index 56c52616a5..e720e2127b 100644 --- a/Rubberduck.CodeAnalysis/app.config +++ b/Rubberduck.CodeAnalysis/app.config @@ -18,169 +18,254 @@ - + - - - - + + + - - - + - - - - - - - - - - - - - + - - - - - - - - + + + + - - - - - - - - + + + + + InspectionType="CodeQualityIssues" /> + + + Severity="Warning" InspectionType="CodeQualityIssues" /> - + Severity="Warning" InspectionType="CodeQualityIssues" /> + + + + + + + + + + + + + + - + + + + + + - + + + + + + + + + + + + + + + + + + - + + + + - + - - - + - - - - - - - + - - - + + - + - - - - - - + + - + + - - + - - + + + + + + + + + + true + true diff --git a/Rubberduck.Core/Properties/Settings.Designer.cs b/Rubberduck.Core/Properties/Settings.Designer.cs index 90eeb2cf96..1a76b26ed5 100644 --- a/Rubberduck.Core/Properties/Settings.Designer.cs +++ b/Rubberduck.Core/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace Rubberduck.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.6.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.12.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/Rubberduck.Core/Rubberduck.Core.csproj b/Rubberduck.Core/Rubberduck.Core.csproj index cda42e9170..5fdef2e9f1 100644 --- a/Rubberduck.Core/Rubberduck.Core.csproj +++ b/Rubberduck.Core/Rubberduck.Core.csproj @@ -65,7 +65,7 @@ - 4.6.4 + 4.6.6 5.0.4 diff --git a/Rubberduck.Core/UI/About/AboutControlViewModel.cs b/Rubberduck.Core/UI/About/AboutControlViewModel.cs index 93272b9980..75720e042a 100644 --- a/Rubberduck.Core/UI/About/AboutControlViewModel.cs +++ b/Rubberduck.Core/UI/About/AboutControlViewModel.cs @@ -1,12 +1,12 @@ -using System; -using System.Diagnostics; -using Path = System.IO.Path; -using NLog; +using NLog; using NLog.Targets; using Rubberduck.Resources.About; using Rubberduck.UI.Command; using Rubberduck.VersionCheck; +using System; +using System.Diagnostics; using Application = System.Windows.Forms.Application; +using Path = System.IO.Path; namespace Rubberduck.UI.About { @@ -26,8 +26,11 @@ public AboutControlViewModel(IVersionCheckService version, IWebNavigator web) public string Version => string.Format(Resources.RubberduckUI.Rubberduck_AboutBuild, _version.VersionString); - public string OperatingSystem => - string.Format(AboutUI.AboutWindow_OperatingSystem, Environment.OSVersion.VersionString, Environment.Is64BitOperatingSystem ? "x64" : "x86"); + private static readonly string _versionString = Environment.OSVersion.Version.Build > 22000 + ? $"{Environment.OSVersion.VersionString} (Win11)" + : Environment.OSVersion.VersionString; + + public string OperatingSystem => string.Format(AboutUI.AboutWindow_OperatingSystem, _versionString, Environment.Is64BitOperatingSystem ? "x64" : "x86"); public string HostProduct => string.Format(AboutUI.AboutWindow_HostProduct, Application.ProductName, Environment.Is64BitProcess ? "x64" : "x86"); @@ -36,7 +39,7 @@ public AboutControlViewModel(IVersionCheckService version, IWebNavigator web) public string HostExecutable => string.Format(AboutUI.AboutWindow_HostExecutable, Path.GetFileName(Application.ExecutablePath).ToUpper()); // .ToUpper() used to convert ExceL.EXE -> EXCEL.EXE - + public string AboutCopyright => string.Format(AboutUI.AboutWindow_Copyright, DateTime.Now.Year); @@ -48,11 +51,11 @@ public AboutControlViewModel(IVersionCheckService version, IWebNavigator web) private void ExecuteViewLog(object parameter) { - var fileTarget = (FileTarget) LogManager.Configuration.FindTargetByName("file"); - - var logEventInfo = new LogEventInfo { TimeStamp = DateTime.Now }; + var fileTarget = (FileTarget)LogManager.Configuration.FindTargetByName("file"); + + var logEventInfo = new LogEventInfo { TimeStamp = DateTime.Now }; var fileName = fileTarget.FileName.Render(logEventInfo); - + // The /select argument will only work if the path has backslashes fileName = fileName.Replace("/", "\\"); Process.Start(new ProcessStartInfo("explorer.exe", $"/select, \"{fileName}\"")); diff --git a/Rubberduck.Core/UI/Inspections/InspectionResultsControl.xaml b/Rubberduck.Core/UI/Inspections/InspectionResultsControl.xaml index ab7e4d7bbf..e756d3ad3b 100644 --- a/Rubberduck.Core/UI/Inspections/InspectionResultsControl.xaml +++ b/Rubberduck.Core/UI/Inspections/InspectionResultsControl.xaml @@ -97,6 +97,8 @@ + + +