未验证 提交 fd0bf09b 编写于 作者: J Julien Couvreur 提交者: GitHub

Formatting: force a space after attribute on parameter (#42466)

上级 bf71ef42
......@@ -4435,7 +4435,7 @@ void AddClass(string name,[OptionalAttribute] object position,[OptionalAttrib
var expected = @"class Program
{
void AddClass(string name, [OptionalAttribute] object position, [OptionalAttribute] object bases)
void AddClass(string name, [OptionalAttribute] object position, [OptionalAttribute] object bases)
{
}
}";
......@@ -9555,5 +9555,45 @@ class C
};
}".Replace(" ", "\u00A0"));
}
[Fact, WorkItem(41022, "https://github.com/dotnet/roslyn/issues/41022")]
[Trait(Traits.Feature, Traits.Features.Formatting)]
public async Task SpacingAfterAttribute()
{
var code = @"class C
{
void M([My]string?[]?[] x)
{
}
}";
var expectedCode = @"class C
{
void M([My] string?[]?[] x)
{
}
}";
await AssertFormatAsync(expectedCode, code);
}
[Fact, WorkItem(41022, "https://github.com/dotnet/roslyn/issues/41022")]
[Trait(Traits.Feature, Traits.Features.Formatting)]
public async Task SpacingAfterAttribute_Multiple()
{
var code = @"class C
{
void M([My][My] int x)
{
}
}";
var expectedCode = @"class C
{
void M([My][My] int x)
{
}
}";
await AssertFormatAsync(expectedCode, code);
}
}
}
......@@ -258,6 +258,24 @@ public override AdjustSpacesOperation GetAdjustSpacesOperation(SyntaxToken previ
return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
}
if (previousToken.IsKind(SyntaxKind.CloseBracketToken) &&
previousToken.Parent.IsKind(SyntaxKind.AttributeList) &&
previousToken.Parent.IsParentKind(SyntaxKind.Parameter))
{
if (currentToken.IsKind(SyntaxKind.OpenBracketToken))
{
// multiple attribute on parameter stick together
// void M([...][...]
return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
}
else
{
// attribute is spaced from parameter type
// void M([...] int
return CreateAdjustSpacesOperation(1, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
}
}
// extension method on tuple type
// M(this (
if (currentToken.Kind() == SyntaxKind.OpenParenToken &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册