]> git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-new-symbol.js
first commit
[pve-eslint.git] / eslint / lib / rules / no-new-symbol.js
1 /**
2 * @fileoverview Rule to disallow use of the new operator with the `Symbol` object
3 * @author Alberto Rodríguez
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Rule Definition
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 messages: {
26 noNewSymbol: "`Symbol` cannot be called as a constructor."
27 }
28 },
29
30 create(context) {
31
32 return {
33 "Program:exit"() {
34 const globalScope = context.getScope();
35 const variable = globalScope.set.get("Symbol");
36
37 if (variable && variable.defs.length === 0) {
38 variable.references.forEach(ref => {
39 const node = ref.identifier;
40
41 if (node.parent && node.parent.type === "NewExpression") {
42 context.report({
43 node,
44 messageId: "noNewSymbol"
45 });
46 }
47 });
48 }
49 }
50 };
51
52 }
53 };