1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | module.exports = {
|
13 | meta: {
|
14 | docs: {
|
15 | description: "disallow `new` operators with the `Symbol` object",
|
16 | category: "ECMAScript 6",
|
17 | recommended: true
|
18 | },
|
19 |
|
20 | schema: []
|
21 | },
|
22 |
|
23 | create(context) {
|
24 |
|
25 | return {
|
26 | "Program:exit"() {
|
27 | const globalScope = context.getScope();
|
28 | const variable = globalScope.set.get("Symbol");
|
29 |
|
30 | if (variable && variable.defs.length === 0) {
|
31 | variable.references.forEach(function(ref) {
|
32 | const node = ref.identifier;
|
33 |
|
34 | if (node.parent && node.parent.type === "NewExpression") {
|
35 | context.report(node, "`Symbol` cannot be called as a constructor.");
|
36 | }
|
37 | });
|
38 | }
|
39 | }
|
40 | };
|
41 |
|
42 | }
|
43 | };
|