From aa9274e95eed2106b8e7043d6ca094851a30f676 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Thu, 22 Jun 2023 05:17:56 +0000 Subject: [PATCH] style: format code with dotnet-format Format code with dotnet-format This commit fixes the style issues introduced in b6daac9 according to the output from dotnet-format. Details: https://app.deepsource.com/gh/dgmjr-io/InterfaceGenerator/transform/2c09a44f-de20-49b0-931e-28a2f778af49/ --- Decomposer/src/DecomposerConstants.cs | 128 ++++++----- .../InterfaceGeneratorConstants.cs | 204 +++++++++--------- 2 files changed, 179 insertions(+), 153 deletions(-) diff --git a/Decomposer/src/DecomposerConstants.cs b/Decomposer/src/DecomposerConstants.cs index 17b19e0..3a94ffc 100644 --- a/Decomposer/src/DecomposerConstants.cs +++ b/Decomposer/src/DecomposerConstants.cs @@ -58,56 +58,78 @@ internal static class Constants DecomposedInterfaceHeader + GeneratedCodeAttribue + $$$""" - public interface I{{ decomposed_from }}{{ memeber_name }} - { - """; + public interface I {{ decomposed_from } + }{{ memeber_name +}} + { + """; public const string DecomposedPropertyDeclaration = GeneratedCodeAttribue + """ - {{ property_type }} {{ property_name }} { {{ if is_gettable }} get; {{ end }} {{ if is_settable }} set; {{ end }} } - """; + { { property_type } } +{ { property_name } } +{ { { if is_gettable } } get; { { end } } { { if is_settable } } set; { { end } } } +"""; public const string DecomposedMethodDeclaration = GeneratedCodeAttribue + """ - {{ return_type }} {{ method_name }} ({{ for parameter in parameters }}{{ parameter.type }} {{ parameter.name }}{{ if not loop.last }}, {{ endif }}{{ endfor }}) - {{ if has_generic_type_constraints }} - {{ for generic_type_constraint in generic_type_constraints }} where {{ generic_type_constraint.name }} : {{ type_constraint.constraint }} - {{ endfor }} - {{ endif }} - """; - - public const string DecomposableAttributeFilename = "DecomposableAttribute.g.cs"; - - public const string DecomposableAttributeDeclaration = - DecomposedInterfaceHeader - + """ - [global::System.AttributeUsage(global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Assembly)] - public sealed class DecomposeAttribute : global::System.Attribute - { - public DecomposeAttribute(string @namespace = null) { } - public DecomposeAttribute(global::System.Type typem string @namespace = null) { } - } - """; + { { return_type } } +{ { method_name } } ({ { for parameter in parameters } } +{ { parameter.type } } +{ { parameter.name } } +{ { if not loop.last } }, { { endif } } +{ { endfor } }) + { { if has_generic_type_constraints } } +{ { for generic_type_constraint in generic_type_constraints } } +where +{ { generic_type_constraint.name } } : { { type_constraint.constraint } } +{ { endfor } } +{ { endif } } +"""; + + public const string DecomposableAttributeFilename = "DecomposableAttribute.g.cs"; + +public const string DecomposableAttributeDeclaration = + DecomposedInterfaceHeader + + """ +[global::System.AttributeUsage(global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Assembly)] + public sealed class DecomposeAttribute : global::System.Attribute +{ + public DecomposeAttribute(string @namespace = null) { } + public DecomposeAttribute(global::System.Type typem string @namespace = null) { } +} +"""; public const string IComposedClassDeclaration = """ - public partial class {{ class_name }} : {{ for type_member_tuple in decomposed_from }} IDecomposed<{{} decomposed_from.type }}> - { - {{ for type_member_tuple in decomposed_from }} - {{ if type_member_tuple.member.is_property }} - public {{ type_member_tuple.member.type }} {{ type_member_tuple.member.name }} {{ get; }} - {{ elif type_member_tuple.member.is_method }} - public {{ decomposed_from.type }} {{} decomposed_from.member }} {{ get; }} - {{ endfor }} - - - public { class_name }({ decomposed_from } decomposed) - { - { decomposed_from } = decomposed; - } - - public { decomposed_from } { decomposed_from } {{ get; }} + public partial class {{ class_name }} : { { for type_member_tuple in decomposed_from } } +IDecomposed <{ { } decomposed_from.type }}> + { + { { for type_member_tuple in decomposed_from } } + { { if type_member_tuple.member.is_property } } + public +{ { type_member_tuple.member.type } } +{ { type_member_tuple.member.name } } +{ { get; } } +{ { elif type_member_tuple.member.is_method } } +public +{ { decomposed_from.type } } +{ { } decomposed_from.member }} { { get; } } +{ { endfor } } + + +public +{ class_name } ({ decomposed_from } +decomposed) + { + { decomposed_from } = decomposed; +} + +public +{ decomposed_from } +{ decomposed_from } +{ { get; } } } """; @@ -140,18 +162,18 @@ public DecomposeAttribute(global::System.Type typem string @namespace = null) { | SymbolDisplayMiscellaneousOptions.UseErrorTypeSymbolName | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier | SymbolDisplayMiscellaneousOptions.IncludeNotNullableReferenceTypeModifier - ); - - internal const string AttributeName = "Decompose"; - internal const string AttributeFullName = AttributeName + nameof(Attribute); - internal const string InterfaceNamePrefix = "I"; - internal const string InterfaceSuffix = "Decomposition"; - internal const string NamespaceSuffix = ".Decompositions"; - internal const string SourceFileNameSuffix = ".Decompositions.g.cs"; - internal const string GeneratedCodeAttributeName = "GeneratedCodeAttribute"; - internal const string GeneratedCodeAttributeFullName = - $"System.Diagnostics.CodeAnalysis.{GeneratedCodeAttributeName}"; - internal const string CompilerGeneratedAttributeFullName = - "System.Runtime.CompilerServices.CompilerGeneratedAttribute"; + ); + +internal const string AttributeName = "Decompose"; +internal const string AttributeFullName = AttributeName + nameof(Attribute); +internal const string InterfaceNamePrefix = "I"; +internal const string InterfaceSuffix = "Decomposition"; +internal const string NamespaceSuffix = ".Decompositions"; +internal const string SourceFileNameSuffix = ".Decompositions.g.cs"; +internal const string GeneratedCodeAttributeName = "GeneratedCodeAttribute"; +internal const string GeneratedCodeAttributeFullName = + $"System.Diagnostics.CodeAnalysis.{GeneratedCodeAttributeName}"; +internal const string CompilerGeneratedAttributeFullName = + "System.Runtime.CompilerServices.CompilerGeneratedAttribute"; } } diff --git a/InterfaceGenerator/InterfaceGeneratorConstants.cs b/InterfaceGenerator/InterfaceGeneratorConstants.cs index 2725c62..d2a4d63 100644 --- a/InterfaceGenerator/InterfaceGeneratorConstants.cs +++ b/InterfaceGenerator/InterfaceGeneratorConstants.cs @@ -36,16 +36,18 @@ public static class Constants using System; [AttributeUsage(AttributeTargets.Interface)] - internal sealed class {{{GenerateInterfaceAttributeName}}} : Attribute - { - public Type Type { get; } - - public {{{GenerateInterfaceAttributeName}}} (Type type = null) - { - { - Type = type; - } - } + internal sealed class {{{GenerateInterfaceAttributeName +}}} : Attribute +{ + public Type Type { get; } + +public +{ { { GenerateInterfaceAttributeName} } } (Type type = null) + { + { + Type = type; + } +} } """; @@ -63,72 +65,74 @@ internal sealed class {{{GenerateInterfaceAttributeName}}} : Attribute namespace {{ namespace }} { - public partial interface {{ interface_name }} - { - {{ members }} - } + public partial interface {{ interface_name +}} + { + { { members } } +} } """; public static readonly Scriban.Template InterfaceDeclarationTemplate = - Scriban.Template.Parse(InterfaceDeclaration); - - public const string MethodDeclaration = "{{ full_definition }};"; - - public static readonly Scriban.Template MethodDeclarationTemplate = Scriban.Template.Parse( - MethodDeclaration - ); - - public const string MethodParameter = """ - {{ type }} {{ name }} - """; + Scriban.Template.Parse(InterfaceDeclaration); + +public const string MethodDeclaration = "{{ full_definition }};"; + +public static readonly Scriban.Template MethodDeclarationTemplate = Scriban.Template.Parse( + MethodDeclaration +); + +public const string MethodParameter = """ + { { type } } +{ { name } } +"""; public static readonly Scriban.Template MethodParameterTemplate = Scriban.Template.Parse( MethodParameter - ); - - public const string PropertyDeclaration = - "{{ type }} {{ if is_indexed }}this[ {{ indexers }}] {{ else }} {{ name }} {{ end }} { {{ if is_gettable }} get; {{ end }} {{ if is_settable }} set; {{ end }} }"; - - public static readonly Scriban.Template PropertyDeclarationTemplate = - Scriban.Template.Parse(PropertyDeclaration); - - // static Constants() - // { - // if(!InterfaceDeclarationTemplate.HasErrors) - // throw new Exception(string.Join(Environment.NewLine, InterfaceDeclarationTemplate.Messages.Select(m => m.ToString()))); - // } - - public static readonly SymbolDisplayFormat SymbolDisplayFormat = - new( - SymbolDisplayGlobalNamespaceStyle.Included, - SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, - SymbolDisplayGenericsOptions.IncludeTypeParameters - | SymbolDisplayGenericsOptions.IncludeVariance - | SymbolDisplayGenericsOptions.IncludeTypeConstraints, - SymbolDisplayMemberOptions.IncludeConstantValue - | SymbolDisplayMemberOptions.IncludeExplicitInterface - | SymbolDisplayMemberOptions.IncludeModifiers - | SymbolDisplayMemberOptions.IncludeParameters - | SymbolDisplayMemberOptions.IncludeRef - | SymbolDisplayMemberOptions.IncludeType, - SymbolDisplayDelegateStyle.NameAndSignature, - SymbolDisplayExtensionMethodStyle.Default, - SymbolDisplayParameterOptions.IncludeExtensionThis - | SymbolDisplayParameterOptions.IncludeName - | SymbolDisplayParameterOptions.IncludeParamsRefOut - | SymbolDisplayParameterOptions.IncludeType - | SymbolDisplayParameterOptions.IncludeType - | SymbolDisplayParameterOptions.IncludeDefaultValue - | SymbolDisplayParameterOptions.IncludeOptionalBrackets, - SymbolDisplayPropertyStyle.ShowReadWriteDescriptor, - miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes - | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers - | SymbolDisplayMiscellaneousOptions.UseAsterisksInMultiDimensionalArrays - | SymbolDisplayMiscellaneousOptions.UseErrorTypeSymbolName - | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier - | SymbolDisplayMiscellaneousOptions.IncludeNotNullableReferenceTypeModifier - ); + ); + +public const string PropertyDeclaration = + "{{ type }} {{ if is_indexed }}this[ {{ indexers }}] {{ else }} {{ name }} {{ end }} { {{ if is_gettable }} get; {{ end }} {{ if is_settable }} set; {{ end }} }"; + +public static readonly Scriban.Template PropertyDeclarationTemplate = + Scriban.Template.Parse(PropertyDeclaration); + +// static Constants() +// { +// if(!InterfaceDeclarationTemplate.HasErrors) +// throw new Exception(string.Join(Environment.NewLine, InterfaceDeclarationTemplate.Messages.Select(m => m.ToString()))); +// } + +public static readonly SymbolDisplayFormat SymbolDisplayFormat = + new( + SymbolDisplayGlobalNamespaceStyle.Included, + SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, + SymbolDisplayGenericsOptions.IncludeTypeParameters + | SymbolDisplayGenericsOptions.IncludeVariance + | SymbolDisplayGenericsOptions.IncludeTypeConstraints, + SymbolDisplayMemberOptions.IncludeConstantValue + | SymbolDisplayMemberOptions.IncludeExplicitInterface + | SymbolDisplayMemberOptions.IncludeModifiers + | SymbolDisplayMemberOptions.IncludeParameters + | SymbolDisplayMemberOptions.IncludeRef + | SymbolDisplayMemberOptions.IncludeType, + SymbolDisplayDelegateStyle.NameAndSignature, + SymbolDisplayExtensionMethodStyle.Default, + SymbolDisplayParameterOptions.IncludeExtensionThis + | SymbolDisplayParameterOptions.IncludeName + | SymbolDisplayParameterOptions.IncludeParamsRefOut + | SymbolDisplayParameterOptions.IncludeType + | SymbolDisplayParameterOptions.IncludeType + | SymbolDisplayParameterOptions.IncludeDefaultValue + | SymbolDisplayParameterOptions.IncludeOptionalBrackets, + SymbolDisplayPropertyStyle.ShowReadWriteDescriptor, + miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes + | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers + | SymbolDisplayMiscellaneousOptions.UseAsterisksInMultiDimensionalArrays + | SymbolDisplayMiscellaneousOptions.UseErrorTypeSymbolName + | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier + | SymbolDisplayMiscellaneousOptions.IncludeNotNullableReferenceTypeModifier + ); } public record struct InterfaceGeneratorModel( @@ -137,35 +141,35 @@ public record struct InterfaceGeneratorModel( string Members, string TypeParameters, string TypeConstraints - ); - - // public record struct MethodDeclarationModel( - // string ReturnType, - // string MethodName, - // string Parameters, - // string TypeConstraints, - // string FullDefinition - // ); - - // public record struct MethodParameterModel(string Type, string Name); - - // public record struct PropertyDeclarationModel( - // string visibility, - // string Type, - // string Name, - // bool IsGettable, - // bool IsSettable, - // string? Indexers = null - // ) - // { - // public bool IsIndexed => !string.IsNullOrWhiteSpace(Indexers); - - // public string Name { get; } = - // (!string.IsNullOrWhiteSpace(Indexers) ? $"this[{Indexers}]" : Name); - // } - - public static class Environment - { - public const string NewLine = "\r\n"; - } + ); + +// public record struct MethodDeclarationModel( +// string ReturnType, +// string MethodName, +// string Parameters, +// string TypeConstraints, +// string FullDefinition +// ); + +// public record struct MethodParameterModel(string Type, string Name); + +// public record struct PropertyDeclarationModel( +// string visibility, +// string Type, +// string Name, +// bool IsGettable, +// bool IsSettable, +// string? Indexers = null +// ) +// { +// public bool IsIndexed => !string.IsNullOrWhiteSpace(Indexers); + +// public string Name { get; } = +// (!string.IsNullOrWhiteSpace(Indexers) ? $"this[{Indexers}]" : Name); +// } + +public static class Environment +{ + public const string NewLine = "\r\n"; +} }