Skip to content

Commit ddf0682

Browse files
committed
Apply updated code style
1 parent ab99859 commit ddf0682

40 files changed

Lines changed: 462 additions & 439 deletions

Roslyn.Testing/Analyzer/CSharpDiagnosticAnalyzerTest.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,18 @@ public abstract class CSharpDiagnosticAnalyzerTest<T> : FileReaderTest
1111
where T : DiagnosticAnalyzer, new()
1212
{
1313
/// <inheritdoc />
14-
public override string Filepath => _diagnosticAnalyzer.GetType().Name;
14+
public override string Filepath =>
15+
_diagnosticAnalyzer.GetType()
16+
.Name;
1517

1618
/// <inheritdoc />
1719
public override string PathToTestData => "./TestData/Analyzer/";
1820

1921
private readonly DiagnosticAnalyzer _diagnosticAnalyzer;
2022

21-
protected CSharpDiagnosticAnalyzerTest()
22-
{
23-
_diagnosticAnalyzer = new T();
24-
}
23+
protected CSharpDiagnosticAnalyzerTest() => _diagnosticAnalyzer = new T();
2524

26-
protected virtual IEnumerable<MetadataReference> GetAdditionalReferences()
27-
{
28-
return Enumerable.Empty<MetadataReference>();
29-
}
25+
protected virtual IEnumerable<MetadataReference> GetAdditionalReferences() => Enumerable.Empty<MetadataReference>();
3026

3127
/// <summary>
3228
/// Called to test a C# DiagnosticAnalyzer when applied on the single inputted
@@ -38,20 +34,23 @@ protected virtual IEnumerable<MetadataReference> GetAdditionalReferences()
3834
/// DiagnosticResults that should appear after the analyzer
3935
/// is run on the source
4036
/// </param>
41-
protected void VerifyDiagnostic(string source, DiagnosticResult[] expected)
37+
protected void VerifyDiagnostic(string source, DiagnosticResult[] expected) => VerifyDiagnostic(new[]
4238
{
43-
VerifyDiagnostic(new[] { source }, expected);
44-
}
39+
source
40+
}, expected);
4541

46-
protected void VerifyDiagnostic(string source, DiagnosticResult expected)
42+
protected void VerifyDiagnostic(string source, DiagnosticResult expected) => VerifyDiagnostic(new[]
4743
{
48-
VerifyDiagnostic(new[] { source }, new[] { expected });
49-
}
44+
source
45+
}, new[]
46+
{
47+
expected
48+
});
5049

51-
protected void VerifyNoDiagnosticTriggered(string source)
50+
protected void VerifyNoDiagnosticTriggered(string source) => VerifyDiagnostic(new[]
5251
{
53-
VerifyDiagnostic(new[] { source }, new DiagnosticResult[0]);
54-
}
52+
source
53+
}, new DiagnosticResult[0]);
5554

5655
/// <summary>
5756
/// Called to test a C# DiagnosticAnalyzer when applied on the inputted strings as

Roslyn.Testing/Analyzer/DiagnosticVerifier.Helpers.cs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public abstract class DiagnosticVerifier
3838

3939
internal static string TestProjectName = "TestProject";
4040

41-
#region Get Diagnostics
41+
#region Get Diagnostics
4242

4343
/// <summary>
4444
/// Given classes in the form of strings, their language, and an
@@ -55,10 +55,8 @@ public abstract class DiagnosticVerifier
5555
/// </returns>
5656
[UsedImplicitly]
5757
private static Diagnostic[] GetSortedDiagnostics(string[] sources, string language, ImmutableArray<DiagnosticAnalyzer> analyzers,
58-
IEnumerable<MetadataReference> references = null)
59-
{
60-
return GetSortedDiagnosticsFromDocuments(analyzers, GetDocuments(sources, language, references));
61-
}
58+
IEnumerable<MetadataReference> references = null) =>
59+
GetSortedDiagnosticsFromDocuments(analyzers, GetDocuments(sources, language, references));
6260

6361
/// <summary>
6462
/// Given an analyzer and a document to apply it to, run the analyzer and gather an
@@ -84,8 +82,14 @@ protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(ImmutableArray<D
8482

8583
foreach (var project in projects)
8684
{
87-
var compilationWithAnalyzers = project.GetCompilationAsync().GetAwaiter().GetResult().WithAnalyzers(analyzers);
88-
var diags = compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().GetAwaiter().GetResult();
85+
var compilationWithAnalyzers = project.GetCompilationAsync()
86+
.GetAwaiter()
87+
.GetResult()
88+
.WithAnalyzers(analyzers);
89+
90+
var diags = compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync()
91+
.GetAwaiter()
92+
.GetResult();
8993

9094
foreach (var diag in diags)
9195
{
@@ -97,7 +101,10 @@ protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(ImmutableArray<D
97101
for (var i = 0; i < documents.Length; i++)
98102
{
99103
var document = documents[i];
100-
var tree = document.GetSyntaxTreeAsync().GetAwaiter().GetResult();
104+
105+
var tree = document.GetSyntaxTreeAsync()
106+
.GetAwaiter()
107+
.GetResult();
101108

102109
if (tree == diag.Location.SourceTree)
103110
{
@@ -119,14 +126,13 @@ protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(ImmutableArray<D
119126
/// </summary>
120127
/// <param name="diagnostics"> The list of Diagnostics to be sorted </param>
121128
/// <returns> An IEnumerable containing the Diagnostics in order of Location </returns>
122-
private static Diagnostic[] SortDiagnostics(IEnumerable<Diagnostic> diagnostics)
123-
{
124-
return diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
125-
}
129+
private static Diagnostic[] SortDiagnostics(IEnumerable<Diagnostic> diagnostics) => diagnostics
130+
.OrderBy(d => d.Location.SourceSpan.Start)
131+
.ToArray();
126132

127-
#endregion
133+
#endregion
128134

129-
#region Set up compilation and documents
135+
#region Set up compilation and documents
130136

131137
/// <summary>
132138
/// Given an array of strings as sources and a language, turn them into a project
@@ -165,10 +171,11 @@ private static Document[] GetDocuments(string[] sources, string language, IEnume
165171
/// <param name="references"></param>
166172
/// <returns> A Document created from the source string </returns>
167173
protected static Document CreateDocument(string source, string language = LanguageNames.CSharp,
168-
IEnumerable<MetadataReference> references = null)
169-
{
170-
return CreateProject(new[] { source }, language, references).Documents.First();
171-
}
174+
IEnumerable<MetadataReference> references = null) => CreateProject(new[]
175+
{
176+
source
177+
}, language, references)
178+
.Documents.First();
172179

173180
/// <summary>
174181
/// Create a project using the inputted strings as sources.
@@ -184,7 +191,10 @@ private static Project CreateProject(string[] sources, string language = Languag
184191
IEnumerable<MetadataReference> references = null)
185192
{
186193
var fileNamePrefix = DefaultFilePathPrefix;
187-
var fileExt = language == LanguageNames.CSharp ? CSharpDefaultFileExt : VisualBasicDefaultExt;
194+
195+
var fileExt = language == LanguageNames.CSharp
196+
? CSharpDefaultFileExt
197+
: VisualBasicDefaultExt;
188198

189199
var projectId = ProjectId.CreateNewId(TestProjectName);
190200

@@ -215,5 +225,5 @@ private static Project CreateProject(string[] sources, string language = Languag
215225
return solution.GetProject(projectId);
216226
}
217227

218-
#endregion
228+
#endregion
219229
}

0 commit comments

Comments
 (0)