UNPKG

925 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag comparison where left part is the same as the right
3 * part.
4 * @author Ilya Volodin
5 */
6
7//------------------------------------------------------------------------------
8// Rule Definition
9//------------------------------------------------------------------------------
10
11module.exports = function(context) {
12 "use strict";
13
14 return {
15
16 "BinaryExpression": function(node) {
17 var operators = ["===", "==", "!==","!=", ">", "<", ">=", "<="];
18 if (operators.indexOf(node.operator) > -1 &&
19 (node.left.type === "Identifier" && node.right.type === "Identifier" && node.left.name === node.right.name ||
20 node.left.type === "Literal" && node.right.type === "Literal" && node.left.value === node.right.value)) {
21 context.report(node, "Comparing to itself is potentially pointless.");
22 }
23 }
24 };
25
26};