Skip to content

Commit 3ff9dda

Browse files
committed
cleanup
1 parent 0a9a0ac commit 3ff9dda

22 files changed

Lines changed: 60 additions & 36 deletions

.editorconfig

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ dotnet_diagnostic.CA1822.severity = error
9393
# Avoid unused private fields
9494
dotnet_diagnostic.CA1823.severity = error
9595

96+
# Remove unused parameter
97+
# non_public, because a public signature sometimes keeps a parameter it does not read: an overload
98+
# retained for binary compatibility cannot drop one without breaking every caller compiled against
99+
# it. Inside a type there is no such excuse, and a parameter nothing reads is either dead weight or
100+
# a bug where the argument was meant to be used.
101+
dotnet_diagnostic.IDE0060.severity = error
102+
dotnet_code_quality_unused_parameters = non_public
103+
104+
# Remove unused private member
105+
dotnet_diagnostic.IDE0051.severity = error
106+
107+
# Remove unread private member
108+
dotnet_diagnostic.IDE0052.severity = error
109+
96110
# Avoid zero-length array allocations
97111
dotnet_diagnostic.CA1825.severity = error
98112

@@ -384,7 +398,7 @@ ij_xml_space_inside_empty_tag = true
384398
indent_size = 2
385399

386400
# Verify settings
387-
[*.{received,verified}.{txt,xml,json,md,sql,csv,html,htm,nuspec,rels}]
401+
[*.{received,verified}.{txt,xml,json,md,mdx,yml,sql,csv,html,htm,nuspec,rels}]
388402
charset = utf-8-bom
389403
end_of_line = lf
390404
indent_size = unset

