Skip to content

Commit 7b6d22d

Browse files
Fix eol handling on the last token in a file when formatting code actions (#79602)
Fixes #79584
2 parents 2d01ce7 + 6c1bed7 commit 7b6d22d

File tree

11 files changed

+99
-106
lines changed

11 files changed

+99
-106
lines changed

src/Analyzers/CSharp/Tests/ImplementAbstractClass/ImplementAbstractClassTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,6 @@ public override void AbstractMethod()
21252125
throw new System.NotImplementedException();
21262126
}
21272127
}
2128-
21292128
""", parseOptions: TestOptions.RegularPreview);
21302129

21312130
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/48742")]

src/Analyzers/CSharp/Tests/ImplementInterface/ImplementInterfaceCodeFixTests.cs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.CodeAnalysis.CSharp.Shared.Extensions;
1111
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
1212
using Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics.NamingStyles;
13+
using Microsoft.CodeAnalysis.Formatting;
1314
using Microsoft.CodeAnalysis.ImplementType;
1415
using Microsoft.CodeAnalysis.Test.Utilities;
1516
using Microsoft.CodeAnalysis.Testing;
@@ -578,7 +579,6 @@ public void Method1()
578579
throw new System.NotImplementedException();
579580
}
580581
}
581-
582582
""");
583583

584584
[Theory, CombinatorialData, WorkItem("https://github.com/dotnet/roslyn/issues/26323")]
@@ -2087,7 +2087,6 @@ public object GetService(Type serviceType)
20872087
throw new NotImplementedException();
20882088
}
20892089
}
2090-
20912090
""");
20922091

20932092
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/540318")]
@@ -3107,8 +3106,7 @@ abstract class Goo : IGoo
31073106
{
31083107
public event EventHandler E;
31093108
}
3110-
""",
3111-
index: 0);
3109+
""");
31123110

31133111
[Fact]
31143112
public Task TestImplementEventAbstractly()
@@ -5687,7 +5685,6 @@ public void Goo<@class>()
56875685
throw new System.NotImplementedException();
56885686
}
56895687
}
5690-
56915688
""");
56925689

56935690
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545922")]
@@ -5775,7 +5772,6 @@ public object GetService(Type serviceType)
57755772
throw new NotImplementedException();
57765773
}
57775774
}
5778-
57795775
""");
57805776

57815777
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529920")]
@@ -5821,7 +5817,6 @@ public object GetService(Type serviceType)
58215817
throw new NotImplementedException();
58225818
}
58235819
}
5824-
58255820
""");
58265821

58275822
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529947")]
@@ -5863,8 +5858,7 @@ public void Dispose()
58635858
throw new NotImplementedException();
58645859
}
58655860
}
5866-
5867-
""", index: 0);
5861+
""");
58685862

58695863
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/958699")]
58705864
[WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994456")]
@@ -5882,7 +5876,6 @@ class C : IDisposable
58825876
58835877
{{DisposePattern("protected virtual ", "C", "public void ")}}
58845878
}
5885-
58865879
""", index: 1);
58875880

58885881
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/958699")]
@@ -5902,7 +5895,6 @@ void IDisposable.Dispose()
59025895
throw new NotImplementedException();
59035896
}
59045897
}
5905-
59065898
""", index: 2);
59075899

59085900
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/941469")]
@@ -5946,7 +5938,6 @@ abstract class C : IDisposable
59465938
{
59475939
public abstract void Dispose();
59485940
}
5949-
59505941
""", index: 2);
59515942

59525943
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/958699")]
@@ -5985,7 +5976,6 @@ class C : System.IDisposable
59855976
59865977
{{DisposePattern("protected virtual ", "C", "void System.IDisposable.", gcPrefix: "System.")}}
59875978
}
5988-
59895979
""",
59905980
CodeActionIndex = 3,
59915981

@@ -6024,7 +6014,7 @@ public void F()
60246014
throw new NotImplementedException();
60256015
}
60266016
}
6027-
""", index: 0);
6017+
""");
60286018

60296019
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/951968")]
60306020
public Task TestImplementIDisposableViaBaseInterface()
@@ -6138,7 +6128,6 @@ public void Dispose()
61386128
throw new NotImplementedException();
61396129
}
61406130
}
6141-
61426131
""");
61436132

61446133
[Fact]
@@ -6157,7 +6146,6 @@ void IDisposable.Dispose()
61576146
throw new NotImplementedException();
61586147
}
61596148
}
6160-
61616149
""", index: 1);
61626150

61636151
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545924")]
@@ -6230,7 +6218,6 @@ public object GetService(Type serviceType)
62306218
throw new NotImplementedException();
62316219
}
62326220
}
6233-
62346221
""");
62356222

62366223
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545939")]
@@ -6250,7 +6237,6 @@ public object GetService(Type serviceType)
62506237
throw new NotImplementedException();
62516238
}
62526239
}
6253-
62546240
""");
62556241

62566242
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545939")]
@@ -6270,7 +6256,6 @@ public object GetService(Type serviceType)
62706256
throw new NotImplementedException();
62716257
}
62726258
}
6273-
62746259
""");
62756260

62766261
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545939")]
@@ -6290,7 +6275,6 @@ public object GetService(Type serviceType)
62906275
throw new NotImplementedException();
62916276
}
62926277
}
6293-
62946278
""");
62956279

