diff --git a/AutomaticInterface/AutomaticInterface/AutomaticInterface.cs b/AutomaticInterface/AutomaticInterface/AutomaticInterface.cs index 16d871a..721208c 100644 --- a/AutomaticInterface/AutomaticInterface/AutomaticInterface.cs +++ b/AutomaticInterface/AutomaticInterface/AutomaticInterface.cs @@ -52,10 +52,9 @@ public void Execute(GeneratorExecutionContext context) string GetLogPath() { - var mainSyntaxTree = context - .Compilation - .SyntaxTrees - .First(x => x.HasCompilationUnitRoot); + var mainSyntaxTree = context.Compilation.SyntaxTrees.First(x => + x.HasCompilationUnitRoot + ); var logDir = Path.GetDirectoryName(mainSyntaxTree.FilePath) ?? Environment.CurrentDirectory; @@ -200,14 +199,12 @@ SemanticModel classSemanticModel var paramResult = new HashSet(); method - .Parameters - .Select(GetMethodSignature) + .Parameters.Select(GetMethodSignature) .ToList() .ForEach(x => paramResult.Add(x)); var typedArgs = method - .TypeParameters - .Select(arg => (arg.ToDisplayString(), arg.GetWhereStatement())) + .TypeParameters.Select(arg => (arg.ToDisplayString(), arg.GetWhereStatement())) .ToList(); codeGenerator.AddMethodToInterface( name, @@ -356,8 +353,8 @@ ClassDeclarationSyntax classSyntax var match = classSyntax .DescendantNodes() .OfType() - .SingleOrDefault( - x => x.Declaration.Variables.Any(y => y.Identifier.ValueText == method.Name) + .SingleOrDefault(x => + x.Declaration.Variables.Any(y => y.Identifier.ValueText == method.Name) ); if (match is null) @@ -420,7 +417,7 @@ NamespaceDeclarationSyntax ndSyntax ); } - return [ ..allUsings.Select(x => x.ToString()) ]; + return [..allUsings.Select(x => x.ToString())]; } private static List GetClassesToAddInterfaceFor( @@ -428,7 +425,7 @@ private static List GetClassesToAddInterfaceFor( Compilation compilation ) { - List classSymbols = [ ]; + List classSymbols = []; foreach (var cls in receiver.CandidateClasses) { var model = compilation.GetSemanticModel(cls.SyntaxTree); diff --git a/AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs b/AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs index 3ac12ee..7c06510 100644 --- a/AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs +++ b/AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs @@ -29,21 +29,21 @@ bool hasNullableContext ) { private readonly string autogenerated = """ - //-------------------------------------------------------------------------------------------------- - // - // This code was generated by a tool. - // - // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. - // - //-------------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------------------------- + // + // This code was generated by a tool. + // + // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. + // + //-------------------------------------------------------------------------------------------------- - """; + """; - private readonly HashSet usings = [ "using System.CodeDom.Compiler;" ]; - private readonly List propertyInfos = [ ]; - private readonly List methodInfos = [ ]; - private readonly List events = [ ]; + private readonly HashSet usings = ["using System.CodeDom.Compiler;"]; + private readonly List propertyInfos = []; + private readonly List methodInfos = []; + private readonly List events = []; private string classDocumentation = string.Empty; private string genericType = string.Empty; @@ -170,8 +170,7 @@ private static void BuildMethod(CodeBuilder cb, MethodInfo method) if (method.GenericArgs.Count != 0) { var constraints = method - .GenericArgs - .Where(a => !string.IsNullOrWhiteSpace(a.WhereConstraint)) + .GenericArgs.Where(a => !string.IsNullOrWhiteSpace(a.WhereConstraint)) .Select(a => a.WhereConstraint); cb.Append($" {string.Join(" ", constraints)}"); } diff --git a/AutomaticInterface/AutomaticInterface/RoslynExtensions.cs b/AutomaticInterface/AutomaticInterface/RoslynExtensions.cs index 2d37b07..749168e 100644 --- a/AutomaticInterface/AutomaticInterface/RoslynExtensions.cs +++ b/AutomaticInterface/AutomaticInterface/RoslynExtensions.cs @@ -49,14 +49,12 @@ string attributeName { return classSyntax.AttributeLists.Count > 0 && classSyntax - .AttributeLists - .SelectMany( - al => - al.Attributes.Where(a => - { - return (a?.Name as IdentifierNameSyntax)?.Identifier.Text - == attributeName; - }) + .AttributeLists.SelectMany(al => + al.Attributes.Where(a => + { + return (a?.Name as IdentifierNameSyntax)?.Identifier.Text + == attributeName; + }) ) .Any(); } @@ -66,8 +64,7 @@ public static string GetNamespace(this CompilationUnitSyntax root) return root.ChildNodes() .OfType() .First() - .Name - .ToString(); + .Name.ToString(); } public static List GetUsings(this CompilationUnitSyntax root) diff --git a/AutomaticInterface/Tests/CSharpSourceGeneratorVerifier.cs b/AutomaticInterface/Tests/CSharpSourceGeneratorVerifier.cs index 38b5abf..ff98606 100644 --- a/AutomaticInterface/Tests/CSharpSourceGeneratorVerifier.cs +++ b/AutomaticInterface/Tests/CSharpSourceGeneratorVerifier.cs @@ -23,9 +23,9 @@ protected override CompilationOptions CreateCompilationOptions() ); return compilationOptions.WithSpecificDiagnosticOptions( - compilationOptions - .SpecificDiagnosticOptions - .SetItems(GetNullableWarningsFromCompiler()) + compilationOptions.SpecificDiagnosticOptions.SetItems( + GetNullableWarningsFromCompiler() + ) ); } @@ -37,13 +37,11 @@ private static ImmutableDictionary< > GetNullableWarningsFromCompiler() { string[] args = { "/warnaserror:nullable" }; - var commandLineArguments = CSharpCommandLineParser - .Default - .Parse( - args, - baseDirectory: Environment.CurrentDirectory, - sdkDirectory: Environment.CurrentDirectory - ); + var commandLineArguments = CSharpCommandLineParser.Default.Parse( + args, + baseDirectory: Environment.CurrentDirectory, + sdkDirectory: Environment.CurrentDirectory + ); var nullableWarnings = commandLineArguments .CompilationOptions .SpecificDiagnosticOptions; diff --git a/AutomaticInterface/Tests/GeneratorTests.cs b/AutomaticInterface/Tests/GeneratorTests.cs index 772d1f0..7101f85 100644 --- a/AutomaticInterface/Tests/GeneratorTests.cs +++ b/AutomaticInterface/Tests/GeneratorTests.cs @@ -17,8 +17,7 @@ namespace Tests public class GeneratorTests { private readonly ImmutableArray references = AppDomain - .CurrentDomain - .GetAssemblies() + .CurrentDomain.GetAssemblies() .Where(assembly => !assembly.IsDynamic) .Select(assembly => assembly.Location) .ToImmutableArray(); @@ -48,20 +47,17 @@ private async Task RunTestAsync( }; tester.ReferenceAssemblies.AddAssemblies(references); - tester - .TestState - .AdditionalReferences - .Add(typeof(GenerateAutomaticInterfaceAttribute).Assembly); - - tester - .ExpectedDiagnostics - .AddRange( - new List() - { - new("AutomaticInterface", DiagnosticSeverity.Info), - new("AutomaticInterface", DiagnosticSeverity.Info) - } - ); + tester.TestState.AdditionalReferences.Add( + typeof(GenerateAutomaticInterfaceAttribute).Assembly + ); + + tester.ExpectedDiagnostics.AddRange( + new List() + { + new("AutomaticInterface", DiagnosticSeverity.Info), + new("AutomaticInterface", DiagnosticSeverity.Info) + } + ); await tester.RunAsync(); }