Skip to content

Commit

Permalink
Merge pull request #59706 from sharwell/formatting-attributes
Browse files Browse the repository at this point in the history
Fix formatting of attributes at end of file
  • Loading branch information
sharwell authored Feb 24, 2022
2 parents 372e6ef + ab5e014 commit c5713c6
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 c5713c6

Please sign in to comment.