aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2020-06-17 14:06:11 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2020-07-02 15:11:29 +0200
commiteb2e53ae81239b561022940db27e65c23506450c (patch)
tree00e6e357c038a42d9f214aa62101423b857463f1 /tools
parentd9a051a7056212d521c1f8aa3f8e5d66b1a01e96 (diff)
qmlformat: Fix nested ifs
Fixes: QTBUG-85077 Change-Id: Ia2fec64a389fd7355f3fcf9438408b021c5abef4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit df1f4c9a9f3e3c60fdd43513fdc4926c0cbaa553)
Diffstat (limited to 'tools')
-rw-r--r--tools/qmlformat/dumpastvisitor.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp
index 9f49fe0090..06a6f6335f 100644
--- a/tools/qmlformat/dumpastvisitor.cpp
+++ b/tools/qmlformat/dumpastvisitor.cpp
@@ -578,6 +578,23 @@ QString DumpAstVisitor::parseExportsList(ExportsList *list)
return result;
}
+bool needsSemicolon(int kind)
+{
+ switch (kind) {
+ case Node::Kind_ForStatement:
+ case Node::Kind_ForEachStatement:
+ case Node::Kind_IfStatement:
+ case Node::Kind_SwitchStatement:
+ case Node::Kind_WhileStatement:
+ case Node::Kind_DoWhileStatement:
+ case Node::Kind_TryStatement:
+ case Node::Kind_WithStatement:
+ return false;
+ default:
+ return true;
+ }
+}
+
QString DumpAstVisitor::parseBlock(Block *block, bool hasNext, bool allowBraceless)
{
bool hasOneLine = (block->statements == nullptr || block->statements->next == nullptr) && allowBraceless;
@@ -593,7 +610,10 @@ QString DumpAstVisitor::parseBlock(Block *block, bool hasNext, bool allowBracele
if (!hasNext && !hasOneLine)
result += formatLine("}", false);
- m_blockNeededBraces |= (block->statements && block->statements->next != nullptr);
+ if (block->statements) {
+ m_blockNeededBraces |= !needsSemicolon(block->statements->statement->kind)
+ || (block->statements->next != nullptr);
+ }
return result;
}
@@ -834,24 +854,6 @@ QString DumpAstVisitor::parseStatement(Statement *statement, bool blockHasNext,
}
}
-bool needsSemicolon(int kind)
-{
- switch (kind)
- {
- case Node::Kind_ForStatement:
- case Node::Kind_ForEachStatement:
- case Node::Kind_IfStatement:
- case Node::Kind_SwitchStatement:
- case Node::Kind_WhileStatement:
- case Node::Kind_DoWhileStatement:
- case Node::Kind_TryStatement:
- case Node::Kind_WithStatement:
- return false;
- default:
- return true;
- }
-}
-
QString DumpAstVisitor::parseStatementList(StatementList *list)
{
QString result = "";