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>
This commit is contained in:
Christian Kamm
2011-09-30 10:39:00 +02:00
parent aeadbcae40
commit c82d53d4ae
5 changed files with 44 additions and 7 deletions

View File

@@ -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;
}

View File

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

View File

@@ -88,9 +88,7 @@ enum Type
WarnBlock = 115,
WarnVoid = 116,
WarnConfusingPluses = 117,
WarnConfusingPreincrement = 118,
WarnConfusingMinuses = 119,
WarnConfusingPredecrement = 120,
HintDeclareVarsInOneLine = 121,
HintExtraParentheses = 123,
MaybeWarnEqualityTypeCoercion = 126,