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-06-18 12:46:17 +0200
commitdf1f4c9a9f3e3c60fdd43513fdc4926c0cbaa553 (patch)
treefeb139f73c591a838684a68d247c1dc89c1c402e /tools
parent58ed7422f550d32b5ace9edc7a4887727f53493a (diff)
qmlformat: Fix nested ifs
Fixes: QTBUG-85077 Change-Id: Ia2fec64a389fd7355f3fcf9438408b021c5abef4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
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 ad310ead3d..c8fb0b511f 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 = "";