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

QmlJS checks: Add confusing +/- check.

Migrated from QtChecker.

Change-Id: I06115152f979f9abfa9cbdf4a3e2e63a51ea7284
Reviewed-on: http://codereview.qt-project.org/5858

Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@nokia.com>
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
parent aeadbcae
......@@ -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;
}
......
......@@ -146,12 +146,8 @@ StaticAnalysisMessages::StaticAnalysisMessages()
tr("do not use void expressions"));
newMsg(WarnConfusingPluses, Warning,
tr("confusing pluses"));
newMsg(WarnConfusingPreincrement, Warning,
tr("confusing preincrement"));
newMsg(WarnConfusingMinuses, Warning,
tr("confusing minuses"));
newMsg(WarnConfusingPredecrement, Warning,
tr("confusing predecrement"));
newMsg(HintDeclareVarsInOneLine, Hint,
tr("declare all function vars on a single line"));
// unused
......
......@@ -88,9 +88,7 @@ enum Type
WarnBlock = 115,
WarnVoid = 116,
WarnConfusingPluses = 117,
WarnConfusingPreincrement = 118,
WarnConfusingMinuses = 119,
WarnConfusingPredecrement = 120,
HintDeclareVarsInOneLine = 121,
HintExtraParentheses = 123,
MaybeWarnEqualityTypeCoercion = 126,
......
import QtQuick 1.0
Item {
function foo() {
var x, y
x = 1 + +2 // 117 15 17
x = 1 + ++x // 117 15 17
x = x++ + x // 117 15 17
x = 1 - -2 // 119 15 17
x = 1 - --x // 119 15 17
x = x-- - x // 119 15 17
x = x + --y + y-- + x++ - y
}
}
......@@ -162,7 +162,7 @@ void tst_Check::test()
fail |= !QCOMPARE_NOEXIT(actual.location.startLine, expected.location.startLine);
if (fail)
return;
fail |= !QCOMPARE_NOEXIT(actual.type, expected.type);
fail |= !QCOMPARE_NOEXIT((int)actual.type, (int)expected.type);
fail |= !QCOMPARE_NOEXIT(actual.location.startColumn, expected.location.startColumn);
fail |= !QCOMPARE_NOEXIT(actual.location.offset, expected.location.offset);
fail |= !QCOMPARE_NOEXIT(actual.location.length, expected.location.length);
......
Markdown is supported
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