Skip to content

Commit

Permalink
Fix formatting of attributes at end of file
Browse files Browse the repository at this point in the history
Fixes #59637
  • Loading branch information
sharwell committed Feb 23, 2022
1 parent 6a2daff commit ab5e014
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -1633,6 +1634,23 @@ protected void Render()
await AssertFormatAsync(expected, code, spans: null);
}

[WpfTheory]
[CombinatorialData]
[WorkItem(59637, "https://github.com/dotnet/roslyn/issues/59637")]
public async Task FormatAttributeAtEndOfFile(bool trailingNewLine)
{
var endOfFile = trailingNewLine ? Environment.NewLine : "";
var code = $@"using System.Diagnostics.CodeAnalysis;
[assembly:SuppressMessage(""Globalization"", ""CA1308: Normalize strings to uppercase"", Justification = ""My reason"", Scope = ""member"", Target = ""~M:Method"") ] {endOfFile}";
var expected = $@"using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage(""Globalization"", ""CA1308: Normalize strings to uppercase"", Justification = ""My reason"", Scope = ""member"", Target = ""~M:Method"")]{endOfFile}";

await AssertFormatAsync(expected, code, spans: null);
await AssertFormatAsync(expected, expected, spans: null);
}

[WorkItem(30787, "https://github.com/dotnet/roslyn/issues/30787")]
[WpfFact]
public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff1()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ public override AbstractFormattingRule WithOptions(SyntaxFormattingOptions optio
return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
}

// [Attribute1]$${EOF}
if (currentToken.IsKind(SyntaxKind.EndOfFileToken))
{
return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
}

// [Attribute]$$ int Prop { ... }
return CreateAdjustSpacesOperation(1, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
}
Expand Down

0 comments on commit ab5e014

Please sign in to comment.