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

QmlJS checks: Add hint about not using multiple statements per line.

Migrated from QtChecker.

Change-Id: Ia76067a5f0e443a61a7b78ca9081f5a1bb51b471
Reviewed-on: http://codereview.qt-project.org/5861


Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@nokia.com>
parent 1b0dc765
......@@ -519,6 +519,7 @@ Check::Check(Document::Ptr doc, const ContextPtr &context)
disableMessage(HintDeclareVarsInOneLine);
disableMessage(HintDeclarationsShouldBeAtStartOfFunction);
disableMessage(HintBinaryOperatorSpacing);
disableMessage(HintOneStatementPerLine);
}
Check::~Check()
......@@ -1165,6 +1166,32 @@ bool Check::visit(CallExpression *ast)
return true;
}
bool Check::visit(StatementList *ast)
{
SourceLocation warnStart;
SourceLocation warnEnd;
unsigned currentLine = 0;
for (StatementList *it = ast; it; it = it->next) {
if (!it->statement)
continue;
const SourceLocation itLoc = it->statement->firstSourceLocation();
if (itLoc.startLine != currentLine) { // first statement on a line
if (warnStart.isValid())
addMessage(HintOneStatementPerLine, locationFromRange(warnStart, warnEnd));
warnStart = SourceLocation();
currentLine = itLoc.startLine;
} else { // other statements on the same line
if (!warnStart.isValid())
warnStart = itLoc;
warnEnd = it->statement->lastSourceLocation();
}
}
if (warnStart.isValid())
addMessage(HintOneStatementPerLine, locationFromRange(warnStart, warnEnd));
return true;
}
/// When something is changed here, also change ReadingContext::lookupProperty in
/// texttomodelmerger.cpp
/// ### Maybe put this into the context as a helper method.
......
......@@ -95,6 +95,7 @@ protected:
virtual bool visit(AST::NewExpression *ast);
virtual bool visit(AST::NewMemberExpression *ast);
virtual bool visit(AST::CallExpression *ast);
virtual bool visit(AST::StatementList *ast);
virtual void endVisit(QmlJS::AST::UiObjectInitializer *);
......
Supports Markdown
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