Skip to content

Commit f119e58

Browse files
authored
Code style upgrade (#900)
* Use collection syntax across the entire code base * Add a few missing `ConfigureAwait` * Fix a test not compatible with Entra auth
1 parent 0d2a09c commit f119e58

File tree

131 files changed

+631
-618
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+631
-618
lines changed

.editorconfig

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,34 @@ dotnet_diagnostic.CA1032.severity = none # We're using RCS1194 which seems to co
446446
dotnet_diagnostic.CA1034.severity = none # Do not nest type. Alternatively, change its accessibility so that it is not externally visible
447447
dotnet_diagnostic.CA1054.severity = none # URI parameters should not be strings
448448
dotnet_diagnostic.CA1062.severity = none # Disable null check, C# already does it for us
449-
dotnet_diagnostic.CS1591.severity = none # Missing XML comment for publicly visible type or member
449+
dotnet_diagnostic.CA1515.severity = none # Because an application's API isn't typically referenced from outside the assembly, types can be made internal
450450
dotnet_diagnostic.CA1805.severity = none # Member is explicitly initialized to its default value
451451
dotnet_diagnostic.CA1822.severity = none # Member does not access instance data and can be marked as static
452452
dotnet_diagnostic.CA1848.severity = none # For improved performance, use the LoggerMessage delegates
453453
dotnet_diagnostic.CA2227.severity = none # Change to be read-only by removing the property setter
454454
dotnet_diagnostic.CA2253.severity = none # Named placeholders in the logging message template should not be comprised of only numeric characters
455+
dotnet_diagnostic.CS1591.severity = none # Missing XML comment for publicly visible type or member
456+
dotnet_diagnostic.IDE0001.severity = none # Simplify name
457+
dotnet_diagnostic.IDE0002.severity = none # Simplify member access
458+
dotnet_diagnostic.IDE0004.severity = none # Remove unnecessary cast
459+
dotnet_diagnostic.IDE0010.severity = none # Populate switch
460+
dotnet_diagnostic.IDE0032.severity = none # Use auto property
461+
dotnet_diagnostic.IDE0035.severity = none # Remove unreachable code
462+
dotnet_diagnostic.IDE0051.severity = none # Remove unused private member
463+
dotnet_diagnostic.IDE0052.severity = none # Remove unread private member
464+
dotnet_diagnostic.IDE0056.severity = none # Indexing can be simplified
465+
dotnet_diagnostic.IDE0057.severity = none # Substring can be simplified
466+
dotnet_diagnostic.IDE0058.severity = none # Remove unused expression value
467+
dotnet_diagnostic.IDE0059.severity = none # Unnecessary assignment of a value
468+
dotnet_diagnostic.IDE0060.severity = none # Remove unused parameter
469+
dotnet_diagnostic.IDE0066.severity = none # Use 'switch' expression
470+
dotnet_diagnostic.IDE0072.severity = none # Populate switch
471+
dotnet_diagnostic.IDE0080.severity = none # Remove unnecessary suppression operator
472+
dotnet_diagnostic.IDE0100.severity = none # Remove unnecessary equality operator
473+
dotnet_diagnostic.IDE0110.severity = none # Remove unnecessary discards
474+
dotnet_diagnostic.IDE0160.severity = none # Use block-scoped namespace
475+
dotnet_diagnostic.IDE0290.severity = none # Use primary constructor
476+
dotnet_diagnostic.IDE0305.severity = none # Collection initialization can be simplified
455477
dotnet_diagnostic.RCS1021.severity = none # Use expression-bodied lambda.
456478
dotnet_diagnostic.RCS1061.severity = none # Merge 'if' with nested 'if'.
457479
dotnet_diagnostic.RCS1069.severity = none # Remove unnecessary case label.
@@ -480,26 +502,11 @@ dotnet_diagnostic.RCS1226.severity = none # Add paragraph to documentation comme
480502
dotnet_diagnostic.RCS1234.severity = none # Enum duplicate value
481503
dotnet_diagnostic.RCS1238.severity = none # Avoid nested ?: operators.
482504
dotnet_diagnostic.RCS1241.severity = none # Implement IComparable when implementing IComparable<T><T>.
483-
dotnet_diagnostic.IDE0001.severity = none # Simplify name
484-
dotnet_diagnostic.IDE0002.severity = none # Simplify member access
485-
dotnet_diagnostic.IDE0004.severity = none # Remove unnecessary cast
486-
dotnet_diagnostic.IDE0035.severity = none # Remove unreachable code
487-
dotnet_diagnostic.IDE0051.severity = none # Remove unused private member
488-
dotnet_diagnostic.IDE0052.severity = none # Remove unread private member
489-
dotnet_diagnostic.IDE0058.severity = none # Remove unused expression value
490-
dotnet_diagnostic.IDE0059.severity = none # Unnecessary assignment of a value
491-
dotnet_diagnostic.IDE0060.severity = none # Remove unused parameter
492-
dotnet_diagnostic.IDE0080.severity = none # Remove unnecessary suppression operator
493-
dotnet_diagnostic.IDE0100.severity = none # Remove unnecessary equality operator
494-
dotnet_diagnostic.IDE0110.severity = none # Remove unnecessary discards
495-
dotnet_diagnostic.IDE0032.severity = none # Use auto property
496-
dotnet_diagnostic.IDE0160.severity = none # Use block-scoped namespace
497505
dotnet_diagnostic.VSTHRD111.severity = none # Use .ConfigureAwait(bool) is hidden by default, set to none to prevent IDE from changing on autosave
498506
dotnet_diagnostic.xUnit1004.severity = none # Test methods should not be skipped. Remove the Skip property to start running the test again.
499507

500508
dotnet_diagnostic.SKEXP0003.severity = none # XYZ is for evaluation purposes only
501509
dotnet_diagnostic.SKEXP0010.severity = none
502-
dotnet_diagnostic.SKEXP0010.severity = none
503510
dotnet_diagnostic.SKEXP0011.severity = none
504511
dotnet_diagnostic.SKEXP0052.severity = none
505512
dotnet_diagnostic.SKEXP0101.severity = none

Directory.Packages.props

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@
7575
<PrivateAssets>all</PrivateAssets>
7676
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
7777
</PackageVersion>
78-
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0" />
79-
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
78+
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
79+
<PrivateAssets>all</PrivateAssets>
80+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
81+
</PackageVersion>
82+
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
8083
<PrivateAssets>all</PrivateAssets>
8184
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
8285
</PackageVersion>

applications/evaluation/Distribution.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ public struct Distribution : IEquatable<Distribution>
1717
public Distribution() { }
1818

1919
// TODO: use tolerance when comparing floating numbers for equality
20-
public override bool Equals(object? obj) => obj is Distribution distribution &&
21-
this.Simple == distribution.Simple &&
22-
this.Reasoning == distribution.Reasoning &&
23-
this.MultiContext == distribution.MultiContext &&
24-
this.Conditioning == distribution.Conditioning;
20+
public override readonly bool Equals(object? obj) => obj is Distribution distribution &&
21+
this.Simple == distribution.Simple &&
22+
this.Reasoning == distribution.Reasoning &&
23+
this.MultiContext == distribution.MultiContext &&
24+
this.Conditioning == distribution.Conditioning;
2525

26-
public override int GetHashCode()
26+
public override readonly int GetHashCode()
2727
{
2828
return HashCode.Combine(this.Simple, this.Reasoning, this.MultiContext, this.Conditioning);
2929
}
@@ -38,9 +38,8 @@ public override int GetHashCode()
3838
return !(left == right);
3939
}
4040

