summaryrefslogtreecommitdiff
path: root/src/libs/qmljs/qmljscheck.cpp
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2011-09-30 12:11:58 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2011-10-10 14:40:17 +0200
commitbf3bf658c4cd726e6bb3b4febb7768782f468966 (patch)
treea547ed6e95fd625b083643d92e74ffe26e350b76 /src/libs/qmljs/qmljscheck.cpp
parent1b0dc76564200f768010e9486c6895433027c607 (diff)
downloadqt-creator-bf3bf658c4cd726e6bb3b4febb7768782f468966.tar.gz
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>
Diffstat (limited to 'src/libs/qmljs/qmljscheck.cpp')
-rw-r--r--src/libs/qmljs/qmljscheck.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/libs/qmljs/qmljscheck.cpp b/src/libs/qmljs/qmljscheck.cpp
index da9c5cf78d..4f6860209d 100644
--- a/src/libs/qmljs/qmljscheck.cpp
+++ b/src/libs/qmljs/qmljscheck.cpp
@@ -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.