forked from qt-creator/qt-creator
QmlJS: Restrict warnings of blocks
Warn only if the block contains a var statement as this is discouraged. Fixes: QTCREATORBUG-24214 Change-Id: Ib96c6723e82b6ddce0b7b63f23d3408f45ae7d58 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
@@ -1367,7 +1367,8 @@ bool Check::visit(Block *ast)
|
||||
&& !cast<IfStatement *>(p)
|
||||
&& !cast<SwitchStatement *>(p)
|
||||
&& !isCaseOrDefault(p)
|
||||
&& !cast<WithStatement *>(p)) {
|
||||
&& !cast<WithStatement *>(p)
|
||||
&& hasVarStatement(ast)) {
|
||||
addMessage(WarnBlock, ast->lbraceToken);
|
||||
}
|
||||
if (!ast->statements
|
||||
@@ -1666,6 +1667,24 @@ bool Check::isCaseOrDefault(Node *n)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Check::hasVarStatement(AST::Block *b) const
|
||||
{
|
||||
QTC_ASSERT(b, return false);
|
||||
StatementList *s = b->statements;
|
||||
while (s) {
|
||||
if (auto var = cast<VariableStatement *>(s->statement)) {
|
||||
VariableDeclarationList *declList = var->declarations;
|
||||
while (declList) {
|
||||
if (declList->declaration && declList->declaration->scope == VariableScope::Var)
|
||||
return true;
|
||||
declList = declList->next;
|
||||
}
|
||||
}
|
||||
s = s->next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Check::visit(NewExpression *ast)
|
||||
{
|
||||
checkNewExpression(ast->expression);
|
||||
|
||||
@@ -123,6 +123,7 @@ private:
|
||||
bool isQtQuick2Ui() const;
|
||||
|
||||
bool isCaseOrDefault(AST::Node *n);
|
||||
bool hasVarStatement(AST::Block *b) const;
|
||||
|
||||
AST::Node *parent(int distance = 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user