41-
public bool Equals(Distribution other)
41+
public readonly bool Equals(Distribution other)
4242
{
4343
return this == other;
4444
}
4545
}
46-

applications/evaluation/Evaluators/AnswerCorrectness/StatementExtraction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ internal sealed class StatementExtraction
1212
#pragma warning restore CA1812 // 'StatementExtraction' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
1313
{
1414
[JsonPropertyName("statements")]
15-
public List<string> Statements { get; set; } = new List<string>();
15+
public List<string> Statements { get; set; } = [];
1616
}

applications/evaluation/Evaluators/ContextRecall/GroundTruthClassifications.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ internal sealed class GroundTruthClassifications
1212
#pragma warning restore CA1812 // 'GroundTruthClassifications' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
1313
{
1414
[JsonPropertyName("evaluations")]
15-
public List<GroundTruthClassification> Evaluations { get; set; } = new();
15+
public List<GroundTruthClassification> Evaluations { get; set; } = [];
1616
}

applications/evaluation/Evaluators/Faithfulness/FaithfulnessEvaluations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ internal sealed class FaithfulnessEvaluations
1212
#pragma warning restore CA1812 // 'FaithfulnessEvaluations' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
1313
{
1414
[JsonPropertyName("evaluations")]
15-
public List<StatementEvaluation> Evaluations { get; set; } = new();
15+
public List<StatementEvaluation> Evaluations { get; set; } = [];
1616
}

