forked from qt-creator/qt-creator
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:
@@ -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 *);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user