62966280
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545940")]
@@ -7030,7 +7014,7 @@ public void Dispose()
70307014
throw new NotImplementedException();
70317015
}
70327016
}
7033-
""", index: 0);
7017+
""");
70347018

70357019
[Fact]
70367020
public Task TestImplementInterfaceForIDisposableNonApplicable2()
@@ -7059,7 +7043,7 @@ public void Dispose()
70597043
throw new NotImplementedException();
70607044
}
70617045
}
7062-
""", index: 0);
7046+
""");
70637047

70647048
[Fact]
70657049
public Task TestImplementInterfaceForExplicitIDisposableWithSealedClass()
@@ -10054,7 +10038,6 @@ public void M1()
1005410038
throw new System.NotImplementedException();
1005510039
}
1005610040
}
10057-
1005810041
""",
1005910042
}.RunAsync();
1006010043

@@ -10085,7 +10068,6 @@ public void M1()
1008510068
throw new System.NotImplementedException();
1008610069
}
1008710070
}
10088-
1008910071
""",
1009010072
}.RunAsync();
1009110073

@@ -10116,7 +10098,6 @@ public void M1()
1011610098
throw new System.NotImplementedException();
1011710099
}
1011810100
}
10119-
1012010101
""",
1012110102
}.RunAsync();
1012210103

@@ -10185,7 +10166,6 @@ public void M1()
1018510166
throw new System.NotImplementedException();
1018610167
}
1018710168
}
10188-
1018910169
""",
1019010170
}.RunAsync();
1019110171

@@ -11900,4 +11880,27 @@ class C1 : I1
1190011880
ReferenceAssemblies = ReferenceAssemblies.Net.Net80,
1190111881
LanguageVersion = LanguageVersionExtensions.CSharpNext,
1190211882
}.RunAsync();
11883+
11884+
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79584")]
11885+
public Task TestImplementIDisposable_DisposePattern_LF_EndOfLine()
11886+
=> new VerifyCS.Test
11887+
{
11888+
TestCode = """
11889+
using System;
11890+
class C : {|CS0535:IDisposable|}{|CS1513:|}{|CS1514:|}
11891+
""".Replace("\r\n", "\n"),
11892+
FixedCode = $$"""
11893+
using System;
11894+
class C : IDisposable
11895+
{
11896+
private bool disposedValue;
11897+
11898+
{{DisposePattern("protected virtual ", "C", "public void ")}}
11899+
}
11900+
""".Replace("\r\n", "\n"),
11901+
CodeActionIndex = 1,
11902+
ReferenceAssemblies = ReferenceAssemblies.Net.Net80,
11903+
LanguageVersion = LanguageVersionExtensions.CSharpNext,
11904+
Options = { { FormattingOptions2.NewLine, "\n" } },
11905+
}.RunAsync();
1190311906
}

src/Analyzers/CSharp/Tests/PopulateSwitch/PopulateSwitchStatementTests_FixAllTests.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#nullable disable
6-
75
using System.Threading.Tasks;
86
using Microsoft.CodeAnalysis.Test.Utilities;
97
using Xunit;
@@ -271,7 +269,7 @@ void Method()
271269
}
272270
}
273271
}
274-
</Document>
272+
</Document>
275273
<Document>
276274
namespace ConsoleApplication1
277275
{
@@ -292,7 +290,7 @@ void Method()
292290
}
293291
}
294292
}
295-
</Document>
293+
</Document>
296294
</Project>
297295
<Project Language="C#" AssemblyName="Assembly2" CommonReferences="true">
298296
<Document>
@@ -425,7 +423,7 @@ void Method()
425423
}
426424
}
427425
}
428-
</Document>
426+
</Document>
429427
<Document>
430428
namespace ConsoleApplication1
431429
{
@@ -450,7 +448,7 @@ void Method()
450448
}
451449
}
452450
}
453-
</Document>
451+
</Document>
454452
</Project>
455453
<Project Language="C#" AssemblyName="Assembly2" CommonReferences="true">
456454
<Document>
@@ -477,7 +475,7 @@ void Method()
477475
}
478476
}
479477
}
480-
</Document>
478+
</Document>
481479
</Project>
482480
</Workspace>
483481
""");

src/EditorFeatures/CSharpTest/CodeActions/GenerateType/GenerateTypeTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5068,7 +5068,6 @@ X void X<X void X
50685068
{
50695069
}
50705070
}
5071-
50725071
""",
50735072
index: 2);
50745073

src/EditorFeatures/CSharpTest/CodeActions/InitializeParameter/InitializeMemberFromPrimaryConstructorParameterTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ class C(string s)
347347
{
348348
public string S { get; } = s;
349349
}
350-
351350
""");
352351

353352
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/19956")]
@@ -361,7 +360,6 @@ class C(string s)
361360
{
362361
private readonly string s = s;
363362
}
364-
365363
""",
366364
index: 1);
367365

0 commit comments

Comments
 (0)