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 | url: "https://eslint.org/docs/rules/no-new-symbol"
|
19 | },
|
20 |
|
21 | schema: []
|
22 | },
|
23 |
|
24 | create(context) {
|
25 |
|
26 | return {
|
27 | "Program:exit"() {
|
28 | const globalScope = context.getScope();
|
29 | const variable = globalScope.set.get("Symbol");
|
30 |
|
31 | if (variable && variable.defs.length === 0) {
|
32 | variable.references.forEach(ref => {
|
33 | const node = ref.identifier;
|
34 |
|
35 | if (node.parent && node.parent.type === "NewExpression") {
|
36 | context.report({ node, message: "`Symbol` cannot be called as a constructor." });
|
37 | }
|
38 | });
|
39 | }
|
40 | }
|
41 | };
|
42 |
|
43 | }
|
44 | };
|