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: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
Christian Kamm
2011-09-30 12:11:58 +02:00
parent 1b0dc76564
commit bf3bf658c4
2 changed files with 28 additions and 0 deletions

View File

@@ -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.

View File

@@ -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 *);