diff options
| author | Olivier De Cannière <olivier.decanniere@qt.io> | 2025-05-28 15:00:38 +0200 |
|---|---|---|
| committer | Olivier De Cannière <olivier.decanniere@qt.io> | 2025-05-30 22:25:39 +0200 |
| commit | 2e00bc40cce9286dcb1ef9ff88845778c316592c (patch) | |
| tree | 3806195ff655f2c41443748d4da8229d8c3b3ef6 /src/qmlcompiler/qqmljslintervisitor.cpp | |
| parent | afc5a1c6f49e33cee07d098728e3c0702e95d168 (diff) | |
qmllint: Warn about unintentional empty blocks
If a property binding is a js block without any statements, it could
mean that the user intended to create an object literal instead of an
empty block that returns undefined.
Task-number: QTBUG-129307
Change-Id: If242ddac140cce6479062194b785096ba1f6c0a6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljslintervisitor.cpp')
| -rw-r--r-- | src/qmlcompiler/qqmljslintervisitor.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/qmlcompiler/qqmljslintervisitor.cpp b/src/qmlcompiler/qqmljslintervisitor.cpp index b5d254a00c..540ba6c535 100644 --- a/src/qmlcompiler/qqmljslintervisitor.cpp +++ b/src/qmlcompiler/qqmljslintervisitor.cpp @@ -416,6 +416,22 @@ bool LinterVisitor::visit(ExpressionStatement *ast) return true; } +QQmlJSImportVisitor::BindingExpressionParseResult LinterVisitor::parseBindingExpression( + const QString &name, const QQmlJS::AST::Statement *statement, + const QQmlJS::AST::UiPublicMember *associatedPropertyDefinition) +{ + if (statement && statement->kind == (int)AST::Node::Kind::Kind_Block) { + const auto *block = static_cast<const AST::Block *>(statement); + if (!block->statements && associatedPropertyDefinition) { + m_logger->log("Unintentional empty block, use ({}) for empty object literal"_L1, + qmlUnintentionalEmptyBlock, + combine(block->lbraceToken, block->rbraceToken)); + } + } + + return QQmlJSImportVisitor::parseBindingExpression(name, statement, associatedPropertyDefinition); +} + void LinterVisitor::handleLiteralBinding(const QQmlJSMetaPropertyBinding &binding, const UiPublicMember *associatedPropertyDefinition) { |
