2 * @fileoverview Rule to flag bitwise identifiers
3 * @author Nicholas C. Zakas
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 module.exports = function(context) {
14 var BITWISE_OPERATORS = [
15 "^", "|", "&", "<<", ">>", ">>>",
16 "^=", "|=", "&=", "<<=", ">>=", ">>>=",
21 * Reports an unexpected use of a bitwise operator.
22 * @param {ASTNode} node Node which contains the bitwise operator.
25 function report(node) {
26 context.report(node, "Unexpected use of '{{operator}}'.", { operator: node.operator });
30 * Checks if the given node has a bitwise operator.
31 * @param {ASTNode} node The node to check.
32 * @returns {boolean} Whether or not the node has a bitwise operator.
34 function hasBitwiseOperator(node) {
35 return BITWISE_OPERATORS.indexOf(node.operator) !== -1;
39 * Report if the given node contains a bitwise operator.
40 * @param {ASTNode} node The node to check.
43 function checkNodeForBitwiseOperator(node) {
44 if (hasBitwiseOperator(node)) {
50 "AssignmentExpression": checkNodeForBitwiseOperator,
51 "BinaryExpression": checkNodeForBitwiseOperator,
52 "UnaryExpression": checkNodeForBitwiseOperator