3 use utils::{SpanlessEq, span_lint};
5 /// **What it does:** This lint checks for equal operands to comparison, logical and bitwise,
6 /// difference and division binary operators (`==`, `>`, etc., `&&`, `||`, `&`, `|`, `^`, `-` and
9 /// **Why is this bad?** This is usually just a typo or a copy and paste error.
11 /// **Known problems:** False negatives: We had some false positives regarding calls (notably
12 /// [racer](https://github.com/phildawes/racer) had one instance of `x.pop() && x.pop()`), so we
13 /// removed matching any function or method calls. We may introduce a whitelist of known pure
14 /// functions in the future.
23 "equal operands on both sides of a comparison or bitwise combination (e.g. `x == x`)"
29 impl LintPass for EqOp {
30 fn get_lints(&self) -> LintArray {
35 impl LateLintPass for EqOp {
36 fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
37 if let ExprBinary(ref op, ref left, ref right) = e.node {
38 if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {
42 &format!("equal expressions as operands to `{}`", op.node.as_str()));
49 fn is_valid_operator(op: &BinOp) -> bool {