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 [racer](https://github.com/phildawes/racer) had one instance of `x.pop() && x.pop()`), so we removed matching any function or method calls. We may introduce a whitelist of known pure functions in the future.
13 /// **Example:** `x + 1 == x + 1`
17 "equal operands on both sides of a comparison or bitwise combination (e.g. `x == x`)"
23 impl LintPass for EqOp {
24 fn get_lints(&self) -> LintArray {
29 impl LateLintPass for EqOp {
30 fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
31 if let ExprBinary(ref op, ref left, ref right) = e.node {
32 if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {
36 &format!("equal expressions as operands to `{}`", op.node.as_str()));
43 fn is_valid_operator(op: &BinOp) -> bool {