[clang-format] Improve C# handling of spaces in square brackets

Reviewers: MyDeveloperDay, krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75336
This commit is contained in:
Jonathan Coe 2020-02-28 12:44:15 +00:00
parent ca950a6bb1
commit f829615205
2 changed files with 4 additions and 8 deletions

View File

@ -2902,8 +2902,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
if (Left.is(TT_TemplateCloser) && Right.is(TT_StartOfName))
return true;
// space after comma in '[,]'.
if (Left.is(tok::comma) && Right.is(tok::r_square))
// spaces inside square brackets.
if (Left.is(tok::l_square) || Right.is(tok::r_square))
return Style.SpacesInSquareBrackets;
// No space before ? in nullable types.

View File

@ -600,7 +600,7 @@ TEST_F(FormatTestCSharp, CSharpSpaces) {
verifyFormat(R"(private float[,] Values;)", Style);
Style.SpacesInSquareBrackets = true;
verifyFormat(R"(private float[, ] Values;)", Style);
verifyFormat(R"(private float[ , ] Values;)", Style);
}
TEST_F(FormatTestCSharp, CSharpNullableTypes) {
@ -608,11 +608,7 @@ TEST_F(FormatTestCSharp, CSharpNullableTypes) {
Style.SpacesInSquareBrackets = false;
verifyFormat(R"(public float? Value;)", Style); // no space before `?`.
// Erroneous spaces in square brackets here will be tackled in a follow-up
// patch and are not addressed by setting
// `Style.SpacesInSquareBrackets = false;`
verifyFormat(R"(int?[] arr = new int?[ 10 ];)",
verifyFormat(R"(int?[] arr = new int?[10];)",
Style); // An array of a nullable type.
}