diff --git a/TUnit.Analyzers.CodeFixers/Base/AssertionRewriter.cs b/TUnit.Analyzers.CodeFixers/Base/AssertionRewriter.cs index 671ccf5c0f..80437c4ac3 100644 --- a/TUnit.Analyzers.CodeFixers/Base/AssertionRewriter.cs +++ b/TUnit.Analyzers.CodeFixers/Base/AssertionRewriter.cs @@ -70,7 +70,7 @@ protected AssertionRewriter(SemanticModel semanticModel) // Conversion added trivia (TODO comments). Structure should be: // [original whitespace] [TODO comment] [newline] [original whitespace] [await expression] var whitespaceTrivia = originalTrivia.Where(t => t.IsKind(SyntaxKind.WhitespaceTrivia)).ToList(); - var nonWhitespaceTrivia = originalTrivia.Where(t => !t.IsKind(SyntaxKind.WhitespaceTrivia)).ToList(); + var nonWhitespaceTrivia = originalTrivia.Where(t => !t.IsKind(SyntaxKind.WhitespaceTrivia)); var builder = new List(); builder.AddRange(nonWhitespaceTrivia); // Add any non-whitespace (e.g., leading newlines) diff --git a/TUnit.Analyzers.CodeFixers/Base/TestAttributeEnsurer.cs b/TUnit.Analyzers.CodeFixers/Base/TestAttributeEnsurer.cs index ba0c546e87..ed802e0189 100644 --- a/TUnit.Analyzers.CodeFixers/Base/TestAttributeEnsurer.cs +++ b/TUnit.Analyzers.CodeFixers/Base/TestAttributeEnsurer.cs @@ -121,8 +121,7 @@ private static MethodDeclarationSyntax AddTestAttribute(MethodDeclarationSyntax // Strip newlines from first attribute's leading trivia, keep only indentation // This prevents double newlines when we insert [Test] before it var strippedTrivia = firstAttributeList.GetLeadingTrivia() - .Where(t => !t.IsKind(SyntaxKind.EndOfLineTrivia)) - .ToList(); + .Where(t => !t.IsKind(SyntaxKind.EndOfLineTrivia)); var updatedFirstAttr = firstAttributeList.WithLeadingTrivia(strippedTrivia); // Build new attribute list: [Test], then updated first attr (with stripped trivia), then rest diff --git a/TUnit.Analyzers.CodeFixers/Base/TwoPhase/MigrationAnalyzer.cs b/TUnit.Analyzers.CodeFixers/Base/TwoPhase/MigrationAnalyzer.cs index 64a9268540..0aabaa76b7 100644 --- a/TUnit.Analyzers.CodeFixers/Base/TwoPhase/MigrationAnalyzer.cs +++ b/TUnit.Analyzers.CodeFixers/Base/TwoPhase/MigrationAnalyzer.cs @@ -144,7 +144,7 @@ protected bool IsInterfaceImplementation(TextSpan methodSpan) protected virtual CompilationUnitSyntax AnalyzeAssertions(CompilationUnitSyntax root) { // Find assertions on the ORIGINAL tree (for semantic analysis) - var assertionNodes = FindAssertionNodes(_originalRoot).ToList(); + var assertionNodes = FindAssertionNodes(_originalRoot); var currentRoot = root; foreach (var originalNode in assertionNodes) @@ -238,7 +238,7 @@ private static bool ContainingMethodHasRefOrOutParameters(SyntaxNode node) /// protected virtual CompilationUnitSyntax AnalyzeAttributes(CompilationUnitSyntax root) { - var attributeNodes = _originalRoot.DescendantNodes().OfType().ToList(); + var attributeNodes = _originalRoot.DescendantNodes().OfType(); var currentRoot = root; foreach (var originalNode in attributeNodes) @@ -338,7 +338,7 @@ protected bool IsFrameworkAttribute(AttributeSyntax node) /// protected virtual CompilationUnitSyntax AnalyzeParameterAttributes(CompilationUnitSyntax root) { - var parameterNodes = _originalRoot.DescendantNodes().OfType().ToList(); + var parameterNodes = _originalRoot.DescendantNodes().OfType(); var currentRoot = root; foreach (var parameter in parameterNodes) @@ -409,7 +409,7 @@ protected virtual CompilationUnitSyntax AnalyzeMethodsForMissingAttributes(Compi /// protected virtual CompilationUnitSyntax AnalyzeBaseTypes(CompilationUnitSyntax root) { - var classNodes = _originalRoot.DescendantNodes().OfType().ToList(); + var classNodes = _originalRoot.DescendantNodes().OfType(); var currentRoot = root; foreach (var classNode in classNodes) diff --git a/TUnit.Analyzers.CodeFixers/NUnitAssertMultipleRewriter.cs b/TUnit.Analyzers.CodeFixers/NUnitAssertMultipleRewriter.cs index 75fc067c82..c15fb8e190 100644 --- a/TUnit.Analyzers.CodeFixers/NUnitAssertMultipleRewriter.cs +++ b/TUnit.Analyzers.CodeFixers/NUnitAssertMultipleRewriter.cs @@ -44,7 +44,7 @@ private SyntaxNode ConvertAssertMultipleLambda(ExpressionStatementSyntax origina if (lambda.Body is BlockSyntax block) { // Visit each statement to convert inner assertions - var convertedStatements = block.Statements.Select(s => (StatementSyntax)Visit(s)!).ToArray(); + var convertedStatements = block.Statements.Select(s => (StatementSyntax)Visit(s)!); statements = SyntaxFactory.List(convertedStatements); } else if (lambda.Body is ExpressionSyntax expr) @@ -67,7 +67,7 @@ private SyntaxNode ConvertAssertMultipleSimpleLambda(ExpressionStatementSyntax o SyntaxList statements; if (lambda.Body is BlockSyntax block) { - var convertedStatements = block.Statements.Select(s => (StatementSyntax)Visit(s)!).ToArray(); + var convertedStatements = block.Statements.Select(s => (StatementSyntax)Visit(s)!); statements = SyntaxFactory.List(convertedStatements); } else if (lambda.Body is ExpressionSyntax expr) diff --git a/TUnit.Analyzers.CodeFixers/NUnitMigrationCodeFixProvider.cs b/TUnit.Analyzers.CodeFixers/NUnitMigrationCodeFixProvider.cs index e758025391..23519686cf 100644 --- a/TUnit.Analyzers.CodeFixers/NUnitMigrationCodeFixProvider.cs +++ b/TUnit.Analyzers.CodeFixers/NUnitMigrationCodeFixProvider.cs @@ -683,7 +683,7 @@ private SyntaxNode ConvertAssertMultipleLambda(ExpressionStatementSyntax origina if (lambda.Body is BlockSyntax block) { // Visit each statement to convert inner assertions - var convertedStatements = block.Statements.Select(s => (StatementSyntax)Visit(s)!).ToArray(); + var convertedStatements = block.Statements.Select(s => (StatementSyntax)Visit(s)!); statements = SyntaxFactory.List(convertedStatements); } else if (lambda.Body is ExpressionSyntax expr) @@ -706,7 +706,7 @@ private SyntaxNode ConvertAssertMultipleSimpleLambda(ExpressionStatementSyntax o SyntaxList statements; if (lambda.Body is BlockSyntax block) { - var convertedStatements = block.Statements.Select(s => (StatementSyntax)Visit(s)!).ToArray(); + var convertedStatements = block.Statements.Select(s => (StatementSyntax)Visit(s)!); statements = SyntaxFactory.List(convertedStatements); } else if (lambda.Body is ExpressionSyntax expr) diff --git a/TUnit.Analyzers.CodeFixers/TwoPhase/XUnitTwoPhaseAnalyzer.cs b/TUnit.Analyzers.CodeFixers/TwoPhase/XUnitTwoPhaseAnalyzer.cs index 54d737a04f..f6c462c6e8 100644 --- a/TUnit.Analyzers.CodeFixers/TwoPhase/XUnitTwoPhaseAnalyzer.cs +++ b/TUnit.Analyzers.CodeFixers/TwoPhase/XUnitTwoPhaseAnalyzer.cs @@ -1117,7 +1117,7 @@ private static string GetAttributeName(AttributeSyntax attribute) protected override CompilationUnitSyntax AnalyzeBaseTypes(CompilationUnitSyntax root) { - var classNodes = OriginalRoot.DescendantNodes().OfType().ToList(); + var classNodes = OriginalRoot.DescendantNodes().OfType(); var currentRoot = root; foreach (var classNode in classNodes) @@ -1486,8 +1486,7 @@ protected override CompilationUnitSyntax AnalyzeMembers(CompilationUnitSyntax ro var members = OriginalRoot.DescendantNodes() .Where(n => (n is PropertyDeclarationSyntax prop && IsTestOutputHelperType(prop.Type)) || - (n is FieldDeclarationSyntax field && IsTestOutputHelperType(field.Declaration.Type))) - .ToList(); + (n is FieldDeclarationSyntax field && IsTestOutputHelperType(field.Declaration.Type))); foreach (var originalMember in members) { @@ -1558,8 +1557,7 @@ protected override CompilationUnitSyntax AnalyzeConstructorParameters(Compilatio // Find parameters on ORIGINAL tree (for semantic analysis) var parameters = OriginalRoot.DescendantNodes() .OfType() - .Where(p => p.Type != null && IsTestOutputHelperType(p.Type)) - .ToList(); + .Where(p => p.Type != null && IsTestOutputHelperType(p.Type)); foreach (var originalParam in parameters) { @@ -1630,8 +1628,7 @@ private CompilationUnitSyntax AnalyzeRecordExceptionCalls(CompilationUnitSyntax // Find Record.Exception calls on the ORIGINAL tree var recordExceptionCalls = OriginalRoot.DescendantNodes() .OfType() - .Where(IsRecordExceptionCall) - .ToList(); + .Where(IsRecordExceptionCall); foreach (var originalCall in recordExceptionCalls) { @@ -1742,8 +1739,7 @@ private CompilationUnitSyntax AnalyzeTestOutputHelperCalls(CompilationUnitSyntax // Find ITestOutputHelper.WriteLine calls on the ORIGINAL tree var testOutputHelperCalls = OriginalRoot.DescendantNodes() .OfType() - .Where(IsTestOutputHelperWriteLineCall) - .ToList(); + .Where(IsTestOutputHelperWriteLineCall); foreach (var originalCall in testOutputHelperCalls) { @@ -1831,8 +1827,7 @@ protected override CompilationUnitSyntax AnalyzeTheoryData(CompilationUnitSyntax // Find all TheoryData types in the original tree (field and property declarations) var theoryDataNodes = OriginalRoot.DescendantNodes() .OfType() - .Where(g => g.Identifier.Text == "TheoryData") - .ToList(); + .Where(g => g.Identifier.Text == "TheoryData"); foreach (var originalGeneric in theoryDataNodes) { diff --git a/TUnit.Analyzers/AssemblyTestHooksAnalyzer.cs b/TUnit.Analyzers/AssemblyTestHooksAnalyzer.cs index 059b3fb1a8..8d2d9b6a1a 100644 --- a/TUnit.Analyzers/AssemblyTestHooksAnalyzer.cs +++ b/TUnit.Analyzers/AssemblyTestHooksAnalyzer.cs @@ -34,8 +34,7 @@ private void AnalyzeSymbol(SymbolAnalysisContext context) var attributes = methodSymbol.GetAttributes(); var onlyOnceAttributes = attributes - .Where(x => x.IsStandardHook(context.Compilation, out _, out var level, out _) && level == HookLevel.Assembly) - .ToList(); + .Where(x => x.IsStandardHook(context.Compilation, out _, out var level, out _) && level == HookLevel.Assembly); if (!onlyOnceAttributes.Any()) { diff --git a/TUnit.Analyzers/ClassHooksAnalyzer.cs b/TUnit.Analyzers/ClassHooksAnalyzer.cs index d819592598..0ade0960ca 100644 --- a/TUnit.Analyzers/ClassHooksAnalyzer.cs +++ b/TUnit.Analyzers/ClassHooksAnalyzer.cs @@ -33,8 +33,7 @@ private void AnalyzeSymbol(SymbolAnalysisContext context) var attributes = methodSymbol.GetAttributes(); var onlyOnceAttributes = attributes - .Where(x => x.IsStandardHook(context.Compilation, out _, out var level, out _) && level == HookLevel.Class) - .ToList(); + .Where(x => x.IsStandardHook(context.Compilation, out _, out var level, out _) && level == HookLevel.Class); if (!onlyOnceAttributes.Any()) { diff --git a/TUnit.Analyzers/CombinedDataSourceAnalyzer.cs b/TUnit.Analyzers/CombinedDataSourceAnalyzer.cs index 2c50620686..c783490c4e 100644 --- a/TUnit.Analyzers/CombinedDataSourceAnalyzer.cs +++ b/TUnit.Analyzers/CombinedDataSourceAnalyzer.cs @@ -63,8 +63,7 @@ private void CheckCombinedDataSourceErrors(SymbolAnalysisContext context, x.IsCombinedDataSourceAttribute(context.Compilation)); var parametersWithDataSources = parameters - .Where(p => p.HasDataSourceAttribute(context.Compilation)) - .ToList(); + .Where(p => p.HasDataSourceAttribute(context.Compilation)); // Rule 1: If parameters have data source attributes, CombinedDataSources must be present if (parametersWithDataSources.Any() && !hasCombinedDataSource) @@ -81,8 +80,7 @@ private void CheckCombinedDataSourceErrors(SymbolAnalysisContext context, // Filter out CancellationToken parameters as they're handled by the engine var nonCancellationTokenParams = parameters .Where(p => p.Type.GloballyQualifiedNonGeneric() != - "global::System.Threading.CancellationToken") - .ToList(); + "global::System.Threading.CancellationToken"); foreach (var parameter in nonCancellationTokenParams) { diff --git a/TUnit.Analyzers/DisposableFieldPropertyAnalyzer.cs b/TUnit.Analyzers/DisposableFieldPropertyAnalyzer.cs index 6c9c75d980..d1fe1d85f6 100644 --- a/TUnit.Analyzers/DisposableFieldPropertyAnalyzer.cs +++ b/TUnit.Analyzers/DisposableFieldPropertyAnalyzer.cs @@ -163,7 +163,7 @@ private static void CheckFieldInitializers(SyntaxNodeAnalysisContext context, IN private static void CheckSetUps(SyntaxNodeAnalysisContext context, IMethodSymbol methodSymbol, ConcurrentDictionary createdObjects) { var syntaxNodes = methodSymbol.DeclaringSyntaxReferences - .SelectMany(x => x.GetSyntax().DescendantNodesAndSelf()).ToArray(); + .SelectMany(x => x.GetSyntax().DescendantNodesAndSelf()); var isHookMethod = methodSymbol.IsHookMethod(context.Compilation, out _, out var level, out _); @@ -227,7 +227,7 @@ private static void CheckSetUps(SyntaxNodeAnalysisContext context, IMethodSymbol private static void CheckTeardowns(SyntaxNodeAnalysisContext context, IMethodSymbol methodSymbol, ConcurrentDictionary createdObjects) { var syntaxNodes = methodSymbol.DeclaringSyntaxReferences - .SelectMany(x => x.GetSyntax().DescendantNodesAndSelf()).ToArray(); + .SelectMany(x => x.GetSyntax().DescendantNodesAndSelf()); foreach (var assignment in syntaxNodes .Where(x => x.IsKind(SyntaxKind.InvocationExpression))) diff --git a/TUnit.Analyzers/InstanceTestHooksAnalyzer.cs b/TUnit.Analyzers/InstanceTestHooksAnalyzer.cs index 542a081939..4fefd73291 100644 --- a/TUnit.Analyzers/InstanceTestHooksAnalyzer.cs +++ b/TUnit.Analyzers/InstanceTestHooksAnalyzer.cs @@ -27,8 +27,7 @@ private void AnalyzeSymbol(SymbolAnalysisContext context) var attributes = methodSymbol.GetAttributes(); var onlyOnceAttributes = attributes - .Where(x => x.IsStandardHook(context.Compilation, out _, out var level, out _) && level == HookLevel.Test) - .ToList(); + .Where(x => x.IsStandardHook(context.Compilation, out _, out var level, out _) && level == HookLevel.Test); if (!onlyOnceAttributes.Any()) { diff --git a/TUnit.Analyzers/SingleTUnitAttributeAnalyzer.cs b/TUnit.Analyzers/SingleTUnitAttributeAnalyzer.cs index 1de850d04b..115e26fa6d 100644 --- a/TUnit.Analyzers/SingleTUnitAttributeAnalyzer.cs +++ b/TUnit.Analyzers/SingleTUnitAttributeAnalyzer.cs @@ -23,9 +23,9 @@ private void AnalyzeSymbol(SymbolAnalysisContext context) var attributes = symbol.GetAttributes(); - var singleAttributes = attributes.Select(ToClassInheritingSingleAttribute).OfType().ToList(); + var singleAttributes = attributes.Select(ToClassInheritingSingleAttribute).OfType(); - var notDistinctAttributes = singleAttributes.GroupBy(x => x, SymbolEqualityComparer.Default).Where(x => x.Count() > 1).Select(x => x.Key!).ToList(); + var notDistinctAttributes = singleAttributes.GroupBy(x => x, SymbolEqualityComparer.Default).Where(x => x.Count() > 1).Select(x => x.Key!); foreach (var notDistinctAttribute in notDistinctAttributes) { diff --git a/TUnit.Assertions.SourceGenerator/Generators/AssertionMethodGenerator.cs b/TUnit.Assertions.SourceGenerator/Generators/AssertionMethodGenerator.cs index 406ef8fcca..05214aeda3 100644 --- a/TUnit.Assertions.SourceGenerator/Generators/AssertionMethodGenerator.cs +++ b/TUnit.Assertions.SourceGenerator/Generators/AssertionMethodGenerator.cs @@ -494,8 +494,7 @@ private static void GenerateAssertionsForSpecificClass(SourceProductionContext c .OfType() .Where(p => p.Type.SpecialType == SpecialType.System_Boolean && p is { GetMethod: not null, IsStatic: false } && - SymbolEqualityComparer.Default.Equals(p.ContainingType, attributeData.TargetType)) - .ToList(); + SymbolEqualityComparer.Default.Equals(p.ContainingType, attributeData.TargetType)); var matchingMethods = methodMembers.ToList(); diff --git a/TUnit.Core.SourceGenerator/CodeGenerationHelpers.cs b/TUnit.Core.SourceGenerator/CodeGenerationHelpers.cs index 7cb27dff05..765927575e 100644 --- a/TUnit.Core.SourceGenerator/CodeGenerationHelpers.cs +++ b/TUnit.Core.SourceGenerator/CodeGenerationHelpers.cs @@ -103,7 +103,7 @@ public static string GenerateAttributeInstantiation(AttributeData attr, Immutabl syntaxIndex++; elementIndex++; return TypedConstantParser.GetRawTypedConstantValue(v, paramType); - }).ToList(); + }); argStrings.AddRange(elements); } } @@ -287,8 +287,7 @@ public static string GenerateTestAttributes(IMethodSymbol methodSymbol) // Group attributes by type var attributesByType = allAttributes - .GroupBy(attr => attr.AttributeClass?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) ?? "System.Attribute") - .ToList(); + .GroupBy(attr => attr.AttributeClass?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) ?? "System.Attribute"); using var writer = new CodeWriter("", includeHeader: false); @@ -301,12 +300,11 @@ public static string GenerateTestAttributes(IMethodSymbol methodSymbol) foreach (var group in attributesByType) { var typeString = group.Key; - var attrs = group.ToList(); writer.Append($"[typeof({typeString})] = new global::System.Attribute[] {{ "); var attributeStrings = new List(); - foreach (var attr in attrs) + foreach (var attr in group) { attributeStrings.Add(GenerateAttributeInstantiation(attr)); } diff --git a/TUnit.Core/Extensions/ReflectionExtensions.cs b/TUnit.Core/Extensions/ReflectionExtensions.cs index 07b12e3a66..0dcc91b667 100644 --- a/TUnit.Core/Extensions/ReflectionExtensions.cs +++ b/TUnit.Core/Extensions/ReflectionExtensions.cs @@ -142,8 +142,7 @@ private static Attribute[] GetAttributesViaCustomAttributeData(ICustomAttributeP var filteredList = customAttributeDataList .Where(x => attributeType == typeof(Attribute) || (inherit ? x.AttributeType.IsAssignableTo(attributeType) - : x.AttributeType == attributeType)) - .ToList(); + : x.AttributeType == attributeType)); foreach (var attributeData in filteredList) { diff --git a/TUnit.Engine/Building/TestBuilder.cs b/TUnit.Engine/Building/TestBuilder.cs index 900537ba7b..4a470817ee 100644 --- a/TUnit.Engine/Building/TestBuilder.cs +++ b/TUnit.Engine/Building/TestBuilder.cs @@ -1193,8 +1193,7 @@ private AbstractExecutableTest CreateFailedTestForClassDataSourceCircularDepende { var instanceClassDataSources = metadata.ClassDataSources .Where(ds => ds is IAccessesInstanceData) - .Select(ds => ds.GetType().Name) - .ToList(); + .Select(ds => ds.GetType().Name); var dataSourceNames = string.Join(", ", instanceClassDataSources); var genericParams = string.Join(", ", metadata.TestClassType.GetGenericArguments().Select(t => t.Name));