Skip to content
This repository has been archived by the owner on May 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request Unity-Technologies#82 from Unity-Technologies/fixe…
Browse files Browse the repository at this point in the history
…s/force-string-literal-to-column-1

Fixes/force string literal to column 1
  • Loading branch information
hschlichter authored Jan 5, 2018
2 parents 8b7d652 + d47bddb commit 90e5acf
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 53 deletions.
14 changes: 14 additions & 0 deletions src/indent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,20 @@ void indent_text(void)
pc = chunk_get_head();
while (pc != nullptr)
{
// forces string literal to column-1 [Fix for 1246]
if ( (pc->type == CT_STRING || pc->type == CT_STRING_MULTI)
&& !(cpd.lang_flags & LANG_OC))
{
string str = pc->text();
if ((str[0] == '@') && (chunk_get_prev(pc)->type == CT_NEWLINE))
{
indent_column_set(1);
reindent_line(pc, indent_column);
pc = chunk_get_next(pc);
did_newline = false;
}
}

if (pc->type == CT_NEWLINE)
{
LOG_FMT(LINDLINE, "%s(%d): orig_line is %zu, NEWLINE\n",
Expand Down
63 changes: 38 additions & 25 deletions tests/input/staging/UNI-2020.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
// This has to do with the @" that opens a literal string getting aligned when we don't want it to.
// Test code:
// As discussed with unity updating the test case

void Func()
{
OtherFunc(
@"multi
line");
}
var a = @"asdasda";
var d =
@"asdasda";

// ...becomes:
var d =
@"asdasda";

void Func()
{
OtherFunc(
@"multi
line");
}
var b = @"
line1
line2";

// (This also happens with var x = \n@"" and probably a few other scenarios.)
// There's no way to keep it from indenting the first line of the string literal. We want to leave it at column 1 because it's being used for a "here doc" that doesn't want leading spaces from indentation. It's weird looking for just the first line to be indented.
// This likely requires a new Uncrustify feature to support.
// Workaround: start the @" on the previous line and permit the string to have an extra empty first line, like this:
var c = Very(Long(Nested(Function(
@"line1
line2"))));

void Func()
{
OtherFunc(@"
multi
line");
}
var c = Very(Long(Nested(Function(
@"line1
line2"))));

var c = Function(
hey,
you,
@"line1
line2", fubar,
hmm);

// That might be ok for many cases, especially here-docs that are for script source.
var c = Function(
hey,
you,
@"line1
line2", fubar,
hmm);

var c = Function(
hey,
you,
@"line1
line2",
fubar,
hmm);
}
2 changes: 1 addition & 1 deletion tests/output/cs/10090-string_multi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public void F()
var y = @"
abc" + "def";
var z = "" +
@"
@"
";
}
}
2 changes: 1 addition & 1 deletion tests/output/staging/10015-misc-failures.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
void Func()
{
OtherFunc(
@"multi
@"multi
line");
}

Expand Down
63 changes: 38 additions & 25 deletions tests/output/staging/10074-UNI-2020.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
// This has to do with the @" that opens a literal string getting aligned when we don't want it to.
// Test code:
// As discussed with unity updating the test case

void Func()
{
OtherFunc(
@"multi
line");
}
var a = @"asdasda";

// ...becomes:
var d =
@"asdasda";

void Func()
{
OtherFunc(
@"multi
line");
}
var d =
@"asdasda";

// (This also happens with var x = \n@"" and probably a few other scenarios.)
// There's no way to keep it from indenting the first line of the string literal. We want to leave it at column 1 because it's being used for a "here doc" that doesn't want leading spaces from indentation. It's weird looking for just the first line to be indented.
// This likely requires a new Uncrustify feature to support.
// Workaround: start the @" on the previous line and permit the string to have an extra empty first line, like this:
var b = @"
line1
line2";

void Func()
{
OtherFunc(@"
multi
line");
}
var c = Very(Long(Nested(Function(
@"line1
line2"))));

// That might be ok for many cases, especially here-docs that are for script source.
var c = Very(Long(Nested(Function(
@"line1
line2"))));

var c = Function(
hey,
you,
@"line1
line2", fubar,
hmm);

var c = Function(
hey,
you,
@"line1
line2", fubar,
hmm);

var c = Function(
hey,
you,
@"line1
line2",
fubar,
hmm);
}
1 change: 1 addition & 0 deletions tests/regression.test
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
10071 staging/Uncrustify.Cpp.cfg staging/UNI-1983.cpp
10072 staging/Uncrustify.CSharp.cfg staging/UNI-2007.cs
10073 staging/Uncrustify.CSharp.cfg staging/UNI-2008.cs
10074 staging/Uncrustify.CSharp.cfg staging/UNI-2020.cs
10075 staging/UNI-2021.cfg staging/UNI-2021.cs
10076 staging/UNI-1343.cfg staging/UNI-1343.cs
10077 staging/Uncrustify.CSharp.cfg staging/UNI-1919.cs
Expand Down
1 change: 0 additions & 1 deletion tests/staging.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
10061 staging/Uncrustify.CSharp.cfg staging/UNI-1355.cs
10064 staging/Uncrustify.CSharp.cfg staging/UNI-1443.cs
10068 staging/Uncrustify.CSharp.cfg staging/UNI-1979.cs
10074 staging/Uncrustify.CSharp.cfg staging/UNI-2020.cs
10076 staging/Uncrustify.CSharp.cfg staging/UNI-1343.cs
60004 staging/Uncrustify.CSharp.cfg staging/UNI-2684.cs
60005 staging/Uncrustify.CSharp.cfg staging/UNI-2685.cs
Expand Down

0 comments on commit 90e5acf

Please sign in to comment.