1 | /**
|
2 | * @fileoverview Rule to disallow use of the new operator with the `Symbol` object
|
3 | * @author Alberto Rodríguez
|
4 | * @copyright 2016 Alberto Rodríguez. All rights reserved.
|
5 | * See LICENSE file in root directory for full license.
|
6 | */
|
7 |
|
8 | ;
|
9 |
|
10 | //------------------------------------------------------------------------------
|
11 | // Rule Definition
|
12 | //------------------------------------------------------------------------------
|
13 |
|
14 | module.exports = function(context) {
|
15 |
|
16 | return {
|
17 | "Program:exit": function() {
|
18 | var globalScope = context.getScope();
|
19 | var variable = globalScope.set.get("Symbol");
|
20 | if (variable && variable.defs.length === 0) {
|
21 | variable.references.forEach(function(ref) {
|
22 | var node = ref.identifier;
|
23 | if (node.parent && node.parent.type === "NewExpression") {
|
24 | context.report(node, "`Symbol` cannot be called as a constructor.");
|
25 | }
|
26 | });
|
27 | }
|
28 | }
|
29 | };
|
30 |
|
31 | };
|
32 |
|
33 | module.exports.schema = [];
|