Skip to content

Commit

Permalink
Automatically linting code
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll authored and renovate[bot] committed Dec 31, 2023
1 parent 7df425e commit e94af1e
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions test/Analyzers.Tests/ModuleInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
);
Expand All @@ -60,23 +60,24 @@ 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));
}

private static ConversionResult Convert(GenerationTestResult target, IReadOnlyDictionary<string, object> context)
{
return new(new { target.Diagnostics }, target.SyntaxTrees.Select(Selector));
return new(new { target.Diagnostics, }, target.SyntaxTrees.Select(Selector));
}


Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -217,4 +223,4 @@ public override void Write(VerifyJsonWriter writer, SourceText value)
writer.WriteValue(value.ToString());
}
}
}
}

0 comments on commit e94af1e

Please sign in to comment.