Skip to content

Commit 025d898

Browse files
authored
Merge pull request #172 from notpeter/hanging_comment
Fix: short comment following long comment close
2 parents 22e4509 + eb59d99 commit 025d898

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

CodeFormatCore/src/Format/Analyzer/LineBreakAnalyzer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,15 @@ void LineBreakAnalyzer::ComplexAnalyze(FormatState &f, const LuaSyntaxTree &t) {
107107

108108
} else {
109109
switch (stmt.GetTokenKind(t)) {
110-
case TK_SHORT_COMMENT:
111110
case TK_LONG_COMMENT:
111+
{
112+
auto nextToken = stmt.GetNextToken(t).GetTokenKind(t);
113+
if (nextToken == TK_SHORT_COMMENT) {
114+
break;
115+
}
116+
// Fall through
117+
}
118+
case TK_SHORT_COMMENT:
112119
case TK_SHEBANG: {
113120
BreakAfter(stmt, t, style.line_space_after_comment);
114121
break;

Test/src/FormatResult_unitest.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,3 +1147,31 @@ only_latin = {
11471147
}
11481148
)", style));
11491149
}
1150+
1151+
TEST(Format, issue_170) {
1152+
EXPECT_TRUE(TestHelper::TestFormatted(
1153+
R"(
1154+
--[[]]
1155+
)",
1156+
R"(
1157+
--[[]]
1158+
)"));
1159+
EXPECT_TRUE(TestHelper::TestFormatted(
1160+
R"(
1161+
--[[]]--
1162+
)",
1163+
R"(
1164+
--[[]] --
1165+
)"));
1166+
EXPECT_TRUE(TestHelper::TestFormatted(
1167+
R"(
1168+
--[[-----------
1169+
1170+
]]-------------
1171+
)",
1172+
R"(
1173+
--[[-----------
1174+
1175+
]] -------------
1176+
)"));
1177+
}

0 commit comments

Comments
 (0)