From e94af1e8f9ad68d38b4a52ddc5c5c8012fbee3f6 Mon Sep 17 00:00:00 2001 From: david-driscoll Date: Sun, 31 Dec 2023 03:38:17 +0000 Subject: [PATCH] Automatically linting code --- test/Analyzers.Tests/ModuleInitializer.cs | 48 +++++++++++++---------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/test/Analyzers.Tests/ModuleInitializer.cs b/test/Analyzers.Tests/ModuleInitializer.cs index 8895bd5e9..7a8097714 100644 --- a/test/Analyzers.Tests/ModuleInitializer.cs +++ b/test/Analyzers.Tests/ModuleInitializer.cs @@ -43,9 +43,9 @@ static string GetTypeName(Type type) // ReSharper disable once RedundantAssignment var path = Path.Combine(Path.GetDirectoryName(sourceFile)!, "snapshots"); -#if !ROSLYN_CURRENT + #if !ROSLYN_CURRENT path = Path.Combine(Path.GetDirectoryName(sourceFile)!, "../Analyzers.Tests", "snapshots"); -#endif + #endif return new(path, typeName, method.Name); } ); @@ -60,15 +60,16 @@ private static ConversionResult Convert(GenerationTestResults target, IReadOnlyD targets.AddRange(item.Value.SyntaxTrees.Select(Selector)); } - return new(new { target.ResultDiagnostics, Results = target.Results.ToDictionary(z => z.Key.FullName!, z => z.Value.Diagnostics) }, targets); + return new(new { target.ResultDiagnostics, Results = target.Results.ToDictionary(z => z.Key.FullName!, z => z.Value.Diagnostics), }, targets); } private static Target Selector(SyntaxTree source) { - var hintPath = source.FilePath - .Replace("\\", "/", StringComparison.OrdinalIgnoreCase) - .Replace(".roslyn4.0", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace(".roslyn4.4", string.Empty, StringComparison.OrdinalIgnoreCase); + var hintPath = source + .FilePath + .Replace("\\", "/", StringComparison.OrdinalIgnoreCase) + .Replace(".roslyn4.0", string.Empty, StringComparison.OrdinalIgnoreCase) + .Replace(".roslyn4.4", string.Empty, StringComparison.OrdinalIgnoreCase); var data = $@"//HintName: {hintPath} {source.GetText()}"; return new("cs", data.Replace("\r", string.Empty, StringComparison.OrdinalIgnoreCase)); @@ -76,7 +77,7 @@ private static Target Selector(SyntaxTree source) private static ConversionResult Convert(GenerationTestResult target, IReadOnlyDictionary context) { - return new(new { target.Diagnostics }, target.SyntaxTrees.Select(Selector)); + return new(new { target.Diagnostics, }, target.SyntaxTrees.Select(Selector)); } @@ -91,9 +92,10 @@ private static ConversionResult Convert(GeneratorDriverRunResult target, IReadOn exceptions.Add(result.Exception); } - var collection = result.GeneratedSources - .OrderBy(x => x.HintName) - .Select(SourceToTarget); + var collection = result + .GeneratedSources + .OrderBy(x => x.HintName) + .Select(SourceToTarget); targets.AddRange(collection); } @@ -110,9 +112,9 @@ private static ConversionResult Convert(GeneratorDriverRunResult target, IReadOn if (target.Diagnostics.Any()) { var info = new - { - target.Diagnostics - }; + { + target.Diagnostics, + }; return new(info, targets); } @@ -121,9 +123,10 @@ private static ConversionResult Convert(GeneratorDriverRunResult target, IReadOn private static Target SourceToTarget(GeneratedSourceResult source) { - var hintName = source.HintName - .Replace(".roslyn4.0", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace(".roslyn4.4", string.Empty, StringComparison.OrdinalIgnoreCase); + var hintName = source + .HintName + .Replace(".roslyn4.0", string.Empty, StringComparison.OrdinalIgnoreCase) + .Replace(".roslyn4.4", string.Empty, StringComparison.OrdinalIgnoreCase); var data = $@"//HintName: {hintName} {source.SourceText}"; return new("cs", data, Path.GetFileNameWithoutExtension(hintName)); @@ -181,9 +184,12 @@ public override void Write(VerifyJsonWriter writer, GeneratedSourceResult value) { writer.WriteStartObject(); writer.WriteMember( - value, value.HintName - .Replace(".roslyn4.0", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace(".roslyn4.4", string.Empty, StringComparison.OrdinalIgnoreCase), "HintName" + value, + value + .HintName + .Replace(".roslyn4.0", string.Empty, StringComparison.OrdinalIgnoreCase) + .Replace(".roslyn4.4", string.Empty, StringComparison.OrdinalIgnoreCase), + "HintName" ); writer.WriteMember(value, value.SourceText, "Source"); writer.WriteEndObject(); @@ -217,4 +223,4 @@ public override void Write(VerifyJsonWriter writer, SourceText value) writer.WriteValue(value.ToString()); } } -} +} \ No newline at end of file