dc68c50046f2ffffdb49127fd3dd8cbb57e9d8b2
[platform/framework/web/crosswalk-tizen.git] /
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 "use strict";
8
9 //------------------------------------------------------------------------------
10 // Rule Definition
11 //------------------------------------------------------------------------------
12
13 module.exports = function(context) {
14
15     return {
16
17         "BinaryExpression": function(node) {
18             var operators = ["===", "==", "!==", "!=", ">", "<", ">=", "<="];
19             if (operators.indexOf(node.operator) > -1 &&
20                 (node.left.type === "Identifier" && node.right.type === "Identifier" && node.left.name === node.right.name ||
21                 node.left.type === "Literal" && node.right.type === "Literal" && node.left.value === node.right.value)) {
22                 context.report(node, "Comparing to itself is potentially pointless.");
23             }
24         }
25     };
26
27 };