summaryrefslogtreecommitdiff
path: root/src/libs/qmljs/qmljscheck.cpp
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2011-09-30 10:07:37 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2011-10-10 14:39:49 +0200
commitaeadbcae4086ebef0ee0fe45ae4a4f62be8121ab (patch)
tree08be607c390eaed1c390d0e66c44b9604b744696 /src/libs/qmljs/qmljscheck.cpp
parentda123becafb8cfb3a3a453049563bae29b135147 (diff)
downloadqt-creator-aeadbcae4086ebef0ee0fe45ae4a4f62be8121ab.tar.gz
QmlJS checks: Add check for spacing around binary operators.
Adapted from QtChecker. Change-Id: I434582314e6431c56c9628a5a642bbfb032dfc2f Reviewed-on: http://codereview.qt-project.org/5857 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.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/libs/qmljs/qmljscheck.cpp b/src/libs/qmljs/qmljscheck.cpp
index cdf88e0c01..81da022205 100644
--- a/src/libs/qmljs/qmljscheck.cpp
+++ b/src/libs/qmljs/qmljscheck.cpp
@@ -518,6 +518,7 @@ Check::Check(Document::Ptr doc, const ContextPtr &context)
disableMessage(HintAnonymousFunctionSpacing);
disableMessage(HintDeclareVarsInOneLine);
disableMessage(HintDeclarationsShouldBeAtStartOfFunction);
+ disableMessage(HintBinaryOperatorSpacing);
}
Check::~Check()
@@ -853,12 +854,22 @@ static bool shouldAvoidNonStrictEqualityCheck(const Value *lhs, const Value *rhs
bool Check::visit(BinaryExpression *ast)
{
+ const QString source = _doc->source();
+
+ // check spacing
+ SourceLocation op = ast->operatorToken;
+ if ((op.begin() > 0 && !source.at(op.begin() - 1).isSpace())
+ || (int(op.end()) < source.size() && !source.at(op.end()).isSpace())) {
+ addMessage(HintBinaryOperatorSpacing, op);
+ }
+
+ // check ==, !=
if (ast->op == QSOperator::Equal || ast->op == QSOperator::NotEqual) {
Evaluate eval(&_scopeChain);
- const Value *lhs = eval(ast->left);
- const Value *rhs = eval(ast->right);
- if (shouldAvoidNonStrictEqualityCheck(lhs, rhs)
- || shouldAvoidNonStrictEqualityCheck(rhs, lhs)) {
+ const Value *lhsValue = eval(ast->left);
+ const Value *rhsValue = eval(ast->right);
+ if (shouldAvoidNonStrictEqualityCheck(lhsValue, rhsValue)
+ || shouldAvoidNonStrictEqualityCheck(rhsValue, lhsValue)) {
addMessage(MaybeWarnEqualityTypeCoercion, ast->operatorToken);
}
}