From d8671561e5b780bc48df2983a05bc124cfb88d3c Mon Sep 17 00:00:00 2001 From: Justin Baur <19896123+justindbaur@users.noreply.github.com> Date: Tue, 26 Dec 2023 11:42:05 -0500 Subject: [PATCH] Formatting and Cleanup --- .editorconfig | 12 +++ perf/Comparison/Program.cs | 2 +- perf/Comparison/Simple.cs | 6 +- .../CSharpSyntaxUtilities.cs | 2 +- .../DiagnosticDescriptors.cs | 4 +- .../Emitter/CommonSyntax.cs | 2 +- .../Emitter/CreateEmitter.cs | 8 +- .../Emitter/GrandEmitter.cs | 2 +- .../Emitter/MatcherArgumentEmitter.cs | 2 +- .../Emitter/NoopArgumentEmitter.cs | 2 +- .../Emitter/PretendEmitter.cs | 2 +- .../Emitter/SetupActionEmitter.cs | 2 +- .../Emitter/SetupArgumentEmitter.cs | 2 +- .../Emitter/SetupEmitter.cs | 2 +- .../Emitter/VerifyEmitter.cs | 2 +- .../Fakes/IKnownFake.cs | 2 +- .../Fakes/ILoggerFake.cs | 2 +- .../IncrementalValuesProviderExtensions.cs | 2 +- .../InterceptsLocationInfo.cs | 2 +- .../Invocation/CreateInvocation.cs | 2 +- .../Invocation/PretendInvocation.cs | 2 +- .../Invocation/SetupInvocation.cs | 2 +- .../Invocation/VerifyInvocation.cs | 2 +- .../InvocationOperationExtensions.cs | 2 +- src/Pretender.SourceGenerator/KnownBlocks.cs | 16 +--- .../OperationExtensions.cs | 35 -------- .../Parser/CreateParser.cs | 2 +- .../Parser/KnownTypeSymbols.cs | 2 +- .../Parser/MethodStrategy.cs | 2 +- .../Parser/PretendParser.cs | 2 +- .../Parser/SetupActionParser.cs | 2 +- .../Parser/SetupParser.cs | 2 +- .../Parser/VerifyParser.cs | 2 +- .../PretenderSettings.cs | 4 +- .../PretenderSourceGenerator.cs | 2 +- .../ScaffoldTypeOptions.cs | 8 +- .../SetupArguments/LiteralArgumentEmitter.cs | 2 +- .../LocalReferenceArgumentEmitter.cs | 2 +- .../SetupArguments/SetupArgumentParser.cs | 2 +- .../SymbolExtensions.cs | 79 +------------------ .../SyntaxNodeExtensions.cs | 5 +- src/Pretender/Argument.cs | 4 +- src/Pretender/Behavior.cs | 2 +- src/Pretender/Behaviors/CallbackBehavior.cs | 2 +- .../Behaviors/ReturnValueBehavior.cs | 2 +- src/Pretender/Behaviors/ThrowBehavior.cs | 2 +- src/Pretender/CallInfo.cs | 2 +- src/Pretender/Called.cs | 4 +- src/Pretender/IPretendSetup.cs | 2 +- src/Pretender/Internals/BaseCompiledSetup.cs | 2 +- src/Pretender/Internals/Cache.cs | 2 +- src/Pretender/Internals/Matcher.cs | 2 +- .../Internals/ReturningCompiledSetup.cs | 4 +- src/Pretender/Internals/VoidCompiledSetup.cs | 2 +- src/Pretender/Matchers/AnonymousMatcher.cs | 2 +- src/Pretender/Matchers/MatcherListener.cs | 4 +- src/Pretender/Pretend.Create.cs | 2 +- src/Pretender/Pretend.cs | 2 +- src/Pretender/PretendAttribute.cs | 2 +- src/Pretender/PretendSetupExtensions.cs | 2 +- src/Pretender/PretenderSettingsAttribute.cs | 2 +- src/Pretender/Settings/PretendBehavior.cs | 2 +- .../Matchers/MatcherListenerTests.cs | 2 +- test/SourceGeneratorTests/MainTests.cs | 2 +- test/SourceGeneratorTests/TestBase.cs | 2 +- 65 files changed, 91 insertions(+), 204 deletions(-) delete mode 100644 src/Pretender.SourceGenerator/OperationExtensions.cs diff --git a/.editorconfig b/.editorconfig index 31b6b5c..cf811d3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -129,6 +129,8 @@ csharp_style_unused_value_expression_statement_preference = discard_variable:sil # 'using' directive preferences csharp_using_directive_placement = outside_namespace:silent + + #### C# Formatting Rules #### # New line preferences @@ -181,6 +183,11 @@ csharp_style_namespace_declarations = block_scoped:silent csharp_style_prefer_method_group_conversion = true:silent csharp_style_prefer_top_level_statements = true:silent csharp_style_prefer_primary_constructors = false:silent +csharp_style_prefer_null_check_over_type_check = true:suggestion +csharp_style_prefer_local_over_anonymous_function = true:suggestion +csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion +csharp_style_prefer_tuple_swap = true:suggestion +csharp_style_prefer_utf8_string_literals = true:suggestion #### Naming styles #### [*.{cs,vb}] @@ -375,3 +382,8 @@ dotnet_naming_style.s_camelcase.capitalization = camel_case tab_width = 4 indent_size = 4 end_of_line = crlf + +dotnet_style_prefer_collection_expression = true:suggestion +dotnet_style_namespace_match_folder = true:suggestion + +dotnet_diagnostic.CA1811.severity = warning diff --git a/perf/Comparison/Program.cs b/perf/Comparison/Program.cs index 6f26c2f..b617fd9 100644 --- a/perf/Comparison/Program.cs +++ b/perf/Comparison/Program.cs @@ -4,4 +4,4 @@ using Comparison; BenchmarkRunner.Run(); -// new Simple().PretenderTest(); +// new Simple().PretenderTest(); \ No newline at end of file diff --git a/perf/Comparison/Simple.cs b/perf/Comparison/Simple.cs index 8b63f9d..3ef2df4 100644 --- a/perf/Comparison/Simple.cs +++ b/perf/Comparison/Simple.cs @@ -11,8 +11,8 @@ public string MoqTest() { var mock = new Moq.Mock(); - mock.Setup(i => i.Foo(Moq.It.IsAny())) - .Returns("2"); + mock.Setup(i => i.Foo(Moq.It.IsAny())) + .Returns("2"); var simpleInterface = mock.Object; return simpleInterface.Foo("1"); @@ -46,4 +46,4 @@ public interface ISimpleInterface string Foo(string bar); } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/CSharpSyntaxUtilities.cs b/src/Pretender.SourceGenerator/CSharpSyntaxUtilities.cs index e26340f..4d4174d 100644 --- a/src/Pretender.SourceGenerator/CSharpSyntaxUtilities.cs +++ b/src/Pretender.SourceGenerator/CSharpSyntaxUtilities.cs @@ -53,4 +53,4 @@ public static string FormatLiteral(object? value, ITypeSymbol type) string FormatNumber() => $"({type.ToFullDisplayString()})({Convert.ToString(value, CultureInfo.InvariantCulture)})"; } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/DiagnosticDescriptors.cs b/src/Pretender.SourceGenerator/DiagnosticDescriptors.cs index 81a54e3..a340566 100644 --- a/src/Pretender.SourceGenerator/DiagnosticDescriptors.cs +++ b/src/Pretender.SourceGenerator/DiagnosticDescriptors.cs @@ -4,7 +4,7 @@ namespace Pretender.SourceGenerator { internal static class DiagnosticDescriptors { - public static DiagnosticDescriptor UnsupportedLanguageVersion { get; } = new ( + public static DiagnosticDescriptor UnsupportedLanguageVersion { get; } = new( "PRTND001", "Unsupported language version", "", @@ -28,4 +28,4 @@ internal static class DiagnosticDescriptors DiagnosticSeverity.Error, isEnabledByDefault: true); } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Emitter/CommonSyntax.cs b/src/Pretender.SourceGenerator/Emitter/CommonSyntax.cs index 7866131..c0f5e1b 100644 --- a/src/Pretender.SourceGenerator/Emitter/CommonSyntax.cs +++ b/src/Pretender.SourceGenerator/Emitter/CommonSyntax.cs @@ -18,4 +18,4 @@ internal static class CommonSyntax public static ParameterSyntax CalledParameter { get; } = Parameter(CalledIdentifier) .WithType(ParseTypeName("Called")); } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Emitter/CreateEmitter.cs b/src/Pretender.SourceGenerator/Emitter/CreateEmitter.cs index 23287d4..37df874 100644 --- a/src/Pretender.SourceGenerator/Emitter/CreateEmitter.cs +++ b/src/Pretender.SourceGenerator/Emitter/CreateEmitter.cs @@ -1,8 +1,8 @@ -using Microsoft.CodeAnalysis.Operations; -using System.Collections.Immutable; +using System.Collections.Immutable; using Microsoft.CodeAnalysis; -using Pretender.SourceGenerator.Writing; +using Microsoft.CodeAnalysis.Operations; using Pretender.SourceGenerator.Parser; +using Pretender.SourceGenerator.Writing; namespace Pretender.SourceGenerator.Emitter { @@ -85,4 +85,4 @@ public void Emit(IndentedTextWriter writer, CancellationToken cancellationToken) } } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Emitter/GrandEmitter.cs b/src/Pretender.SourceGenerator/Emitter/GrandEmitter.cs index aac58a4..a9c0934 100644 --- a/src/Pretender.SourceGenerator/Emitter/GrandEmitter.cs +++ b/src/Pretender.SourceGenerator/Emitter/GrandEmitter.cs @@ -108,4 +108,4 @@ public string Emit(CancellationToken cancellationToken) return writer.ToString(); } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Emitter/MatcherArgumentEmitter.cs b/src/Pretender.SourceGenerator/Emitter/MatcherArgumentEmitter.cs index 406f5f2..1b1b49a 100644 --- a/src/Pretender.SourceGenerator/Emitter/MatcherArgumentEmitter.cs +++ b/src/Pretender.SourceGenerator/Emitter/MatcherArgumentEmitter.cs @@ -79,4 +79,4 @@ public override void EmitArgumentMatcher(IndentedTextWriter writer, Cancellation } } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Emitter/NoopArgumentEmitter.cs b/src/Pretender.SourceGenerator/Emitter/NoopArgumentEmitter.cs index b7da48f..87f6af2 100644 --- a/src/Pretender.SourceGenerator/Emitter/NoopArgumentEmitter.cs +++ b/src/Pretender.SourceGenerator/Emitter/NoopArgumentEmitter.cs @@ -16,4 +16,4 @@ public override void EmitArgumentMatcher(IndentedTextWriter writer, Cancellation // Intentional no-op } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Emitter/PretendEmitter.cs b/src/Pretender.SourceGenerator/Emitter/PretendEmitter.cs index 319b39a..2624fba 100644 --- a/src/Pretender.SourceGenerator/Emitter/PretendEmitter.cs +++ b/src/Pretender.SourceGenerator/Emitter/PretendEmitter.cs @@ -182,4 +182,4 @@ int IEqualityComparer.GetHashCode(PretendEmitter obj) } } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Emitter/SetupActionEmitter.cs b/src/Pretender.SourceGenerator/Emitter/SetupActionEmitter.cs index 6f6a42c..556434e 100644 --- a/src/Pretender.SourceGenerator/Emitter/SetupActionEmitter.cs +++ b/src/Pretender.SourceGenerator/Emitter/SetupActionEmitter.cs @@ -79,4 +79,4 @@ public void Emit(IndentedTextWriter writer, CancellationToken cancellationToken) writer.WriteLine("}, setupExpression);"); } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Emitter/SetupArgumentEmitter.cs b/src/Pretender.SourceGenerator/Emitter/SetupArgumentEmitter.cs index ac3bcce..026262d 100644 --- a/src/Pretender.SourceGenerator/Emitter/SetupArgumentEmitter.cs +++ b/src/Pretender.SourceGenerator/Emitter/SetupArgumentEmitter.cs @@ -35,4 +35,4 @@ protected void EmitIfReturnFalseCheck(IndentedTextWriter writer, string left, st } } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Emitter/SetupEmitter.cs b/src/Pretender.SourceGenerator/Emitter/SetupEmitter.cs index 9b9d280..88a1897 100644 --- a/src/Pretender.SourceGenerator/Emitter/SetupEmitter.cs +++ b/src/Pretender.SourceGenerator/Emitter/SetupEmitter.cs @@ -45,4 +45,4 @@ public void Emit(IndentedTextWriter writer, int index, CancellationToken cancell } } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Emitter/VerifyEmitter.cs b/src/Pretender.SourceGenerator/Emitter/VerifyEmitter.cs index 446fc18..7c5fb5f 100644 --- a/src/Pretender.SourceGenerator/Emitter/VerifyEmitter.cs +++ b/src/Pretender.SourceGenerator/Emitter/VerifyEmitter.cs @@ -40,4 +40,4 @@ public void Emit(IndentedTextWriter writer, int index, CancellationToken cancell } } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Fakes/IKnownFake.cs b/src/Pretender.SourceGenerator/Fakes/IKnownFake.cs index ea15cbb..e9860dc 100644 --- a/src/Pretender.SourceGenerator/Fakes/IKnownFake.cs +++ b/src/Pretender.SourceGenerator/Fakes/IKnownFake.cs @@ -7,4 +7,4 @@ internal interface IKnownFake { bool TryConstruct(INamedTypeSymbol typeSymbol, KnownTypeSymbols knownTypeSymbols, CancellationToken cancellationToken, out INamedTypeSymbol? fakeType); } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Fakes/ILoggerFake.cs b/src/Pretender.SourceGenerator/Fakes/ILoggerFake.cs index e16bff6..117f302 100644 --- a/src/Pretender.SourceGenerator/Fakes/ILoggerFake.cs +++ b/src/Pretender.SourceGenerator/Fakes/ILoggerFake.cs @@ -16,4 +16,4 @@ public bool TryConstruct(INamedTypeSymbol typeSymbol, KnownTypeSymbols knownType return false; } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/IncrementalValuesProviderExtensions.cs b/src/Pretender.SourceGenerator/IncrementalValuesProviderExtensions.cs index 041c46a..8237725 100644 --- a/src/Pretender.SourceGenerator/IncrementalValuesProviderExtensions.cs +++ b/src/Pretender.SourceGenerator/IncrementalValuesProviderExtensions.cs @@ -34,4 +34,4 @@ internal static class IncrementalValuesProviderExtensions }); } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/InterceptsLocationInfo.cs b/src/Pretender.SourceGenerator/InterceptsLocationInfo.cs index 48e342c..637a845 100644 --- a/src/Pretender.SourceGenerator/InterceptsLocationInfo.cs +++ b/src/Pretender.SourceGenerator/InterceptsLocationInfo.cs @@ -45,4 +45,4 @@ public AttributeSyntax ToAttributeSyntax() }))); } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Invocation/CreateInvocation.cs b/src/Pretender.SourceGenerator/Invocation/CreateInvocation.cs index b295c09..d48c66e 100644 --- a/src/Pretender.SourceGenerator/Invocation/CreateInvocation.cs +++ b/src/Pretender.SourceGenerator/Invocation/CreateInvocation.cs @@ -128,4 +128,4 @@ int IEqualityComparer.GetHashCode(CreateInvocation obj) } } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Invocation/PretendInvocation.cs b/src/Pretender.SourceGenerator/Invocation/PretendInvocation.cs index 856b408..a45c067 100644 --- a/src/Pretender.SourceGenerator/Invocation/PretendInvocation.cs +++ b/src/Pretender.SourceGenerator/Invocation/PretendInvocation.cs @@ -81,4 +81,4 @@ public static bool IsCandidateSyntaxNode(SyntaxNode node) return new PretendInvocation(typeSymbol, location, fillExisting); } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Invocation/SetupInvocation.cs b/src/Pretender.SourceGenerator/Invocation/SetupInvocation.cs index bfc8d81..4eb48e7 100644 --- a/src/Pretender.SourceGenerator/Invocation/SetupInvocation.cs +++ b/src/Pretender.SourceGenerator/Invocation/SetupInvocation.cs @@ -54,4 +54,4 @@ private static bool IsSetupOperation(IInvocationOperation operation) return true; } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Invocation/VerifyInvocation.cs b/src/Pretender.SourceGenerator/Invocation/VerifyInvocation.cs index 70cdf14..e112192 100644 --- a/src/Pretender.SourceGenerator/Invocation/VerifyInvocation.cs +++ b/src/Pretender.SourceGenerator/Invocation/VerifyInvocation.cs @@ -60,4 +60,4 @@ private static bool IsVerifyOperation(IInvocationOperation operation) return true; } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/InvocationOperationExtensions.cs b/src/Pretender.SourceGenerator/InvocationOperationExtensions.cs index 3dd2163..e8139ad 100644 --- a/src/Pretender.SourceGenerator/InvocationOperationExtensions.cs +++ b/src/Pretender.SourceGenerator/InvocationOperationExtensions.cs @@ -45,4 +45,4 @@ public static bool IsValidCreateOperation(this IOperation? operation, Compilatio return false; } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/KnownBlocks.cs b/src/Pretender.SourceGenerator/KnownBlocks.cs index 6911176..46ab6ec 100644 --- a/src/Pretender.SourceGenerator/KnownBlocks.cs +++ b/src/Pretender.SourceGenerator/KnownBlocks.cs @@ -26,18 +26,6 @@ public InterceptsLocationAttribute(string filePath, int line, int column) } """; - public static NamespaceDeclarationSyntax OurNamespace { get; } - = NamespaceDeclaration(IdentifierName("Pretender.SourceGeneration")); - - public static UsingDirectiveSyntax PretenderUsing { get; } - = UsingDirective(ParseName("Pretender")); - - public static UsingDirectiveSyntax PretenderInternalsUsing { get; } - = UsingDirective(ParseName("Pretender.Internals")); - - public static UsingDirectiveSyntax CompilerServicesUsing { get; } - = UsingDirective(ParseName("System.Runtime.CompilerServices")); - public static MemberAccessExpressionSyntax TaskCompletedTask = MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, IdentifierName("Task"), @@ -67,9 +55,9 @@ public static InvocationExpressionSyntax ValueTaskFromResult(TypeSyntax resultTy .AddTypeArgumentListArguments(resultType)); // ValueTask.FromResult(value) - return InvocationExpression(memberAccess, + return InvocationExpression(memberAccess, ArgumentList( SingletonSeparatedList(Argument(resultValue)))); } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/OperationExtensions.cs b/src/Pretender.SourceGenerator/OperationExtensions.cs deleted file mode 100644 index 345818c..0000000 --- a/src/Pretender.SourceGenerator/OperationExtensions.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Operations; - -using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; - -namespace Pretender.SourceGenerator -{ - internal static class OperationExtensions - { - // TODO: Take KnownTypeSymbols - public static LiteralExpressionSyntax ToLiteralExpression(this ILiteralOperation operation) - { - if (operation.Type is null || !operation.ConstantValue.HasValue) - { - return LiteralExpression(SyntaxKind.NullLiteralExpression); - } - else if (operation.Type.EqualsByName(["System", "String"])) - { - return LiteralExpression(SyntaxKind.StringLiteralExpression, Literal((string)operation.ConstantValue.Value!)); - } - else if (operation.Type.EqualsByName(["System", "Int32"])) - { - return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)operation.ConstantValue.Value!)); - } - else if (operation.Type.EqualsByName(["System", "Boolean"])) - { - var value = (bool)operation.ConstantValue.Value!; - return LiteralExpression(value ? SyntaxKind.TrueLiteralExpression : SyntaxKind.FalseLiteralExpression); - } - - throw new NotImplementedException($"We don't support literals of {operation.Type.Name} yet."); - } - } -} diff --git a/src/Pretender.SourceGenerator/Parser/CreateParser.cs b/src/Pretender.SourceGenerator/Parser/CreateParser.cs index f8df8a9..540be42 100644 --- a/src/Pretender.SourceGenerator/Parser/CreateParser.cs +++ b/src/Pretender.SourceGenerator/Parser/CreateParser.cs @@ -35,4 +35,4 @@ public CreateParser(CreateInvocation createInvocation, ImmutableArray Arguments { get; } } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Parser/SetupParser.cs b/src/Pretender.SourceGenerator/Parser/SetupParser.cs index b2d3f37..4955380 100644 --- a/src/Pretender.SourceGenerator/Parser/SetupParser.cs +++ b/src/Pretender.SourceGenerator/Parser/SetupParser.cs @@ -46,4 +46,4 @@ public SetupParser(SetupInvocation setupInvocation, KnownTypeSymbols knownTypeSy return (new SetupEmitter(setupActionEmitter, operation), setupActionDiagnostics); } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/Parser/VerifyParser.cs b/src/Pretender.SourceGenerator/Parser/VerifyParser.cs index b0e6fac..5e6b0b8 100644 --- a/src/Pretender.SourceGenerator/Parser/VerifyParser.cs +++ b/src/Pretender.SourceGenerator/Parser/VerifyParser.cs @@ -56,4 +56,4 @@ public VerifyParser(VerifyInvocation verifyInvocation, KnownTypeSymbols knownTyp return (emitter, setupActionDiagnostics); } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/PretenderSettings.cs b/src/Pretender.SourceGenerator/PretenderSettings.cs index 49fedf8..fa96c71 100644 --- a/src/Pretender.SourceGenerator/PretenderSettings.cs +++ b/src/Pretender.SourceGenerator/PretenderSettings.cs @@ -36,6 +36,6 @@ public PretenderSettings(PretendBehavior behavior) Behavior = behavior; } - public PretendBehavior Behavior { get; } + public PretendBehavior Behavior { get; } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/PretenderSourceGenerator.cs b/src/Pretender.SourceGenerator/PretenderSourceGenerator.cs index 0349e62..4f93e47 100644 --- a/src/Pretender.SourceGenerator/PretenderSourceGenerator.cs +++ b/src/Pretender.SourceGenerator/PretenderSourceGenerator.cs @@ -139,4 +139,4 @@ private static IncrementalValuesProvider ReportDiagnostics(IncrementalGene .Where(e => e != null)!; } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/ScaffoldTypeOptions.cs b/src/Pretender.SourceGenerator/ScaffoldTypeOptions.cs index 4c74660..929c4bf 100644 --- a/src/Pretender.SourceGenerator/ScaffoldTypeOptions.cs +++ b/src/Pretender.SourceGenerator/ScaffoldTypeOptions.cs @@ -1,7 +1,7 @@ -using Microsoft.CodeAnalysis.CSharp.Syntax; +using System.Collections.Immutable; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -using System.Collections.Immutable; namespace Pretender.SourceGenerator; @@ -11,5 +11,5 @@ public class ScaffoldTypeOptions public Func AddMethodBody { get; set; } = (_) => Block(); // TODO: Is there a better symbol for constructors, methods? - public Func<(ParameterSyntax FirstParameter, StatementSyntax[] AdditionalBodyStatements)>? CustomizeConstructor { get; set; } -} + public Func<(ParameterSyntax FirstParameter, StatementSyntax[] AdditionalBodyStatements)>? CustomizeConstructor { get; set; } +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/SetupArguments/LiteralArgumentEmitter.cs b/src/Pretender.SourceGenerator/SetupArguments/LiteralArgumentEmitter.cs index 1c0958d..7bfb379 100644 --- a/src/Pretender.SourceGenerator/SetupArguments/LiteralArgumentEmitter.cs +++ b/src/Pretender.SourceGenerator/SetupArguments/LiteralArgumentEmitter.cs @@ -29,4 +29,4 @@ public override int GetHashCode() : 1337; // TODO: Magic value? } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/SetupArguments/LocalReferenceArgumentEmitter.cs b/src/Pretender.SourceGenerator/SetupArguments/LocalReferenceArgumentEmitter.cs index 8a146c0..d451010 100644 --- a/src/Pretender.SourceGenerator/SetupArguments/LocalReferenceArgumentEmitter.cs +++ b/src/Pretender.SourceGenerator/SetupArguments/LocalReferenceArgumentEmitter.cs @@ -27,4 +27,4 @@ public override int GetHashCode() return SymbolEqualityComparer.Default.GetHashCode(_localReferenceOperation.Local); } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/SetupArguments/SetupArgumentParser.cs b/src/Pretender.SourceGenerator/SetupArguments/SetupArgumentParser.cs index 68a5dc9..eb820af 100644 --- a/src/Pretender.SourceGenerator/SetupArguments/SetupArgumentParser.cs +++ b/src/Pretender.SourceGenerator/SetupArguments/SetupArgumentParser.cs @@ -275,4 +275,4 @@ public void ExitScope() } } } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/SymbolExtensions.cs b/src/Pretender.SourceGenerator/SymbolExtensions.cs index 7e77da6..8d8427a 100644 --- a/src/Pretender.SourceGenerator/SymbolExtensions.cs +++ b/src/Pretender.SourceGenerator/SymbolExtensions.cs @@ -41,17 +41,6 @@ public static bool EqualsByName(this ITypeSymbol type, string[] name) return true; } - public static TypeSyntax AsUnknownTypeSyntax(this ITypeSymbol type) - { - var typeSyntax = ParseTypeName(type.ToFullDisplayString()); - if (type.NullableAnnotation == NullableAnnotation.Annotated) - { - return NullableType(typeSyntax, Token(SyntaxKind.QuestionToken)); - } - - return typeSyntax; - } - public static string ToUnknownTypeString(this ITypeSymbol type) { return type.NullableAnnotation == NullableAnnotation.Annotated @@ -59,72 +48,6 @@ public static string ToUnknownTypeString(this ITypeSymbol type) : type.ToFullDisplayString(); } - public static ExpressionSyntax ToDefaultValueSyntax(this INamedTypeSymbol type, KnownTypeSymbols knownTypeSymbols) - { - // They have explicitly annotated this type as nullable, so return null - if (type.NullableAnnotation == NullableAnnotation.Annotated) - { - return LiteralExpression(SyntaxKind.DefaultLiteralExpression); - } - - var nullableEnabled = type.NullableAnnotation != NullableAnnotation.None; - - var comparer = SymbolEqualityComparer.Default; - - if (type.IsUnboundGenericType) - { - throw new NotImplementedException("We believe this should have been impossible, please report this issue with a minimally reproducible sample."); - } - - if (type.IsGenericType) - { - var unboundType = type.ConstructUnboundGenericType(); - - if (comparer.Equals(unboundType, knownTypeSymbols.TaskOfT_Unbound)) - { - // Create Task.FromResult(); - // TODO: Is this ever an unsafe cast? How could you have Task? - var resultType = (INamedTypeSymbol)type.TypeArguments[0]; - - // Recursion? Issue? - return KnownBlocks.TaskFromResult(resultType.AsUnknownTypeSyntax(), resultType.ToDefaultValueSyntax(knownTypeSymbols)); - } - - if (comparer.Equals(unboundType, knownTypeSymbols.ValueTaskOfT_Unbound)) - { - var resultType = (INamedTypeSymbol)type.TypeArguments[0]; - - // Recursion! - return KnownBlocks.ValueTaskFromResult(resultType.AsUnknownTypeSyntax(), resultType.ToDefaultValueSyntax(knownTypeSymbols)); - } - - // TODO: Support IEnumerable, Lists, Arrays, and others - } - - if (comparer.Equals(type, knownTypeSymbols.Task)) - { - return KnownBlocks.TaskCompletedTask; - } - - if (comparer.Equals(type, knownTypeSymbols.ValueTask)) - { - return KnownBlocks.ValueTaskCompletedTask; - } - - if (comparer.Equals(type, knownTypeSymbols.String)) - { - // They have requested not-null so special case non-null string to be string.Empty - // people may not like this. - return MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - PredefinedType(Token(SyntaxKind.StringKeyword)), - IdentifierName("Empty")); - } - - // No better default found, just use 'default' even though it might not be in line with nullability annotations - return LiteralExpression(SyntaxKind.DefaultLiteralExpression); - } - public static string ToFullDisplayString(this ITypeSymbol type) { return type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); @@ -383,4 +306,4 @@ public static ImmutableArray GetApplicableMethods(this INamedType // return false; //} } -} +} \ No newline at end of file diff --git a/src/Pretender.SourceGenerator/SyntaxNodeExtensions.cs b/src/Pretender.SourceGenerator/SyntaxNodeExtensions.cs index 388a86d..67d5285 100644 --- a/src/Pretender.SourceGenerator/SyntaxNodeExtensions.cs +++ b/src/Pretender.SourceGenerator/SyntaxNodeExtensions.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; using System.Text; -using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; - using Microsoft.CodeAnalysis; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; namespace Pretender.SourceGenerator { @@ -15,4 +14,4 @@ public static TSyntax WithInheritDoc(this TSyntax node) return node.WithLeadingTrivia(TriviaList(Comment("/// "))); } } -} +} \ No newline at end of file diff --git a/src/Pretender/Argument.cs b/src/Pretender/Argument.cs index 5d2887f..ace26e2 100644 --- a/src/Pretender/Argument.cs +++ b/src/Pretender/Argument.cs @@ -21,8 +21,8 @@ public Argument(Type declaredType, object? value) public object? Value { readonly get { return _value; } - set { _value = value; } + set { _value = value; } } public readonly Type ActualType => _value != null ? _value.GetType() : _declaredType; } -} +} \ No newline at end of file diff --git a/src/Pretender/Behavior.cs b/src/Pretender/Behavior.cs index 43d095d..9692efa 100644 --- a/src/Pretender/Behavior.cs +++ b/src/Pretender/Behavior.cs @@ -4,4 +4,4 @@ public abstract class Behavior { public abstract void Execute(CallInfo callInfo); } -} +} \ No newline at end of file diff --git a/src/Pretender/Behaviors/CallbackBehavior.cs b/src/Pretender/Behaviors/CallbackBehavior.cs index 4da4f4e..f2dc36d 100644 --- a/src/Pretender/Behaviors/CallbackBehavior.cs +++ b/src/Pretender/Behaviors/CallbackBehavior.cs @@ -14,4 +14,4 @@ public override void Execute(CallInfo callInfo) _action(callInfo); } } -} +} \ No newline at end of file diff --git a/src/Pretender/Behaviors/ReturnValueBehavior.cs b/src/Pretender/Behaviors/ReturnValueBehavior.cs index 1c58ee9..5fa93b9 100644 --- a/src/Pretender/Behaviors/ReturnValueBehavior.cs +++ b/src/Pretender/Behaviors/ReturnValueBehavior.cs @@ -13,4 +13,4 @@ public override void Execute(CallInfo callInfo) callInfo.ReturnValue = _value; } } -} +} \ No newline at end of file diff --git a/src/Pretender/Behaviors/ThrowBehavior.cs b/src/Pretender/Behaviors/ThrowBehavior.cs index d656e50..60ae2ca 100644 --- a/src/Pretender/Behaviors/ThrowBehavior.cs +++ b/src/Pretender/Behaviors/ThrowBehavior.cs @@ -14,4 +14,4 @@ public override void Execute(CallInfo callInfo) throw _exception; } } -} +} \ No newline at end of file diff --git a/src/Pretender/CallInfo.cs b/src/Pretender/CallInfo.cs index d74eb4b..f6a9eb9 100644 --- a/src/Pretender/CallInfo.cs +++ b/src/Pretender/CallInfo.cs @@ -14,4 +14,4 @@ public CallInfo(MethodInfo methodInfo, object?[] arguments) public object?[] Arguments { get; } public object? ReturnValue { get; set; } } -} +} \ No newline at end of file diff --git a/src/Pretender/Called.cs b/src/Pretender/Called.cs index 35dc57a..6ca70a0 100644 --- a/src/Pretender/Called.cs +++ b/src/Pretender/Called.cs @@ -48,7 +48,7 @@ public static Called Range(Range range) public void Validate(int callCount) { switch (_calledKind) - { + { case CalledKind.Exact: if (callCount != _from) { @@ -78,4 +78,4 @@ public override string ToString() return $"From = {_from}, To = {_to}, Kind = {_calledKind}"; } } -} +} \ No newline at end of file diff --git a/src/Pretender/IPretendSetup.cs b/src/Pretender/IPretendSetup.cs index 4223b20..555b68b 100644 --- a/src/Pretender/IPretendSetup.cs +++ b/src/Pretender/IPretendSetup.cs @@ -21,4 +21,4 @@ public interface IPretendSetup : IPretendSetup { Type ReturnType => typeof(TResult); } -} +} \ No newline at end of file diff --git a/src/Pretender/Internals/BaseCompiledSetup.cs b/src/Pretender/Internals/BaseCompiledSetup.cs index 7d0c1c4..34daae4 100644 --- a/src/Pretender/Internals/BaseCompiledSetup.cs +++ b/src/Pretender/Internals/BaseCompiledSetup.cs @@ -54,4 +54,4 @@ public bool Matches(CallInfo callInfo) return true; } } -} +} \ No newline at end of file diff --git a/src/Pretender/Internals/Cache.cs b/src/Pretender/Internals/Cache.cs index af9e148..01adb82 100644 --- a/src/Pretender/Internals/Cache.cs +++ b/src/Pretender/Internals/Cache.cs @@ -13,4 +13,4 @@ public static class Cache return true; }; } -} +} \ No newline at end of file diff --git a/src/Pretender/Internals/Matcher.cs b/src/Pretender/Internals/Matcher.cs index 2ad9103..1c4cbbb 100644 --- a/src/Pretender/Internals/Matcher.cs +++ b/src/Pretender/Internals/Matcher.cs @@ -2,4 +2,4 @@ { // TODO: Can I make this a delegate of the unsafe wrapper around this? public delegate bool Matcher(CallInfo callInfo, object? target); -} +} \ No newline at end of file diff --git a/src/Pretender/Internals/ReturningCompiledSetup.cs b/src/Pretender/Internals/ReturningCompiledSetup.cs index ff71c32..3056bd7 100644 --- a/src/Pretender/Internals/ReturningCompiledSetup.cs +++ b/src/Pretender/Internals/ReturningCompiledSetup.cs @@ -4,7 +4,7 @@ namespace Pretender.Internals { - + [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is only meant to be used by source generators")] @@ -33,4 +33,4 @@ public void Execute(CallInfo callInfo) callInfo.ReturnValue ??= _defaultValue; } } -} +} \ No newline at end of file diff --git a/src/Pretender/Internals/VoidCompiledSetup.cs b/src/Pretender/Internals/VoidCompiledSetup.cs index fa974cf..af2723e 100644 --- a/src/Pretender/Internals/VoidCompiledSetup.cs +++ b/src/Pretender/Internals/VoidCompiledSetup.cs @@ -24,4 +24,4 @@ public void Execute(CallInfo callInfo) _behavior.Execute(callInfo); } } -} +} \ No newline at end of file diff --git a/src/Pretender/Matchers/AnonymousMatcher.cs b/src/Pretender/Matchers/AnonymousMatcher.cs index ee17898..e18a2c0 100644 --- a/src/Pretender/Matchers/AnonymousMatcher.cs +++ b/src/Pretender/Matchers/AnonymousMatcher.cs @@ -14,4 +14,4 @@ public bool Matches(T? argument) return _matcher(argument); } } -} +} \ No newline at end of file diff --git a/src/Pretender/Matchers/MatcherListener.cs b/src/Pretender/Matchers/MatcherListener.cs index df18184..1f96137 100644 --- a/src/Pretender/Matchers/MatcherListener.cs +++ b/src/Pretender/Matchers/MatcherListener.cs @@ -26,7 +26,7 @@ public static bool IsListening([MaybeNullWhen(false)] out MatcherListener listen { var listeners = s_listeners; - if (listeners != null && listeners.Count > 0) + if (listeners != null && listeners.Count > 0) { listener = listeners.Peek(); return true; @@ -65,4 +65,4 @@ public void Dispose() listeners.Pop(); } } -} +} \ No newline at end of file diff --git a/src/Pretender/Pretend.Create.cs b/src/Pretender/Pretend.Create.cs index 8050179..4919448 100644 --- a/src/Pretender/Pretend.Create.cs +++ b/src/Pretender/Pretend.Create.cs @@ -40,4 +40,4 @@ public T Create(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 a // TODO: Support overloads up to 16 // TODO: Support params object[] args after that, maybe when params Span comes around? } -} +} \ No newline at end of file diff --git a/src/Pretender/Pretend.cs b/src/Pretender/Pretend.cs index 7913449..08109ac 100644 --- a/src/Pretender/Pretend.cs +++ b/src/Pretender/Pretend.cs @@ -119,4 +119,4 @@ public static Pretend That() // var pretend = new Pretend(); // return pretend.Create(); //} -} +} \ No newline at end of file diff --git a/src/Pretender/PretendAttribute.cs b/src/Pretender/PretendAttribute.cs index 5be7fdc..59ff005 100644 --- a/src/Pretender/PretendAttribute.cs +++ b/src/Pretender/PretendAttribute.cs @@ -11,4 +11,4 @@ public class PretendAttribute : Attribute // TODO: Use this as a marker for instead of creating our own class // do it as a partial to this type } -} +} \ No newline at end of file diff --git a/src/Pretender/PretendSetupExtensions.cs b/src/Pretender/PretendSetupExtensions.cs index 54f51c4..f5f2b84 100644 --- a/src/Pretender/PretendSetupExtensions.cs +++ b/src/Pretender/PretendSetupExtensions.cs @@ -41,4 +41,4 @@ public static Pretend Does(this IPretendSetup pretendSetup, Action< return pretendSetup.Pretend; } } -} +} \ No newline at end of file diff --git a/src/Pretender/PretenderSettingsAttribute.cs b/src/Pretender/PretenderSettingsAttribute.cs index 7c1cd07..5f4b3a5 100644 --- a/src/Pretender/PretenderSettingsAttribute.cs +++ b/src/Pretender/PretenderSettingsAttribute.cs @@ -8,4 +8,4 @@ public class PretenderSettingsAttribute : Attribute { public PretendBehavior Behavior { get; set; } } -} +} \ No newline at end of file diff --git a/src/Pretender/Settings/PretendBehavior.cs b/src/Pretender/Settings/PretendBehavior.cs index 3884da0..fef1178 100644 --- a/src/Pretender/Settings/PretendBehavior.cs +++ b/src/Pretender/Settings/PretendBehavior.cs @@ -5,4 +5,4 @@ public enum PretendBehavior PreferFakes, AlwaysPretend, } -} +} \ No newline at end of file diff --git a/test/Pretender.Tests/Matchers/MatcherListenerTests.cs b/test/Pretender.Tests/Matchers/MatcherListenerTests.cs index edf7687..64780b6 100644 --- a/test/Pretender.Tests/Matchers/MatcherListenerTests.cs +++ b/test/Pretender.Tests/Matchers/MatcherListenerTests.cs @@ -19,4 +19,4 @@ public void IsListening_ReturnsFalse_WhenNotStarted() Assert.Null(listener); } } -} +} \ No newline at end of file diff --git a/test/SourceGeneratorTests/MainTests.cs b/test/SourceGeneratorTests/MainTests.cs index 1ce47f6..4c05ff2 100644 --- a/test/SourceGeneratorTests/MainTests.cs +++ b/test/SourceGeneratorTests/MainTests.cs @@ -103,4 +103,4 @@ public async Task Test3() var source = Assert.Single(result.GeneratedSources); var text = source.SourceText.ToString(); } -} +} \ No newline at end of file diff --git a/test/SourceGeneratorTests/TestBase.cs b/test/SourceGeneratorTests/TestBase.cs index 5108881..f4acd1e 100644 --- a/test/SourceGeneratorTests/TestBase.cs +++ b/test/SourceGeneratorTests/TestBase.cs @@ -191,4 +191,4 @@ private static Project CreateProject() return project; } } -} +} \ No newline at end of file