summaryrefslogtreecommitdiff
path: root/src/libs/qmljs/qmljscheck.cpp
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2011-09-30 10:39:00 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2011-10-10 14:39:56 +0200
commitc82d53d4ae413004dae3b2b7dc0da55fd8cfb077 (patch)
treeff71774565d24806b090609956b4a2a6245688df /src/libs/qmljs/qmljscheck.cpp
parentaeadbcae4086ebef0ee0fe45ae4a4f62be8121ab (diff)
downloadqt-creator-c82d53d4ae413004dae3b2b7dc0da55fd8cfb077.tar.gz
QmlJS checks: Add confusing +/- check.
Migrated from QtChecker. Change-Id: I06115152f979f9abfa9cbdf4a3e2e63a51ea7284 Reviewed-on: http://codereview.qt-project.org/5858 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com> Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Diffstat (limited to 'src/libs/qmljs/qmljscheck.cpp')
-rw-r--r--src/libs/qmljs/qmljscheck.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libs/qmljs/qmljscheck.cpp b/src/libs/qmljs/qmljscheck.cpp
index 81da022205..f22588e3a4 100644
--- a/src/libs/qmljs/qmljscheck.cpp
+++ b/src/libs/qmljs/qmljscheck.cpp
@@ -873,6 +873,35 @@ bool Check::visit(BinaryExpression *ast)
addMessage(MaybeWarnEqualityTypeCoercion, ast->operatorToken);
}
}
+
+ // check odd + ++ combinations
+ const QLatin1Char newline('\n');
+ if (ast->op == QSOperator::Add || ast->op == QSOperator::Sub) {
+ QChar match;
+ Type msg;
+ if (ast->op == QSOperator::Add) {
+ match = QLatin1Char('+');
+ msg = WarnConfusingPluses;
+ } else {
+ QTC_CHECK(ast->op == QSOperator::Sub);
+ match = QLatin1Char('-');
+ msg = WarnConfusingMinuses;
+ }
+
+ if (int(op.end()) + 1 < source.size()) {
+ const QChar next = source.at(op.end());
+ if (next.isSpace() && next != newline
+ && source.at(op.end() + 1) == match)
+ addMessage(msg, SourceLocation(op.begin(), 3, op.startLine, op.startColumn));
+ }
+ if (op.begin() >= 2) {
+ const QChar prev = source.at(op.begin() - 1);
+ if (prev.isSpace() && prev != newline
+ && source.at(op.begin() - 2) == match)
+ addMessage(msg, SourceLocation(op.begin() - 2, 3, op.startLine, op.startColumn - 2));
+ }
+ }
+
return true;
}