applications/evaluation/TestSet/TestSetItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public sealed class TestSetItem
1515

1616
public int GroundTruthVerdict { get; set; }
1717

18-
public IEnumerable<string> Context { get; set; } = Array.Empty<string>();
18+
public IEnumerable<string> Context { get; set; } = [];
1919

2020
public ICollection<MemoryFilter> Filters { get; set; } = Array.Empty<MemoryFilter>();
2121

applications/evaluation/TestSetEvaluator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public class QuestionEvaluation
129129

130130
public MemoryAnswer MemoryAnswer { get; set; } = null!;
131131

132-
public EvaluationMetrics Metrics { get; set; } = new EvaluationMetrics();
132+
public EvaluationMetrics Metrics { get; set; } = new();
133133

134-
public Dictionary<string, object?> Metadata { get; set; } = new();
134+
public Dictionary<string, object?> Metadata { get; set; } = [];
135135
}

applications/evaluation/TestSetGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public async IAsyncEnumerable<TestSetItem> GenerateTestSetsAsync(
9797

9898
var documentIds = new List<string>();
9999

100-
await foreach (var record in this._memory.GetListAsync(index, limit: int.MaxValue))
100+
await foreach (var record in this._memory.GetListAsync(index, limit: int.MaxValue).ConfigureAwait(false))
101101
{
102102
if (documentIds.Contains(record.GetDocumentId()))
103103
{
@@ -110,7 +110,7 @@ public async IAsyncEnumerable<TestSetItem> GenerateTestSetsAsync(
110110
foreach (var documentId in documentIds)
111111
{
112112
var partitionRecords = await this._memory.GetListAsync(index,
113-
filters: new[] { new MemoryFilter().ByDocument(documentId) },
113+
filters: [new MemoryFilter().ByDocument(documentId)],
114114
limit: int.MaxValue)
115115
.ToArrayAsync()
116116
.ConfigureAwait(false);
@@ -123,7 +123,7 @@ public async IAsyncEnumerable<TestSetItem> GenerateTestSetsAsync(
123123
.Concat(this.GetMultiContextTestSetsAsync(nodes.Skip(simpleCount + reasoningCount).Take(multiContextCount), language: language, retryCount: retryCount))
124124
.Concat(this.GetConditioningTestSetsAsync(nodes.Skip(simpleCount + reasoningCount + multiContextCount).Take(conditioningCount), language: language, retryCount: retryCount));
125125

126-
await foreach (var item in questions)
126+
await foreach (var item in questions.ConfigureAwait(false))
127127
{
128128
yield return item;
129129
}

applications/tests/Evaluation.Tests/TestsetGenerationTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,13 @@ await this._memory
8181
documentId: "file1-NASA-news",
8282
steps: Constants.PipelineWithoutSummary);
8383

84-
var evaluation = await this._testSetEvaluator.EvaluateTestSetAsync("default4tests", new[]
85-
{
84+
var evaluation = await this._testSetEvaluator.EvaluateTestSetAsync("default4tests", [
8685
new TestSetItem
8786
{
8887
Question = "What is the role of the Department of Defense in the recovery operations for the Artemis II mission?",
8988
GroundTruth = "The Department of Defense personnel are involved in practicing recovery operations for the Artemis II mission. They use a crew module test article to help verify the recovery team's readiness to recover the Artemis II crew and the Orion spacecraft.",
9089
}
91-
}).ToArrayAsync();
90+
]).ToArrayAsync();
9291

9392
Assert.NotEmpty(evaluation);
9493
}

0 commit comments

Comments
 (0)