From 571aeb4333847b3ef6bc54907d1f7ccf24896d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Barr=C3=A9?= Date: Wed, 17 Apr 2024 20:46:01 -0400 Subject: [PATCH] Fix formatting --- ...ualityShouldBeCorrectlyImplementedFixer.cs | 4 +-- ...tsShouldHaveProperArgumentsFixer.MA0091.cs | 2 +- .../Rules/ValidateArgumentsCorrectlyFixer.cs | 2 +- .../Internals/ContextExtensions.cs | 2 +- .../CultureSensitiveFormattingContext.cs | 6 ++-- .../Internals/MethodSymbolExtensions.cs | 18 +++++------ .../Internals/TypeSymbolExtensions.cs | 4 +-- src/Meziantou.Analyzer/RuleIdentifiers.cs | 1 + ...tTypesShouldNotHaveConstructorsAnalyzer.cs | 2 +- ...otBeUsedToUnsubscribeFromEventsAnalyzer.cs | 2 +- ...otUseBlockingCallInAsyncContextAnalyzer.cs | 2 +- ...ropMustNotBeUsedInOnInitializedAnalyzer.cs | 2 +- .../Rules/NamedParameterAnalyzerCommon.cs | 2 +- .../Rules/OptimizeLinqUsageAnalyzer.cs | 4 +-- .../ValidateArgumentsCorrectlyAnalyzer.cs | 2 +- .../Helpers/DiagnosticResult.cs | 2 +- .../Helpers/ProjectBuilder.Validation.cs | 4 +-- .../Helpers/ProjectBuilder.cs | 14 ++++++++- tests/Meziantou.Analyzer.Test/RuleHelpUri.cs | 27 +++++++++++++++++ ...ddOverloadWithSpanOrMemoryAnalyzerTests.cs | 10 +++---- ...nShouldSpecifyArgumentNameAnalyzerTests.cs | 2 +- ...waitableMethodInSyncMethodAnalyzerTests.cs | 2 +- ...skBeforeDisposingResourcesAnalyzerTests.cs | 8 ++--- .../Rules/ClassMustBeSealedAnalyzerTests.cs | 2 +- ...uldContainValidExpressionsAnalyzerTests.cs | 8 ++--- .../DoNotLogClassifiedDataAnalyzerTests.cs | 10 +++---- ...yncDelegateForSyncDelegateAnalyzerTests.cs | 6 ++-- ...itCultureSensitiveToStringAnalyzerTests.cs | 4 +-- .../DoNotUseToStringIfObjectAnalyzerTests.cs | 2 +- ...ParameterForRazorComponentAnalyzerTests.cs | 6 ++-- ...sShouldHaveProperArgumentsAnalyzerTests.cs | 2 +- .../FileNameMustMatchTypeNameAnalyzerTests.cs | 12 ++++---- .../Rules/LoggerParameterTypeAnalyzerTests.cs | 8 ++--- .../Rules/MakeClassStaticAnalyzerTests.cs | 2 +- .../Rules/NamedParameterAnalyzerTests.cs | 4 +-- ...eLinqUsageAnalyzerUseDirectMethodsTests.cs | 4 +-- .../Rules/OptimizeStartsWithAnalyzerTests.cs | 2 +- ...OptimizeStringBuilderUsageAnalyzerTests.cs | 4 +-- ...rParameterShouldBeReadOnlyAnalyzerTests.cs | 4 +-- .../RemoveEmptyStatementAnalyzerTests.cs | 2 +- ...sNonDeterministicEndOfLineAnalyzerTests.cs | 8 ++--- .../Rules/TaskInUsingAnalyzerTests.cs | 2 +- .../UseDateTimeUnixEpochAnalyzerTests.cs | 2 +- .../Rules/UseIFormatProviderAnalyzerTests.cs | 30 +++++++++---------- ...eVoidAsyncWhenReturnValueIsNotUsedTests.cs | 22 +++++++------- ...hingForEqualityComparisonsAnalyzerTests.cs | 2 +- .../Rules/UseRegexTimeoutAnalyzerTests.cs | 6 ++-- .../Rules/UseStringComparerAnalyzerTests.cs | 8 ++--- ...parisonAnalyzerNonCultureSensitiveTests.cs | 2 +- ...InsteadOfFormattableStringAnalyzerTests.cs | 2 +- ...ngEqualsInsteadOfIsPatternAnalyzerTests.cs | 4 +-- .../Rules/UseTaskUnwrapAnalyzerTests.cs | 8 ++--- 52 files changed, 171 insertions(+), 131 deletions(-) mode change 100644 => 100755 src/Meziantou.Analyzer.CodeFixers/Rules/EqualityShouldBeCorrectlyImplementedFixer.cs mode change 100644 => 100755 src/Meziantou.Analyzer.CodeFixers/Rules/EventsShouldHaveProperArgumentsFixer.MA0091.cs mode change 100644 => 100755 src/Meziantou.Analyzer.CodeFixers/Rules/ValidateArgumentsCorrectlyFixer.cs mode change 100644 => 100755 src/Meziantou.Analyzer/Internals/ContextExtensions.cs mode change 100644 => 100755 src/Meziantou.Analyzer/Internals/CultureSensitiveFormattingContext.cs mode change 100644 => 100755 src/Meziantou.Analyzer/Internals/MethodSymbolExtensions.cs mode change 100644 => 100755 src/Meziantou.Analyzer/Internals/TypeSymbolExtensions.cs mode change 100644 => 100755 src/Meziantou.Analyzer/RuleIdentifiers.cs mode change 100644 => 100755 src/Meziantou.Analyzer/Rules/AbstractTypesShouldNotHaveConstructorsAnalyzer.cs mode change 100644 => 100755 src/Meziantou.Analyzer/Rules/AnonymousDelegatesShouldNotBeUsedToUnsubscribeFromEventsAnalyzer.cs mode change 100644 => 100755 src/Meziantou.Analyzer/Rules/DoNotUseBlockingCallInAsyncContextAnalyzer.cs mode change 100644 => 100755 src/Meziantou.Analyzer/Rules/JSInteropMustNotBeUsedInOnInitializedAnalyzer.cs mode change 100644 => 100755 src/Meziantou.Analyzer/Rules/NamedParameterAnalyzerCommon.cs mode change 100644 => 100755 src/Meziantou.Analyzer/Rules/OptimizeLinqUsageAnalyzer.cs mode change 100644 => 100755 src/Meziantou.Analyzer/Rules/ValidateArgumentsCorrectlyAnalyzer.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Helpers/DiagnosticResult.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.Validation.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.cs create mode 100755 tests/Meziantou.Analyzer.Test/RuleHelpUri.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/AddOverloadWithSpanOrMemoryAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/ArgumentExceptionShouldSpecifyArgumentNameAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/AwaitAwaitableMethodInSyncMethodAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/AwaitTaskBeforeDisposingResourcesAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/ClassMustBeSealedAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/DebuggerDisplayAttributeShouldContainValidExpressionsAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/DoNotLogClassifiedDataAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/DoNotUseAsyncDelegateForSyncDelegateAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/DoNotUseImplicitCultureSensitiveToStringAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/DoNotUseToStringIfObjectAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/DoNotUseUnknownParameterForRazorComponentAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/EventsShouldHaveProperArgumentsAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/FileNameMustMatchTypeNameAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/LoggerParameterTypeAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/MakeClassStaticAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/NamedParameterAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/OptimizeLinqUsageAnalyzerUseDirectMethodsTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/OptimizeStartsWithAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/OptimizeStringBuilderUsageAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/PrimaryConstructorParameterShouldBeReadOnlyAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/RemoveEmptyStatementAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/StringShouldNotContainsNonDeterministicEndOfLineAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/TaskInUsingAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/UseDateTimeUnixEpochAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/UseIFormatProviderAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/UseJSRuntimeInvokeVoidAsyncWhenReturnValueIsNotUsedTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/UsePatternMatchingForEqualityComparisonsAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/UseRegexTimeoutAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/UseStringComparerAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/UseStringComparisonAnalyzerNonCultureSensitiveTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/UseStringCreateInsteadOfFormattableStringAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/UseStringEqualsInsteadOfIsPatternAnalyzerTests.cs mode change 100644 => 100755 tests/Meziantou.Analyzer.Test/Rules/UseTaskUnwrapAnalyzerTests.cs diff --git a/src/Meziantou.Analyzer.CodeFixers/Rules/EqualityShouldBeCorrectlyImplementedFixer.cs b/src/Meziantou.Analyzer.CodeFixers/Rules/EqualityShouldBeCorrectlyImplementedFixer.cs old mode 100644 new mode 100755 index 2a23fbe25..2bc118b8c --- a/src/Meziantou.Analyzer.CodeFixers/Rules/EqualityShouldBeCorrectlyImplementedFixer.cs +++ b/src/Meziantou.Analyzer.CodeFixers/Rules/EqualityShouldBeCorrectlyImplementedFixer.cs @@ -23,7 +23,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) var nodeToFix = root?.FindNode(context.Span, getInnermostNodeForTie: true); if (nodeToFix is null) return; - + var title = "Implement System.IEquatable"; var codeAction = CodeAction.Create( title, @@ -36,7 +36,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) private static async Task ImplementIEquatable(Document document, SyntaxNode nodeToFix, CancellationToken cancellationToken) { var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); - + if (semanticModel is null || semanticModel.GetDeclaredSymbol(nodeToFix, cancellationToken: cancellationToken) is not ITypeSymbol declaredTypeSymbol) return document; diff --git a/src/Meziantou.Analyzer.CodeFixers/Rules/EventsShouldHaveProperArgumentsFixer.MA0091.cs b/src/Meziantou.Analyzer.CodeFixers/Rules/EventsShouldHaveProperArgumentsFixer.MA0091.cs old mode 100644 new mode 100755 index 897c37696..64403be22 --- a/src/Meziantou.Analyzer.CodeFixers/Rules/EventsShouldHaveProperArgumentsFixer.MA0091.cs +++ b/src/Meziantou.Analyzer.CodeFixers/Rules/EventsShouldHaveProperArgumentsFixer.MA0091.cs @@ -34,7 +34,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) private static async Task UseThis(Document document, SyntaxNode nodeToFix, CancellationToken cancellationToken) { - var editor = await DocumentEditor.CreateAsync(document, cancellationToken).ConfigureAwait(false); + var editor = await DocumentEditor.CreateAsync(document, cancellationToken).ConfigureAwait(false); editor.ReplaceNode(nodeToFix, editor.Generator.ThisExpression()); return editor.GetChangedDocument(); } diff --git a/src/Meziantou.Analyzer.CodeFixers/Rules/ValidateArgumentsCorrectlyFixer.cs b/src/Meziantou.Analyzer.CodeFixers/Rules/ValidateArgumentsCorrectlyFixer.cs old mode 100644 new mode 100755 index 819d633d0..b6ae3c919 --- a/src/Meziantou.Analyzer.CodeFixers/Rules/ValidateArgumentsCorrectlyFixer.cs +++ b/src/Meziantou.Analyzer.CodeFixers/Rules/ValidateArgumentsCorrectlyFixer.cs @@ -113,7 +113,7 @@ private static ParameterListSyntax RemoveEnumeratorCancellationAttribute(Paramet ParameterSyntax UpdateParameter(ParameterSyntax parameter) { - return parameter.WithAttributeLists(new SyntaxList(parameter.AttributeLists.Select(UpdateAttributeList).Where(list=>list.Attributes.Count > 0))); + return parameter.WithAttributeLists(new SyntaxList(parameter.AttributeLists.Select(UpdateAttributeList).Where(list => list.Attributes.Count > 0))); } AttributeListSyntax UpdateAttributeList(AttributeListSyntax attributes) diff --git a/src/Meziantou.Analyzer/Internals/ContextExtensions.cs b/src/Meziantou.Analyzer/Internals/ContextExtensions.cs old mode 100644 new mode 100755 index f62be174e..f40e31440 --- a/src/Meziantou.Analyzer/Internals/ContextExtensions.cs +++ b/src/Meziantou.Analyzer/Internals/ContextExtensions.cs @@ -105,7 +105,7 @@ public static void ReportDiagnostic(this DiagnosticReporter context, DiagnosticD ReportDiagnostic(context, descriptor, properties, location, messageArgs); } } - + public static void ReportDiagnostic(this DiagnosticReporter context, DiagnosticDescriptor descriptor, IPropertySymbol symbol, DiagnosticPropertyReportOptions reportOptions, string?[]? messageArgs = null) => ReportDiagnostic(context, descriptor, ImmutableDictionary.Empty, symbol, reportOptions, messageArgs); public static void ReportDiagnostic(this DiagnosticReporter context, DiagnosticDescriptor descriptor, ImmutableDictionary? properties, IPropertySymbol symbol, DiagnosticPropertyReportOptions reportOptions, string?[]? messageArgs = null) { diff --git a/src/Meziantou.Analyzer/Internals/CultureSensitiveFormattingContext.cs b/src/Meziantou.Analyzer/Internals/CultureSensitiveFormattingContext.cs old mode 100644 new mode 100755 index b467126e5..ffb275e06 --- a/src/Meziantou.Analyzer/Internals/CultureSensitiveFormattingContext.cs +++ b/src/Meziantou.Analyzer/Internals/CultureSensitiveFormattingContext.cs @@ -183,10 +183,10 @@ public bool IsCultureSensitiveOperation(IOperation operation, CultureSensitiveOp if (operation is IDefaultValueOperation defaultValue) return IsCultureSensitiveType(defaultValue.Type, format: null, instance: null, options); - + if (operation is IArrayElementReferenceOperation arrayElementReference) return IsCultureSensitiveType(arrayElementReference.Type, format: null, instance: null, options); - + if (operation is IBinaryOperation binaryOperation) return IsCultureSensitiveType(binaryOperation.Type, format: null, instance: null, options); @@ -288,7 +288,7 @@ private static bool IsInvariantDateTimeFormat(IOperation? valueOperation) private static bool IsInvariantTimeSpanFormat(IOperation? valueOperation) { // note: "c" format is case-sensitive - return valueOperation is null || valueOperation is { ConstantValue: { HasValue: true, Value: null or "" or "c" or "t" or "T" } }; + return valueOperation is null or { ConstantValue: { HasValue: true, Value: null or "" or "c" or "t" or "T" } }; } // Only negative numbers are culture-sensitive (negative sign) diff --git a/src/Meziantou.Analyzer/Internals/MethodSymbolExtensions.cs b/src/Meziantou.Analyzer/Internals/MethodSymbolExtensions.cs old mode 100644 new mode 100755 index 53c412c31..8fd9fa7b8 --- a/src/Meziantou.Analyzer/Internals/MethodSymbolExtensions.cs +++ b/src/Meziantou.Analyzer/Internals/MethodSymbolExtensions.cs @@ -9,28 +9,28 @@ internal static class MethodSymbolExtensions private static readonly string[] NunitNamespaceParts = ["NUnit", "Framework"]; private static readonly string[] XunitNamespaceParts = ["Xunit"]; - public static bool IsInterfaceImplementation(this IMethodSymbol method) + public static bool IsInterfaceImplementation(this IMethodSymbol symbol) { - if (method.ExplicitInterfaceImplementations.Length > 0) + if (symbol.ExplicitInterfaceImplementations.Length > 0) return true; - return IsInterfaceImplementation((ISymbol)method); + return IsInterfaceImplementation((ISymbol)symbol); } - public static bool IsInterfaceImplementation(this IPropertySymbol property) + public static bool IsInterfaceImplementation(this IPropertySymbol symbol) { - if (property.ExplicitInterfaceImplementations.Length > 0) + if (symbol.ExplicitInterfaceImplementations.Length > 0) return true; - return IsInterfaceImplementation((ISymbol)property); + return IsInterfaceImplementation((ISymbol)symbol); } - public static bool IsInterfaceImplementation(this IEventSymbol method) + public static bool IsInterfaceImplementation(this IEventSymbol symbol) { - if (method.ExplicitInterfaceImplementations.Length > 0) + if (symbol.ExplicitInterfaceImplementations.Length > 0) return true; - return IsInterfaceImplementation((ISymbol)method); + return IsInterfaceImplementation((ISymbol)symbol); } private static bool IsInterfaceImplementation(this ISymbol symbol) diff --git a/src/Meziantou.Analyzer/Internals/TypeSymbolExtensions.cs b/src/Meziantou.Analyzer/Internals/TypeSymbolExtensions.cs old mode 100644 new mode 100755 index 581def6ba..c59be90e4 --- a/src/Meziantou.Analyzer/Internals/TypeSymbolExtensions.cs +++ b/src/Meziantou.Analyzer/Internals/TypeSymbolExtensions.cs @@ -48,7 +48,7 @@ public static bool Implements(this ITypeSymbol classSymbol, ITypeSymbol? interfa if (interfaceType is null) return false; - return classSymbol.AllInterfaces.Any(i => interfaceType.IsEqualTo(i)); + return classSymbol.AllInterfaces.Any(interfaceType.IsEqualTo); } public static bool IsOrImplements(this ITypeSymbol symbol, ITypeSymbol? interfaceType) @@ -56,7 +56,7 @@ public static bool IsOrImplements(this ITypeSymbol symbol, ITypeSymbol? interfac if (interfaceType is null) return false; - return GetAllInterfacesIncludingThis(symbol).Any(i => interfaceType.IsEqualTo(i)); + return GetAllInterfacesIncludingThis(symbol).Any(interfaceType.IsEqualTo); } public static AttributeData? GetAttribute(this ISymbol symbol, ITypeSymbol? attributeType, bool inherits = true) diff --git a/src/Meziantou.Analyzer/RuleIdentifiers.cs b/src/Meziantou.Analyzer/RuleIdentifiers.cs old mode 100644 new mode 100755 index b503886fc..be515433c --- a/src/Meziantou.Analyzer/RuleIdentifiers.cs +++ b/src/Meziantou.Analyzer/RuleIdentifiers.cs @@ -157,6 +157,7 @@ internal static class RuleIdentifiers public const string UseTaskUnwrap = "MA0152"; public const string DoNotLogClassifiedData = "MA0153"; public const string UseLangwordInXmlComment = "MA0154"; + public const string DoNotUseAsyncVoid = "MA0155"; public static string GetHelpUri(string identifier) { diff --git a/src/Meziantou.Analyzer/Rules/AbstractTypesShouldNotHaveConstructorsAnalyzer.cs b/src/Meziantou.Analyzer/Rules/AbstractTypesShouldNotHaveConstructorsAnalyzer.cs old mode 100644 new mode 100755 index e0fa9f1f5..5af2a633c --- a/src/Meziantou.Analyzer/Rules/AbstractTypesShouldNotHaveConstructorsAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/AbstractTypesShouldNotHaveConstructorsAnalyzer.cs @@ -35,7 +35,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context) foreach (var ctor in symbol.InstanceConstructors) { - if (ctor.DeclaredAccessibility == Accessibility.Public || ctor.DeclaredAccessibility == Accessibility.Internal) + if (ctor.DeclaredAccessibility is Accessibility.Public or Accessibility.Internal) { context.ReportDiagnostic(Rule, ctor); } diff --git a/src/Meziantou.Analyzer/Rules/AnonymousDelegatesShouldNotBeUsedToUnsubscribeFromEventsAnalyzer.cs b/src/Meziantou.Analyzer/Rules/AnonymousDelegatesShouldNotBeUsedToUnsubscribeFromEventsAnalyzer.cs old mode 100644 new mode 100755 index 7fbfd1303..8b30fad07 --- a/src/Meziantou.Analyzer/Rules/AnonymousDelegatesShouldNotBeUsedToUnsubscribeFromEventsAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/AnonymousDelegatesShouldNotBeUsedToUnsubscribeFromEventsAnalyzer.cs @@ -40,7 +40,7 @@ private static void AnalyzeOperation(OperationAnalysisContext context) handler = op.Operand; } - if (handler is not null && handler is IDelegateCreationOperation delegateCreation) + if (handler is IDelegateCreationOperation delegateCreation) { if (delegateCreation.Target is IAnonymousFunctionOperation) { diff --git a/src/Meziantou.Analyzer/Rules/DoNotUseBlockingCallInAsyncContextAnalyzer.cs b/src/Meziantou.Analyzer/Rules/DoNotUseBlockingCallInAsyncContextAnalyzer.cs old mode 100644 new mode 100755 index f3373d2a8..fd66fd9ec --- a/src/Meziantou.Analyzer/Rules/DoNotUseBlockingCallInAsyncContextAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/DoNotUseBlockingCallInAsyncContextAnalyzer.cs @@ -217,7 +217,7 @@ private bool HasAsyncEquivalent(IInvocationOperation operation, [NotNullWhen(tru } // Console.Out|Error.Write - else if (targetMethod.Name == "WriteLine" || targetMethod.Name == "Write" || targetMethod.Name == "Flush") + else if (targetMethod.Name is "WriteLine" or "Write" or "Flush") { var left = operation.GetChildOperations().FirstOrDefault(); if (left is IMemberReferenceOperation memberReference) diff --git a/src/Meziantou.Analyzer/Rules/JSInteropMustNotBeUsedInOnInitializedAnalyzer.cs b/src/Meziantou.Analyzer/Rules/JSInteropMustNotBeUsedInOnInitializedAnalyzer.cs old mode 100644 new mode 100755 index ed374c863..1fc4e1db8 --- a/src/Meziantou.Analyzer/Rules/JSInteropMustNotBeUsedInOnInitializedAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/JSInteropMustNotBeUsedInOnInitializedAnalyzer.cs @@ -65,7 +65,7 @@ public bool IsValid { if (WebAssemblyJSRuntimeSymbol is not null) return false; // There is no issue in WebAssembly - + if (WebViewJSRuntimeSymbol is not null) return false; // There is no issue in WebView diff --git a/src/Meziantou.Analyzer/Rules/NamedParameterAnalyzerCommon.cs b/src/Meziantou.Analyzer/Rules/NamedParameterAnalyzerCommon.cs old mode 100644 new mode 100755 index c2dd9c4b6..9cd423bc6 --- a/src/Meziantou.Analyzer/Rules/NamedParameterAnalyzerCommon.cs +++ b/src/Meziantou.Analyzer/Rules/NamedParameterAnalyzerCommon.cs @@ -3,7 +3,7 @@ namespace Meziantou.Analyzer.Rules; internal static class NamedParameterAnalyzerCommon -{ +{ public static int ArgumentIndex(ArgumentSyntax argument) { var argumentListExpression = argument.FirstAncestorOrSelf(); diff --git a/src/Meziantou.Analyzer/Rules/OptimizeLinqUsageAnalyzer.cs b/src/Meziantou.Analyzer/Rules/OptimizeLinqUsageAnalyzer.cs old mode 100644 new mode 100755 index cbf837474..888b6e4d5 --- a/src/Meziantou.Analyzer/Rules/OptimizeLinqUsageAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/OptimizeLinqUsageAnalyzer.cs @@ -290,7 +290,7 @@ private void UseFindInsteadOfFirstOrDefault(OperationAnalysisContext context, II context.ReportDiagnostic(ListMethodsRule, properties, operation, DiagnosticInvocationReportOptions.ReportOnMember, "Find()", operation.TargetMethod.Name); } } - + private void UseTrueForAllInsteadOfAll(OperationAnalysisContext context, IInvocationOperation operation) { if (operation.TargetMethod.Name != nameof(Enumerable.All)) @@ -322,7 +322,7 @@ private void UseTrueForAllInsteadOfAll(OperationAnalysisContext context, IInvoca context.ReportDiagnostic(ListMethodsRule, properties, operation, DiagnosticInvocationReportOptions.ReportOnMember, "TrueForAll()", operation.TargetMethod.Name); } } - + private void UseExistsInsteadOfAny(OperationAnalysisContext context, IInvocationOperation operation) { if (operation.TargetMethod.Name != nameof(Enumerable.Any)) diff --git a/src/Meziantou.Analyzer/Rules/ValidateArgumentsCorrectlyAnalyzer.cs b/src/Meziantou.Analyzer/Rules/ValidateArgumentsCorrectlyAnalyzer.cs old mode 100644 new mode 100755 index d083ee70d..660887266 --- a/src/Meziantou.Analyzer/Rules/ValidateArgumentsCorrectlyAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/ValidateArgumentsCorrectlyAnalyzer.cs @@ -101,7 +101,7 @@ private bool IsArgumentValidation(SyntaxNodeAnalysisContext context, SyntaxNode { if ((node.IsKind(SyntaxKind.ThrowStatement) || node.IsKind(SyntaxKind.ThrowExpression)) && IsArgumentException(context, node)) return true; - + if (node is InvocationExpressionSyntax invocationExpression) { if (context.SemanticModel.GetOperation(invocationExpression, context.CancellationToken) is IInvocationOperation operation) diff --git a/tests/Meziantou.Analyzer.Test/Helpers/DiagnosticResult.cs b/tests/Meziantou.Analyzer.Test/Helpers/DiagnosticResult.cs old mode 100644 new mode 100755 index d9c89f624..b7c7b9611 --- a/tests/Meziantou.Analyzer.Test/Helpers/DiagnosticResult.cs +++ b/tests/Meziantou.Analyzer.Test/Helpers/DiagnosticResult.cs @@ -10,7 +10,7 @@ public sealed class DiagnosticResult public IReadOnlyList Locations { - get => _locations ??= Array.Empty(); + get => _locations ??= []; set => _locations = value; } diff --git a/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.Validation.cs b/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.Validation.cs old mode 100644 new mode 100755 index 333de9a32..1520d8be0 --- a/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.Validation.cs +++ b/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.Validation.cs @@ -204,7 +204,7 @@ private Task CreateProject() AddNuGetReference("Microsoft.NETCore.App.Ref", "7.0.0", "ref/net7.0/"); AddNuGetReference("Microsoft.AspNetCore.App.Ref", "7.0.0", "ref/net7.0/"); break; - + case TargetFramework.AspNetCore8_0: AddNuGetReference("Microsoft.NETCore.App.Ref", "8.0.0", "ref/net8.0/"); AddNuGetReference("Microsoft.AspNetCore.App.Ref", "8.0.0", "ref/net8.0/"); @@ -262,7 +262,7 @@ private static ReportDiagnostic GetReportDiagnostic(DiagnosticDescriptor descrip }; } - [DebuggerStepThrough] + //[DebuggerStepThrough] private async Task GetSortedDiagnosticsFromDocuments(IList analyzers, Document[] documents, bool compileSolution) { var projects = new HashSet(); diff --git a/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.cs b/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.cs old mode 100644 new mode 100755 index 3b97928e9..b83656426 --- a/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.cs +++ b/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.cs @@ -105,11 +105,12 @@ public ProjectBuilder AddNuGetReference(string packageName, string version, stri public ProjectBuilder WithAnalyzerFromNuGet(string packageName, string version, string[] paths, string[] ruleIds) { + var ruleFound = false; var references = GetNuGetReferences(packageName, version, paths).Result; foreach (var reference in references) { var assembly = Assembly.LoadFrom(reference); - foreach (var type in assembly.GetExportedTypes()) + foreach (var type in assembly.GetTypes()) { if (type.IsAbstract || !typeof(DiagnosticAnalyzer).IsAssignableFrom(type)) continue; @@ -118,10 +119,14 @@ public ProjectBuilder WithAnalyzerFromNuGet(string packageName, string version, if (instance.SupportedDiagnostics.Any(d => ruleIds.Contains(d.Id, StringComparer.Ordinal))) { DiagnosticAnalyzer.Add(instance); + ruleFound = true; } } } + if (!ruleFound) + throw new InvalidOperationException("Rule id not found"); + return this; } @@ -132,6 +137,13 @@ public ProjectBuilder WithMicrosoftCodeAnalysisNetAnalyzers(params string[] rule paths: ["analyzers/dotnet/cs/Microsoft.CodeAnalysis"], ruleIds); + public ProjectBuilder WithMicrosoftCodeAnalysisCSharpCodeStyleAnalyzers(params string[] ruleIds) => + WithAnalyzerFromNuGet( + "Microsoft.CodeAnalysis.CSharp.CodeStyle", + "4.10.0-2.final", + paths: ["analyzers/dotnet/cs/"], + ruleIds); + public ProjectBuilder AddMSTestApi() => AddNuGetReference("MSTest.TestFramework", "2.1.1", "lib/netstandard1.0/"); public ProjectBuilder AddNUnitApi() => AddNuGetReference("NUnit", "3.12.0", "lib/netstandard2.0/"); diff --git a/tests/Meziantou.Analyzer.Test/RuleHelpUri.cs b/tests/Meziantou.Analyzer.Test/RuleHelpUri.cs new file mode 100755 index 000000000..18feb4c1b --- /dev/null +++ b/tests/Meziantou.Analyzer.Test/RuleHelpUri.cs @@ -0,0 +1,27 @@ +using System; +using Meziantou.Analyzer.Rules; +using Microsoft.CodeAnalysis.Diagnostics; +using Xunit; + +namespace Meziantou.Analyzer.Test; +public sealed class RuleHelpUri +{ + [Fact] + public void HelpUriIsSet() + { + foreach (var type in typeof(AbstractTypesShouldNotHaveConstructorsAnalyzer).Assembly.GetExportedTypes()) + { + if (type.IsAbstract) + continue; + + if (!typeof(DiagnosticAnalyzer).IsAssignableFrom(type)) + continue; + + var instance = (DiagnosticAnalyzer)Activator.CreateInstance(type); + foreach (var diag in instance.SupportedDiagnostics) + { + Assert.Equal($"https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/{diag.Id}.md", diag.HelpLinkUri); + } + } + } +} diff --git a/tests/Meziantou.Analyzer.Test/Rules/AddOverloadWithSpanOrMemoryAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/AddOverloadWithSpanOrMemoryAnalyzerTests.cs old mode 100644 new mode 100755 index 3f431ed4d..8ff4ca7ac --- a/tests/Meziantou.Analyzer.Test/Rules/AddOverloadWithSpanOrMemoryAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/AddOverloadWithSpanOrMemoryAnalyzerTests.cs @@ -29,7 +29,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task StringArrayWithoutSpanOverload_Out() { @@ -43,7 +43,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task StringArrayWithSpanOverload_Params() { @@ -58,7 +58,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task StringArrayWithoutSpanOverload() { @@ -74,7 +74,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task StringArrayWithoutSpanOverload_Complex() { @@ -111,7 +111,7 @@ await CreateProjectBuilder() .WithSourceCode(sourceCode) .ValidateAsync(); } - + [Theory] [InlineData("System.Span")] [InlineData("System.ReadOnlySpan")] diff --git a/tests/Meziantou.Analyzer.Test/Rules/ArgumentExceptionShouldSpecifyArgumentNameAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/ArgumentExceptionShouldSpecifyArgumentNameAnalyzerTests.cs old mode 100644 new mode 100755 index 9bb50c6ee..2c70c8da2 --- a/tests/Meziantou.Analyzer.Test/Rules/ArgumentExceptionShouldSpecifyArgumentNameAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/ArgumentExceptionShouldSpecifyArgumentNameAnalyzerTests.cs @@ -49,7 +49,7 @@ await CreateProjectBuilder() .WithSourceCode(sourceCode) .ValidateAsync(); } - + [Fact] public async Task ArgumentNameIsSpecified_LocalFunction_Static_ShouldNotReportError() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/AwaitAwaitableMethodInSyncMethodAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/AwaitAwaitableMethodInSyncMethodAnalyzerTests.cs old mode 100644 new mode 100755 index d37342ec3..6b2ba0464 --- a/tests/Meziantou.Analyzer.Test/Rules/AwaitAwaitableMethodInSyncMethodAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/AwaitAwaitableMethodInSyncMethodAnalyzerTests.cs @@ -289,7 +289,7 @@ int A """) .ValidateAsync(); } - + [Fact] public async Task Report_TaskInLocalFunction() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/AwaitTaskBeforeDisposingResourcesAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/AwaitTaskBeforeDisposingResourcesAnalyzerTests.cs old mode 100644 new mode 100755 index 361ecd480..0785f6a4f --- a/tests/Meziantou.Analyzer.Test/Rules/AwaitTaskBeforeDisposingResourcesAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/AwaitTaskBeforeDisposingResourcesAnalyzerTests.cs @@ -59,7 +59,7 @@ await CreateProjectBuilder() .WithSourceCode(originalCode) .ValidateAsync(); } - + [Fact] public async Task NotAwaitedTaskYieldMethod_InUsing() { @@ -82,7 +82,7 @@ await CreateProjectBuilder() .WithSourceCode(originalCode) .ValidateAsync(); } - + [Fact] public async Task NotAwaitedExtensionMethodOnInt32_InUsing() { @@ -107,7 +107,7 @@ await CreateProjectBuilder() .WithSourceCode(originalCode) .ValidateAsync(); } - + [Fact] public async Task NotAwaitedExtensionMethodOnValueTuple_InUsing() { @@ -325,7 +325,7 @@ await CreateProjectBuilder() .WithSourceCode(originalCode) .ValidateAsync(); } - + [Fact] public async Task NotAwaitedDefaultValueTask_InUsing() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/ClassMustBeSealedAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/ClassMustBeSealedAnalyzerTests.cs old mode 100644 new mode 100755 index e8986177b..ec63074b1 --- a/tests/Meziantou.Analyzer.Test/Rules/ClassMustBeSealedAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/ClassMustBeSealedAnalyzerTests.cs @@ -149,7 +149,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task Exception_ConfigEnabled() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/DebuggerDisplayAttributeShouldContainValidExpressionsAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/DebuggerDisplayAttributeShouldContainValidExpressionsAnalyzerTests.cs old mode 100644 new mode 100755 index e70b62df8..a1101a447 --- a/tests/Meziantou.Analyzer.Test/Rules/DebuggerDisplayAttributeShouldContainValidExpressionsAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/DebuggerDisplayAttributeShouldContainValidExpressionsAnalyzerTests.cs @@ -33,7 +33,7 @@ await CreateProjectBuilder() .WithSourceCode(sourceCode) .ValidateAsync(); } - + [Theory] [InlineData("Invalid")] [InlineData("Invalid,np")] @@ -53,7 +53,7 @@ await CreateProjectBuilder() .WithSourceCode(sourceCode) .ValidateAsync(); } - + [Theory] [InlineData("Invalid")] [InlineData("Invalid,np")] @@ -89,7 +89,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task Valid_Name() { @@ -105,7 +105,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task Valid_Type() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/DoNotLogClassifiedDataAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/DoNotLogClassifiedDataAnalyzerTests.cs old mode 100644 new mode 100755 index 23a6f239a..48c704019 --- a/tests/Meziantou.Analyzer.Test/Rules/DoNotLogClassifiedDataAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/DoNotLogClassifiedDataAnalyzerTests.cs @@ -37,7 +37,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task Logger_LogInformation_DataClassification_Property() { @@ -62,7 +62,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task Logger_LogInformation_DataClassification_Property_Array() { @@ -87,7 +87,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task Logger_LogInformation_DataClassification_Field() { @@ -112,7 +112,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task Logger_LogInformation_DataClassification_Parameter() { @@ -141,7 +141,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task Logger_BeginScope_DataClassification_Parameter() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/DoNotUseAsyncDelegateForSyncDelegateAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/DoNotUseAsyncDelegateForSyncDelegateAnalyzerTests.cs old mode 100644 new mode 100755 index 3b3105c06..d6889b2f5 --- a/tests/Meziantou.Analyzer.Test/Rules/DoNotUseAsyncDelegateForSyncDelegateAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/DoNotUseAsyncDelegateForSyncDelegateAnalyzerTests.cs @@ -34,7 +34,7 @@ await CreateProjectBuilder() """) .ValidateAsync(); } - + [Fact] public async Task CustomDelegate_Sync() { @@ -47,7 +47,7 @@ await CreateProjectBuilder() """) .ValidateAsync(); } - + [Fact] public async Task CustomDelegate_AsyncVoid() { @@ -60,7 +60,7 @@ await CreateProjectBuilder() """) .ValidateAsync(); } - + [Fact] public async Task Action_Sync() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/DoNotUseImplicitCultureSensitiveToStringAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/DoNotUseImplicitCultureSensitiveToStringAnalyzerTests.cs old mode 100644 new mode 100755 index 539d2dda7..6c28b187f --- a/tests/Meziantou.Analyzer.Test/Rules/DoNotUseImplicitCultureSensitiveToStringAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/DoNotUseImplicitCultureSensitiveToStringAnalyzerTests.cs @@ -126,7 +126,7 @@ await CreateProjectBuilder() } [Fact] - public async Task Concat_Char_String_NoDiagnostic() + public async Task Concat_Char_String_NoDiagnostic() { var sourceCode = """ class Test @@ -266,7 +266,7 @@ await CreateProjectBuilder() .WithSourceCode(sourceCode) .ValidateAsync(); } - + [Fact] public async Task StringConcat_ToString_Int32ToString_ConfigNotExcludeToString() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/DoNotUseToStringIfObjectAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/DoNotUseToStringIfObjectAnalyzerTests.cs old mode 100644 new mode 100755 index 7abcb1822..3687f82a1 --- a/tests/Meziantou.Analyzer.Test/Rules/DoNotUseToStringIfObjectAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/DoNotUseToStringIfObjectAnalyzerTests.cs @@ -282,7 +282,7 @@ await CreateProjectBuilder() .WithSourceCode(sourceCode) .ValidateAsync(); } - + [Fact] public async Task Interpolation_AnonymousType() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/DoNotUseUnknownParameterForRazorComponentAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/DoNotUseUnknownParameterForRazorComponentAnalyzerTests.cs old mode 100644 new mode 100755 index 32f3e4f56..d96fad802 --- a/tests/Meziantou.Analyzer.Test/Rules/DoNotUseUnknownParameterForRazorComponentAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/DoNotUseUnknownParameterForRazorComponentAnalyzerTests.cs @@ -52,7 +52,7 @@ public class SampleComponent : CustomComponentBase public string Param2 { get; set; } } """"; - + private const string ComponentWithChildContent = """" public class CustomComponentBase : ComponentBase { @@ -180,7 +180,7 @@ await CreateProjectBuilder() .WithSourceCode(Usings + sourceCode + ComponentWithInheritedParameter) .ValidateAsync(); } - + [Fact] public async Task InvalidParameterInChildContent() { @@ -214,7 +214,7 @@ await CreateProjectBuilder() .WithSourceCode(Usings + sourceCode + ComponentWithChildContent) .ValidateAsync(); } - + [Fact] public async Task InvalidParameterInAddComponentParameter_Net8() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/EventsShouldHaveProperArgumentsAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/EventsShouldHaveProperArgumentsAnalyzerTests.cs old mode 100644 new mode 100755 index 69cf8a4be..ccff4fcbf --- a/tests/Meziantou.Analyzer.Test/Rules/EventsShouldHaveProperArgumentsAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/EventsShouldHaveProperArgumentsAnalyzerTests.cs @@ -133,7 +133,7 @@ await CreateProjectBuilder() .ShouldFixCodeWith(Fix) .ValidateAsync(); } - + [Fact] public async Task InvalidEventArgs_NamedArgument() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/FileNameMustMatchTypeNameAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/FileNameMustMatchTypeNameAnalyzerTests.cs old mode 100644 new mode 100755 index 0121c613a..196e7844c --- a/tests/Meziantou.Analyzer.Test/Rules/FileNameMustMatchTypeNameAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/FileNameMustMatchTypeNameAnalyzerTests.cs @@ -34,7 +34,7 @@ class Sample }") .ValidateAsync(); } - + [Fact] public async Task MatchFileName() { @@ -171,7 +171,7 @@ class Sample {} .AddAnalyzerConfiguration("MA0048.only_validate_first_type", "true") .ValidateAsync(); } - + [Fact] public async Task MatchOnlyFirstType_class3() { @@ -183,7 +183,7 @@ class Test0 {} .AddAnalyzerConfiguration("MA0048.only_validate_first_type", "true") .ValidateAsync(); } - + [Fact] public async Task MatchOnlyFirstType_Enum() { @@ -195,7 +195,7 @@ enum Bar {} .AddAnalyzerConfiguration("MA0048.only_validate_first_type", "true") .ValidateAsync(); } - + [Fact] public async Task MatchOnlyFirstType_Interface() { @@ -206,8 +206,8 @@ interface Bar {} """) .AddAnalyzerConfiguration("MA0048.only_validate_first_type", "true") .ValidateAsync(); - } - + } + [Fact] public async Task MatchOnlyFirstType_Record() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/LoggerParameterTypeAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/LoggerParameterTypeAnalyzerTests.cs old mode 100644 new mode 100755 index 3a3b59bfe..91031c98f --- a/tests/Meziantou.Analyzer.Test/Rules/LoggerParameterTypeAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/LoggerParameterTypeAnalyzerTests.cs @@ -296,7 +296,7 @@ await CreateProjectBuilder() Prop;System.String """) .ValidateAsync(); - } + } [Fact] public async Task Logger_LogTrace_InvalidParameterType_NullableReferenceType() @@ -353,7 +353,7 @@ await CreateProjectBuilder() """) .ValidateAsync(); } - + [Fact] public async Task Configuration_UnknownParameterType() { @@ -406,7 +406,7 @@ await CreateProjectBuilder() .ShouldReportDiagnosticWithMessage("Log parameter 'Prop' has no configured type") .ValidateAsync(); } - + [Fact] public async Task DeniedParameter() { @@ -426,7 +426,7 @@ await CreateProjectBuilder() .ShouldReportDiagnosticWithMessage("Log parameter 'Prop' is not allowed by configuration") .ValidateAsync(); } - + [Fact] public async Task DeniedParameterWithoutSemiColon() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/MakeClassStaticAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/MakeClassStaticAnalyzerTests.cs old mode 100644 new mode 100755 index b5e1b7927..134755c18 --- a/tests/Meziantou.Analyzer.Test/Rules/MakeClassStaticAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/MakeClassStaticAnalyzerTests.cs @@ -306,7 +306,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + #if CSHARP10_OR_GREATER [Fact] public async Task TopLevelStatement_10() diff --git a/tests/Meziantou.Analyzer.Test/Rules/NamedParameterAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/NamedParameterAnalyzerTests.cs old mode 100644 new mode 100755 index 077a82352..7165b5131 --- a/tests/Meziantou.Analyzer.Test/Rules/NamedParameterAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/NamedParameterAnalyzerTests.cs @@ -710,7 +710,7 @@ void EnableTest(bool value) { } ") .ValidateAsync(); } - + [Fact] public async Task List_Add() { @@ -744,7 +744,7 @@ void A() ") .ValidateAsync(); } - + [Fact] public async Task Expression_Constant() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/OptimizeLinqUsageAnalyzerUseDirectMethodsTests.cs b/tests/Meziantou.Analyzer.Test/Rules/OptimizeLinqUsageAnalyzerUseDirectMethodsTests.cs old mode 100644 new mode 100755 index b8dbe0361..4e3f36156 --- a/tests/Meziantou.Analyzer.Test/Rules/OptimizeLinqUsageAnalyzerUseDirectMethodsTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/OptimizeLinqUsageAnalyzerUseDirectMethodsTests.cs @@ -105,7 +105,7 @@ await CreateProjectBuilder() .ShouldFixCodeWith(CodeFix) .ValidateAsync(); } - + [Fact] public async Task TrueForAll() { @@ -193,7 +193,7 @@ await CreateProjectBuilder() .ShouldFixCodeWith(CodeFix) .ValidateAsync(); } - + [Fact] public async Task Exists() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/OptimizeStartsWithAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/OptimizeStartsWithAnalyzerTests.cs old mode 100644 new mode 100755 index 520388c84..b058ff521 --- a/tests/Meziantou.Analyzer.Test/Rules/OptimizeStartsWithAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/OptimizeStartsWithAnalyzerTests.cs @@ -42,7 +42,7 @@ void A(string str) """) .ValidateAsync(); } - + [Theory] [InlineData("""[|"a"|], StringComparison.Ordinal""", """'a'""")] public async Task StartsWith_Report(string method, string fix) diff --git a/tests/Meziantou.Analyzer.Test/Rules/OptimizeStringBuilderUsageAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/OptimizeStringBuilderUsageAnalyzerTests.cs old mode 100644 new mode 100755 index 45fc6150a..f994c2508 --- a/tests/Meziantou.Analyzer.Test/Rules/OptimizeStringBuilderUsageAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/OptimizeStringBuilderUsageAnalyzerTests.cs @@ -542,7 +542,7 @@ void A() }") .ValidateAsync(); } - + [Fact] public async Task Append_StringJoin_AppendJoin_OldTargetFramework() { @@ -557,7 +557,7 @@ void A(string format) }") .ValidateAsync(); } - + [Fact] public async Task Append_StringJoin_AppendJoin() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/PrimaryConstructorParameterShouldBeReadOnlyAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/PrimaryConstructorParameterShouldBeReadOnlyAnalyzerTests.cs old mode 100644 new mode 100755 index 7b054a3ae..109597abe --- a/tests/Meziantou.Analyzer.Test/Rules/PrimaryConstructorParameterShouldBeReadOnlyAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/PrimaryConstructorParameterShouldBeReadOnlyAnalyzerTests.cs @@ -159,7 +159,7 @@ void A() """) .ValidateAsync(); } - + [Fact] public async Task Argument() { @@ -175,7 +175,7 @@ void A(string value) """) .ValidateAsync(); } - + [Fact] public async Task EditUsingRefVariable() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/RemoveEmptyStatementAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/RemoveEmptyStatementAnalyzerTests.cs old mode 100644 new mode 100755 index 48e0a327f..e07f182c9 --- a/tests/Meziantou.Analyzer.Test/Rules/RemoveEmptyStatementAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/RemoveEmptyStatementAnalyzerTests.cs @@ -37,7 +37,7 @@ await CreateProjectBuilder() .ShouldFixCodeWith(Fix) .ValidateAsync(); } - + [Fact] public async Task EmptyInLoopStatement() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/StringShouldNotContainsNonDeterministicEndOfLineAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/StringShouldNotContainsNonDeterministicEndOfLineAnalyzerTests.cs old mode 100644 new mode 100755 index 80245a091..1ae499e9e --- a/tests/Meziantou.Analyzer.Test/Rules/StringShouldNotContainsNonDeterministicEndOfLineAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/StringShouldNotContainsNonDeterministicEndOfLineAnalyzerTests.cs @@ -139,7 +139,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task VerbatimU8String() { @@ -160,7 +160,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task U8RawString() { @@ -205,7 +205,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task SingleLineRawString2() { @@ -224,7 +224,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task RawString() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/TaskInUsingAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/TaskInUsingAnalyzerTests.cs old mode 100644 new mode 100755 index 49b8fdbee..8d8abd054 --- a/tests/Meziantou.Analyzer.Test/Rules/TaskInUsingAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/TaskInUsingAnalyzerTests.cs @@ -28,7 +28,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task SingleTaskAssignedInUsing() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/UseDateTimeUnixEpochAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/UseDateTimeUnixEpochAnalyzerTests.cs old mode 100644 new mode 100755 index f0c9f0336..7189cdeaf --- a/tests/Meziantou.Analyzer.Test/Rules/UseDateTimeUnixEpochAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/UseDateTimeUnixEpochAnalyzerTests.cs @@ -47,7 +47,7 @@ await CreateProjectBuilder() .ShouldFixCodeWith(fix) .ValidateAsync(); } - + [Theory] [InlineData("new DateTimeOffset(DateTime.UnixEpoch)")] [InlineData("new DateTimeOffset(DateTime.UnixEpoch, TimeSpan.Zero)")] diff --git a/tests/Meziantou.Analyzer.Test/Rules/UseIFormatProviderAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/UseIFormatProviderAnalyzerTests.cs old mode 100644 new mode 100755 index e68cc045a..eb6a7fef2 --- a/tests/Meziantou.Analyzer.Test/Rules/UseIFormatProviderAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/UseIFormatProviderAnalyzerTests.cs @@ -45,7 +45,7 @@ await CreateProjectBuilder() .ShouldReportDiagnosticWithMessage("Use an overload of 'ToString' that has a 'System.IFormatProvider' parameter") .ValidateAsync(); } - + [Fact] public async Task Int32_PositiveToStringWithoutCultureInfo_ShouldReportDiagnostic() { @@ -94,7 +94,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task SystemTimeSpanToStringWithoutCultureInfo_ShouldNotReportDiagnostic() { @@ -110,7 +110,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task SystemTimeSpanImplicitToStringWithoutCultureInfo_InterpolatedString_ShouldNotReportDiagnostic() { @@ -128,7 +128,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task SystemTimeSpanToStringWithoutCultureInfo_FormatC_ShouldNotReportDiagnostic() { @@ -144,7 +144,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task SystemTimeSpanToStringWithoutCultureInfo_FormatT_ShouldNotReportDiagnostic() { @@ -160,7 +160,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task SystemTimeSpanToStringWithoutCultureInfo_FormatG_ShouldReportDiagnostic() { @@ -518,7 +518,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task NullableInt32ToStringWithoutCultureInfo() { @@ -535,7 +535,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task NullableInt32ToStringWithoutCultureInfo_DisabledConfig() { @@ -552,7 +552,7 @@ await CreateProjectBuilder() .AddAnalyzerConfiguration("MA0011.consider_nullable_types", "false") .ValidateAsync(); } - + [Fact] public async Task StringFormat_ArgsAreNonCultureSensitive() { @@ -569,7 +569,7 @@ await CreateProjectBuilder() .WithSourceCode(sourceCode) .ValidateAsync(); } - + [Fact] public async Task StringFormat_AlreadyHasFormatProvider() { @@ -586,7 +586,7 @@ await CreateProjectBuilder() .WithSourceCode(sourceCode) .ValidateAsync(); } - + [Fact] public async Task StringFormat_NoArgument() { @@ -603,7 +603,7 @@ await CreateProjectBuilder() .WithSourceCode(sourceCode) .ValidateAsync(); } - + [Fact] public async Task StringFormat_Report() { @@ -620,7 +620,7 @@ await CreateProjectBuilder() .WithSourceCode(sourceCode) .ValidateAsync(); } - + [Fact] public async Task StringFormat_ManyArgs_Report() { @@ -637,7 +637,7 @@ await CreateProjectBuilder() .WithSourceCode(sourceCode) .ValidateAsync(); } - + [Fact] public async Task Convert_ToChar_Object() { @@ -654,7 +654,7 @@ await CreateProjectBuilder() .WithSourceCode(sourceCode) .ValidateAsync(); } - + [Fact] public async Task Convert_ToChar_String() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/UseJSRuntimeInvokeVoidAsyncWhenReturnValueIsNotUsedTests.cs b/tests/Meziantou.Analyzer.Test/Rules/UseJSRuntimeInvokeVoidAsyncWhenReturnValueIsNotUsedTests.cs old mode 100644 new mode 100755 index ebefdd874..7e3a71b7d --- a/tests/Meziantou.Analyzer.Test/Rules/UseJSRuntimeInvokeVoidAsyncWhenReturnValueIsNotUsedTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/UseJSRuntimeInvokeVoidAsyncWhenReturnValueIsNotUsedTests.cs @@ -46,7 +46,7 @@ async Task A() ") .ValidateAsync(); } - + [Fact] public async Task IJSRuntime_InvokeAsyncExplicit_ReturnNotUsed() { @@ -79,7 +79,7 @@ async Task A() ") .ValidateAsync(); } - + [Fact] public async Task IJSRuntime_InvokeAsyncExplicitWithCancellationToken_ReturnNotUsed() { @@ -134,7 +134,7 @@ async Task A() ") .ValidateAsync(); } - + [Fact] public async Task IJSRuntime_InvokeAsync_ReturnAsArgument() { @@ -154,7 +154,7 @@ async Task A() ") .ValidateAsync(); } - + [Fact] public async Task IJSRuntime_InvokeVoidAsync() { @@ -194,7 +194,7 @@ async Task A() ") .ValidateAsync(); } - + [Fact] public async Task IJSInProcessRuntime_InvokeVoid() { @@ -214,7 +214,7 @@ void A() ") .ValidateAsync(); } - + [Fact] public async Task IJSInProcessRuntime_InvokeAsync_ReturnNotUsed() { @@ -246,8 +246,8 @@ async Task A() } ") .ValidateAsync(); - } - + } + [Fact] public async Task IJSInProcessRuntime_Invoke_ReturnNotUsed() { @@ -280,7 +280,7 @@ void A() ") .ValidateAsync(); } - + [Fact] public async Task IJSInProcessRuntime_InvokeAsync_ReturnAssigned() { @@ -300,7 +300,7 @@ async Task A() ") .ValidateAsync(); } - + [Fact] public async Task IJSInProcessRuntime_Invoke_ReturnAssigned() { @@ -319,5 +319,5 @@ void A() } ") .ValidateAsync(); - } + } } diff --git a/tests/Meziantou.Analyzer.Test/Rules/UsePatternMatchingForEqualityComparisonsAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/UsePatternMatchingForEqualityComparisonsAnalyzerTests.cs old mode 100644 new mode 100755 index 5faf79996..acfff5214 --- a/tests/Meziantou.Analyzer.Test/Rules/UsePatternMatchingForEqualityComparisonsAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/UsePatternMatchingForEqualityComparisonsAnalyzerTests.cs @@ -27,7 +27,7 @@ await CreateProjectBuilder() """) .ValidateAsync(); } - + [Fact] public async Task NullCheckForNullableOfT() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/UseRegexTimeoutAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/UseRegexTimeoutAnalyzerTests.cs old mode 100644 new mode 100755 index 30d6bf468..7b7f2ab0d --- a/tests/Meziantou.Analyzer.Test/Rules/UseRegexTimeoutAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/UseRegexTimeoutAnalyzerTests.cs @@ -45,7 +45,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task IsMatch_NonBacktracking_WithoutTimeout_ShouldNotReportError() { @@ -94,7 +94,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task Ctor_WithoutTimeout_NonBacktracking_ShouldNotReportError() { @@ -150,7 +150,7 @@ partial class TestClass await project.ValidateAsync(); } - + [Fact] public async Task GeneratedRegex_WithTimeout() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/UseStringComparerAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/UseStringComparerAnalyzerTests.cs old mode 100644 new mode 100755 index 7541477be..c5ad2a7da --- a/tests/Meziantou.Analyzer.Test/Rules/UseStringComparerAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/UseStringComparerAnalyzerTests.cs @@ -254,7 +254,7 @@ await CreateProjectBuilder() .ShouldFixCodeWith(CodeFix) .ValidateAsync(); } - + [Fact] public async Task OrderBy_String_ShouldReportDiagnostic() { @@ -281,7 +281,7 @@ await CreateProjectBuilder() .ShouldFixCodeWith(CodeFix) .ValidateAsync(); } - + [Fact] public async Task OrderByDescending_String_ShouldReportDiagnostic() { @@ -308,7 +308,7 @@ await CreateProjectBuilder() .ShouldFixCodeWith(CodeFix) .ValidateAsync(); } - + [Fact] public async Task ThenBy_String_ShouldReportDiagnostic() { @@ -335,7 +335,7 @@ await CreateProjectBuilder() .ShouldFixCodeWith(CodeFix) .ValidateAsync(); } - + [Fact] public async Task ThenByDescending_String_ShouldReportDiagnostic() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/UseStringComparisonAnalyzerNonCultureSensitiveTests.cs b/tests/Meziantou.Analyzer.Test/Rules/UseStringComparisonAnalyzerNonCultureSensitiveTests.cs old mode 100644 new mode 100755 index 8a84cbfdf..e078333e6 --- a/tests/Meziantou.Analyzer.Test/Rules/UseStringComparisonAnalyzerNonCultureSensitiveTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/UseStringComparisonAnalyzerNonCultureSensitiveTests.cs @@ -82,7 +82,7 @@ await CreateProjectBuilder() .ShouldFixCodeWith(CodeFix) .ValidateAsync(); } - + [Fact] public async Task String_GetHashCode_ShouldReportDiagnostic() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/UseStringCreateInsteadOfFormattableStringAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/UseStringCreateInsteadOfFormattableStringAnalyzerTests.cs old mode 100644 new mode 100755 index e0c0c1230..312ac1057 --- a/tests/Meziantou.Analyzer.Test/Rules/UseStringCreateInsteadOfFormattableStringAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/UseStringCreateInsteadOfFormattableStringAnalyzerTests.cs @@ -110,7 +110,7 @@ await CreateProjectBuilder() .ShouldFixCodeWith(Fix) .ValidateAsync(); } - + [Fact] public async Task FormattableStringCurrentCulture() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/UseStringEqualsInsteadOfIsPatternAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/UseStringEqualsInsteadOfIsPatternAnalyzerTests.cs old mode 100644 new mode 100755 index bf04c4868..5e41a9aa0 --- a/tests/Meziantou.Analyzer.Test/Rules/UseStringEqualsInsteadOfIsPatternAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/UseStringEqualsInsteadOfIsPatternAnalyzerTests.cs @@ -48,7 +48,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task IsNotNull() { @@ -66,7 +66,7 @@ await CreateProjectBuilder() .WithSourceCode(SourceCode) .ValidateAsync(); } - + [Fact] public async Task PatternMatching() { diff --git a/tests/Meziantou.Analyzer.Test/Rules/UseTaskUnwrapAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/UseTaskUnwrapAnalyzerTests.cs old mode 100644 new mode 100755 index b4a3d6cb1..a4aa170a2 --- a/tests/Meziantou.Analyzer.Test/Rules/UseTaskUnwrapAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/UseTaskUnwrapAnalyzerTests.cs @@ -27,7 +27,7 @@ await CreateProjectBuilder() """) .ValidateAsync(); } - + [Fact] public async Task TaskOfTask_ConfigureAwait() { @@ -40,7 +40,7 @@ await CreateProjectBuilder() """) .ValidateAsync(); } - + [Fact] public async Task TaskOfTask_ConfigureAwait_Root() { @@ -53,7 +53,7 @@ await CreateProjectBuilder() """) .ValidateAsync(); } - + [Fact] public async Task TaskOfTask_Unwrap_ConfigureAwait_Root() { @@ -79,7 +79,7 @@ await CreateProjectBuilder() """) .ValidateAsync(); } - + [Fact] public async Task TaskOfValueTaskOfInt32() {