Commit d4856623 authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS checks: Hint about extra parentheses.

Migrated from QtChecker.

Change-Id: I85f7dd039ac858b103dfe0af257f66031540c5de
Reviewed-on: http://codereview.qt-project.org/5969


Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@nokia.com>
parent 038111c3
......@@ -525,6 +525,7 @@ Check::Check(Document::Ptr doc, const ContextPtr &context)
disableMessage(HintDeclarationsShouldBeAtStartOfFunction);
disableMessage(HintBinaryOperatorSpacing);
disableMessage(HintOneStatementPerLine);
disableMessage(HintExtraParentheses);
}
Check::~Check()
......@@ -1104,6 +1105,13 @@ void Check::checkBindingRhs(Statement *statement)
addMessages(unreachableCheck(statement));
}
void Check::checkExtraParentheses(ExpressionNode *expression)
{
if (NestedExpression *nested = cast<NestedExpression *>(expression)) {
addMessage(HintExtraParentheses, nested->lparenToken);
}
}
void Check::addMessages(const QList<Message> &messages)
{
foreach (const Message &msg, messages)
......@@ -1199,6 +1207,30 @@ bool Check::visit(StatementList *ast)
return true;
}
bool Check::visit(ReturnStatement *ast)
{
checkExtraParentheses(ast->expression);
return true;
}
bool Check::visit(ThrowStatement *ast)
{
checkExtraParentheses(ast->expression);
return true;
}
bool Check::visit(DeleteExpression *ast)
{
checkExtraParentheses(ast->expression);
return true;
}
bool Check::visit(TypeOfExpression *ast)
{
checkExtraParentheses(ast->expression);
return true;
}
/// When something is changed here, also change ReadingContext::lookupProperty in
/// texttomodelmerger.cpp
/// ### Maybe put this into the context as a helper method.
......
......@@ -96,6 +96,10 @@ protected:
virtual bool visit(AST::NewMemberExpression *ast);
virtual bool visit(AST::CallExpression *ast);
virtual bool visit(AST::StatementList *ast);
virtual bool visit(AST::ReturnStatement *ast);
virtual bool visit(AST::ThrowStatement *ast);
virtual bool visit(AST::DeleteExpression *ast);
virtual bool visit(AST::TypeOfExpression *ast);
virtual void endVisit(QmlJS::AST::UiObjectInitializer *);
......@@ -108,6 +112,7 @@ private:
void checkProperty(QmlJS::AST::UiQualifiedId *);
void checkNewExpression(AST::ExpressionNode *node);
void checkBindingRhs(AST::Statement *statement);
void checkExtraParentheses(AST::ExpressionNode *expression);
void addMessages(const QList<StaticAnalysis::Message> &messages);
void addMessage(const StaticAnalysis::Message &message);
......
......@@ -150,9 +150,8 @@ StaticAnalysisMessages::StaticAnalysisMessages()
tr("confusing minuses"));
newMsg(HintDeclareVarsInOneLine, Hint,
tr("declare all function vars on a single line"));
// unused
// newMsg(HintExtraParentheses, Hint,
// tr(""));
newMsg(HintExtraParentheses, Hint,
tr("unnecessary parentheses"));
newMsg(MaybeWarnEqualityTypeCoercion, MaybeWarning,
tr("== and != may perform type coercion, use === or !== to avoid"));
newMsg(WarnConfusingExpressionStatement, Warning,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment