Skip to content

Commit

Permalink
Formatting and Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
justindbaur committed Dec 26, 2023
1 parent 347dd0c commit d867156
Show file tree
Hide file tree
Showing 65 changed files with 91 additions and 204 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}]
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion perf/Comparison/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
using Comparison;

BenchmarkRunner.Run<Simple>();
// new Simple().PretenderTest();
// new Simple().PretenderTest();
6 changes: 3 additions & 3 deletions perf/Comparison/Simple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public string MoqTest()
{
var mock = new Moq.Mock<ISimpleInterface>();

mock.Setup(i => i.Foo(Moq.It.IsAny<string>()))
.Returns("2");
mock.Setup(i => i.Foo(Moq.It.IsAny<string>()))
.Returns("2");

var simpleInterface = mock.Object;
return simpleInterface.Foo("1");
Expand Down Expand Up @@ -46,4 +46,4 @@ public interface ISimpleInterface
string Foo(string bar);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/CSharpSyntaxUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ public static string FormatLiteral(object? value, ITypeSymbol type)
string FormatNumber() => $"({type.ToFullDisplayString()})({Convert.ToString(value, CultureInfo.InvariantCulture)})";
}
}
}
}
4 changes: 2 additions & 2 deletions src/Pretender.SourceGenerator/DiagnosticDescriptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"",
Expand All @@ -28,4 +28,4 @@ internal static class DiagnosticDescriptors
DiagnosticSeverity.Error,
isEnabledByDefault: true);
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/Emitter/CommonSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ internal static class CommonSyntax
public static ParameterSyntax CalledParameter { get; } = Parameter(CalledIdentifier)
.WithType(ParseTypeName("Called"));
}
}
}
8 changes: 4 additions & 4 deletions src/Pretender.SourceGenerator/Emitter/CreateEmitter.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -85,4 +85,4 @@ public void Emit(IndentedTextWriter writer, CancellationToken cancellationToken)
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/Emitter/GrandEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ public string Emit(CancellationToken cancellationToken)
return writer.ToString();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ public override void EmitArgumentMatcher(IndentedTextWriter writer, Cancellation
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public override void EmitArgumentMatcher(IndentedTextWriter writer, Cancellation
// Intentional no-op
}
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/Emitter/PretendEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,4 @@ int IEqualityComparer<PretendEmitter>.GetHashCode(PretendEmitter obj)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ public void Emit(IndentedTextWriter writer, CancellationToken cancellationToken)
writer.WriteLine("}, setupExpression);");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ protected void EmitIfReturnFalseCheck(IndentedTextWriter writer, string left, st
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/Emitter/SetupEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ public void Emit(IndentedTextWriter writer, int index, CancellationToken cancell
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/Emitter/VerifyEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ public void Emit(IndentedTextWriter writer, int index, CancellationToken cancell
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/Fakes/IKnownFake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ internal interface IKnownFake
{
bool TryConstruct(INamedTypeSymbol typeSymbol, KnownTypeSymbols knownTypeSymbols, CancellationToken cancellationToken, out INamedTypeSymbol? fakeType);
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/Fakes/ILoggerFake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public bool TryConstruct(INamedTypeSymbol typeSymbol, KnownTypeSymbols knownType
return false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ internal static class IncrementalValuesProviderExtensions
});
}
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/InterceptsLocationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ public AttributeSyntax ToAttributeSyntax()
})));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ int IEqualityComparer<CreateInvocation>.GetHashCode(CreateInvocation obj)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ public static bool IsCandidateSyntaxNode(SyntaxNode node)
return new PretendInvocation(typeSymbol, location, fillExisting);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ private static bool IsSetupOperation(IInvocationOperation operation)
return true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ private static bool IsVerifyOperation(IInvocationOperation operation)
return true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ public static bool IsValidCreateOperation(this IOperation? operation, Compilatio
return false;
}
}
}
}
16 changes: 2 additions & 14 deletions src/Pretender.SourceGenerator/KnownBlocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -67,9 +55,9 @@ public static InvocationExpressionSyntax ValueTaskFromResult(TypeSyntax resultTy
.AddTypeArgumentListArguments(resultType));

// ValueTask.FromResult<T>(value)
return InvocationExpression(memberAccess,
return InvocationExpression(memberAccess,
ArgumentList(
SingletonSeparatedList(Argument(resultValue))));
}
}
}
}
35 changes: 0 additions & 35 deletions src/Pretender.SourceGenerator/OperationExtensions.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/Parser/CreateParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ public CreateParser(CreateInvocation createInvocation, ImmutableArray<Intercepts
return (emitter, null);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/Parser/KnownTypeSymbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ public string GetPretendName(INamedTypeSymbol type)
return firstName;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/Parser/MethodStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ public override void EmitMethodGetter(IndentedTextWriter writer, CancellationTok
throw new NotImplementedException();
}
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/Parser/PretendParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ public PretendParser(PretendInvocation pretendInvocation, KnownTypeSymbols known
return (new PretendEmitter(PretendInvocation.PretendType, _knownTypeSymbols, PretendInvocation.FillExisting), null);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/Parser/SetupActionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@ public InvocationCandidate(IMethodSymbol methodSymbol, ImmutableArray<IArgumentO
public ImmutableArray<IArgumentOperation> Arguments { get; }
}
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/Parser/SetupParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ public SetupParser(SetupInvocation setupInvocation, KnownTypeSymbols knownTypeSy
return (new SetupEmitter(setupActionEmitter, operation), setupActionDiagnostics);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/Parser/VerifyParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ public VerifyParser(VerifyInvocation verifyInvocation, KnownTypeSymbols knownTyp
return (emitter, setupActionDiagnostics);
}
}
}
}
4 changes: 2 additions & 2 deletions src/Pretender.SourceGenerator/PretenderSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public PretenderSettings(PretendBehavior behavior)
Behavior = behavior;
}

public PretendBehavior Behavior { get; }
public PretendBehavior Behavior { get; }
}
}
}
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/PretenderSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ private static IncrementalValuesProvider<T> ReportDiagnostics<T>(IncrementalGene
.Where(e => e != null)!;
}
}
}
}
8 changes: 4 additions & 4 deletions src/Pretender.SourceGenerator/ScaffoldTypeOptions.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -11,5 +11,5 @@ public class ScaffoldTypeOptions
public Func<IMethodSymbol, BlockSyntax> 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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ public override int GetHashCode()
: 1337; // TODO: Magic value?
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public override int GetHashCode()
return SymbolEqualityComparer.Default.GetHashCode(_localReferenceOperation.Local);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,4 @@ public void ExitScope()
}
}
}
}
}
Loading

0 comments on commit d867156

Please sign in to comment.