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