src/DiffEngine.Tests/FsCompilerRoundTripTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async Task PatchedSourceCompilesAndReadsBack()
6161
{
6262
var script = BuildScript();
6363
var path = Path.Combine(Path.GetTempPath(), $"DiffEngineFsRoundTrip_{Guid.NewGuid():N}.fsx");
64-
File.WriteAllText(path, script, new UTF8Encoding(false));
64+
await File.WriteAllTextAsync(path, script, new UTF8Encoding(false));
6565
try
6666
{
6767
var (exitCode, output) = RunFsi(path);

src/DiffEngine.Tests/InlineApplierTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public async Task LeavesNoTemporaryBehind()
175175
try
176176
{
177177
var path = Path.Combine(directory, "Sample.cs");
178-
File.WriteAllBytes(path, Utf8(source, bom: false));
178+
await File.WriteAllBytesAsync(path, Utf8(source, bom: false));
179179

180180
var result = InlineApplier.Apply(Patch(path, 3, "\"old\"", "new"));
181181

@@ -200,10 +200,10 @@ public async Task ContentIsNeverObservedHalfWritten()
200200
try
201201
{
202202
var path = Path.Combine(directory, "Big.cs");
203-
File.WriteAllBytes(path, Utf8(text, bom: false));
203+
await File.WriteAllBytesAsync(path, Utf8(text, bom: false));
204204
var before = new FileInfo(path).Length;
205205

206-
using var cancellation = new CancellationTokenSource();
206+
using var cancellation = new CancelSource();
207207
var seen = new ConcurrentDictionary<long, byte>();
208208
var reader = Task.Run(
209209
() =>
@@ -229,7 +229,7 @@ public async Task ContentIsNeverObservedHalfWritten()
229229
// Long enough that the two whole files differ in length, which is what makes a
230230
// half written one tell itself apart
231231
var result = InlineApplier.Apply(Patch(path, 3, "\"old\"", "a replacement longer than what it replaces"));
232-
cancellation.Cancel();
232+
await cancellation.CancelAsync();
233233
await reader;
234234

235235
await Assert.That(result.Status).IsEqualTo(InlineApplyStatus.Applied);
@@ -265,7 +265,7 @@ public async Task ConcurrentAppliesNeverReportAMissingFile()
265265
var methods = Enumerable.Range(0, writers)
266266
.Select(_ => $" void M{_}() => Verify(v).Snapshot(\"a{_}\");");
267267
var path = Path.Combine(directory, "Contended.cs");
268-
File.WriteAllBytes(path, Utf8($"class C\n{{\n{string.Join("\n", methods)}\n}}", bom: false));
268+
await File.WriteAllBytesAsync(path, Utf8($"class C\n{{\n{string.Join("\n", methods)}\n}}", bom: false));
269269

270270
var results = await Task.WhenAll(
271271
Enumerable

src/DiffEngine.Tests/InlineStagingTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public async Task WritesTheTrioUnderTheProjectsObj()
1212
var source = project.Source("SampleTests.cs");
1313

1414
var patch = Patch(source, "line one\nline two", framework: "net10.0");
15-
var written = InlineStaging.Persist([new PendingInline(patch)]);
15+
var written = InlineStaging.Persist([new(patch)]);
1616

1717
await Assert.That(written).IsEqualTo(1);
1818

@@ -32,9 +32,9 @@ await Assert.That(Path.GetFileName(patchFile))
3232
await Assert.That(read.OriginalValue).IsEqualTo(patch.OriginalValue);
3333
await Assert.That(read.Framework).IsEqualTo("net10.0");
3434

35-
await Assert.That(File.ReadAllText(files.Single(_ => _.EndsWith(".received.txt"))))
35+
await Assert.That(await File.ReadAllTextAsync(files.Single(_ => _.EndsWith(".received.txt"))))
3636
.IsEqualTo("line one\nline two");
37-
await Assert.That(File.ReadAllText(files.Single(_ => _.EndsWith(".expected.txt"))))
37+
await Assert.That(await File.ReadAllTextAsync(files.Single(_ => _.EndsWith(".expected.txt"))))
3838
.IsEqualTo("old");
3939
}
4040

@@ -44,12 +44,12 @@ public async Task PersistingAgainOverwritesRatherThanAccumulates()
4444
using var project = new TempProject();
4545
var source = project.Source("SampleTests.cs");
4646

47-
InlineStaging.Persist([new PendingInline(Patch(source, "first", framework: "net10.0"))]);
48-
InlineStaging.Persist([new PendingInline(Patch(source, "second", framework: "net10.0"))]);
47+
InlineStaging.Persist([new(Patch(source, "first", framework: "net10.0"))]);
48+
InlineStaging.Persist([new(Patch(source, "second", framework: "net10.0"))]);
4949

5050
var files = project.StagedFiles();
5151
await Assert.That(files.Count).IsEqualTo(3);
52-
await Assert.That(File.ReadAllText(files.Single(_ => _.EndsWith(".received.txt"))))
52+
await Assert.That(await File.ReadAllTextAsync(files.Single(_ => _.EndsWith(".received.txt"))))
5353
.IsEqualTo("second");
5454
}
5555

@@ -82,7 +82,7 @@ public async Task SourceWithNoProjectAboveItIsSkipped()
8282
// stage, and skipped is better than a guess.
8383
var source = Path.Combine(Path.GetTempPath(), $"inline-staging-none-{Guid.NewGuid():N}", "SampleTests.cs");
8484

85-
var written = InlineStaging.Persist([new PendingInline(Patch(source, "content"))]);
85+
var written = InlineStaging.Persist([new(Patch(source, "content"))]);
8686

8787
await Assert.That(written).IsEqualTo(0);
8888
}
@@ -99,7 +99,7 @@ public async Task RemoveIsNeverPersisted()
9999
OriginalValue = "old"
100100
};
101101

102-
var written = InlineStaging.Persist([new PendingInline(remove)]);
102+
var written = InlineStaging.Persist([new(remove)]);
103103

104104
await Assert.That(written).IsEqualTo(0);
105105
await Assert.That(project.StagedFiles()).IsEmpty();
@@ -111,7 +111,7 @@ public async Task UnlabeledPatchStillPersists()
111111
using var project = new TempProject();
112112
var source = project.Source("SampleTests.cs");
113113

114-
var written = InlineStaging.Persist([new PendingInline(Patch(source, "content"))]);
114+
var written = InlineStaging.Persist([new(Patch(source, "content"))]);
115115

116116
await Assert.That(written).IsEqualTo(1);
117117
var patchFile = project.StagedFiles().Single(_ => _.EndsWith(".inlinepatch"));

src/DiffEngine.Tests/RequiresDotnetAttribute.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public override Task<bool> ShouldSkip(TestRegisteredContext context) =>
1717
var root = Environment.GetEnvironmentVariable("DOTNET_ROOT");
1818
if (!string.IsNullOrEmpty(root))
1919
{
20+
// ReSharper disable once RedundantSuppressNullableWarningExpression
2021
var candidate = Path.Combine(root!, name);
2122
if (File.Exists(candidate))
2223
{

src/DiffEngine/Inline/FsStringLiteral.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static string Render(string content, string indent, string eol)
6262
/// </summary>
6363
static bool CanTripleQuote(string content) =>
6464
content[0] != '"' &&
65-
content[content.Length - 1] != '"' &&
65+
content[^1] != '"' &&
6666
content.IndexOf("\"\"\"", StringComparison.Ordinal) == -1 &&
6767
!StringLiteral.HasLineTerminator(content);
6868

src/DiffEngine/Inline/InlinePatcher.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ static int Clamp(int line, int lineCount) =>
734734
break;
735735
}
736736

737+
// ReSharper disable once RedundantSuppressNullableWarningExpression
737738
var end = index + memberName!.Length;
738739
if (scan.IsCode(index) &&
739740
StartsToken(source, scan, index) &&
@@ -1109,7 +1110,7 @@ static string UnitFor(string fileUnit, string lead)
11091110
// spaces for alignment continues in spaces: a tab there would advance to the next tab stop
11101111
// from wherever the alignment left off, which is a different width in every editor. With
11111112
// no indentation to read, follow the file
1112-
var tabs = lead.Length > 0 ? lead[lead.Length - 1] == '\t' : fileUsesTabs;
1113+
var tabs = lead.Length > 0 ? lead[^1] == '\t' : fileUsesTabs;
11131114
if (tabs)
11141115
{
11151116
return "\t";

src/DiffEngine/Inline/InlineQueue.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ static PendingInline Fold(PendingInline entry, InlinePatch patch)
120120
// throws away the completion of an accept whose entry changed identity while the
121121
// patch was applying, and a still failing test re-sending the same patch is exactly
122122
// what happens during those ten seconds
123-
if (entry.Variants is [var only] &&
124-
only.Origins.Count == 0 &&
123+
if (entry.Variants is [{Origins.Count: 0} only] &&
125124
only.Patch.Matches(patch))
126125
{
127126
return Unchanged(entry);

src/DiffEngine/Inline/InlineStaging.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ static string BuildName(InlinePatch patch, string? origin)
159159
return null;
160160
}
161161

162+
// ReSharper disable once RedundantSuppressNullableWarningExpression
162163
var builder = new StringBuilder(value!.Length);
163164
foreach (var character in value)
164165
{

src/DiffEngine/Inline/StringLiteral.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public static bool TryStripLayout(string text, [NotNullWhen(true)] out string? v
247247
return false;
248248
}
249249

250-
var closeIndent = lines[lines.Length - 1];
250+
var closeIndent = lines[^1];
251251
if (closeIndent.Trim().Length > 0)
252252
{
253253
return false;
@@ -485,8 +485,7 @@ public static bool TryScanVerbatim(string text, int start, out string? value, ou
485485
/// </para>
486486
/// </summary>
487487
public static bool IsScalarValue(uint codePoint) =>
488-
codePoint <= 0x10FFFF &&
489-
codePoint is < 0xD800 or > 0xDFFF;
488+
codePoint is <= 0x10FFFF and (< 0xD800 or > 0xDFFF);
490489

491490
public static bool TryReadHex(string text, ref int index, int min, int max, out uint result)
492491
{

0 commit comments

Comments
 (0)