UNPKG

859 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag bitwise identifiers
3 * @author Nicholas C. Zakas
4 */
5
6//------------------------------------------------------------------------------
7// Rule Definition
8//------------------------------------------------------------------------------
9
10module.exports = function(context) {
11
12 "use strict";
13
14 function report(node) {
15 context.report(node, "Unexpected use of '{{operator}}'.", { operator: node.operator });
16 }
17
18 return {
19 "BinaryExpression": function(node) {
20
21 // warn for ^ | & ~ << >> >>>
22 if (node.operator.match(/^(?:[\^&\|~]|<<|>>>?)$/)) {
23 report(node);
24 }
25
26 },
27
28 "UnaryExpression": function(node) {
29
30 // warn for ~
31 if (node.operator === "~") {
32 report(node);
33 }
34
35 }
36 };
37
38};