main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.6 KB
|
Line | |
---|
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 | /** @type {import('../shared/types').Rule} */
|
---|
13 | module.exports = {
|
---|
14 | meta: {
|
---|
15 | type: "problem",
|
---|
16 |
|
---|
17 | docs: {
|
---|
18 | description: "Disallow `new` operators with the `Symbol` object",
|
---|
19 | recommended: true,
|
---|
20 | url: "https://eslint.org/docs/latest/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 | const sourceCode = context.sourceCode;
|
---|
33 |
|
---|
34 | return {
|
---|
35 | "Program:exit"(node) {
|
---|
36 | const globalScope = sourceCode.getScope(node);
|
---|
37 | const variable = globalScope.set.get("Symbol");
|
---|
38 |
|
---|
39 | if (variable && variable.defs.length === 0) {
|
---|
40 | variable.references.forEach(ref => {
|
---|
41 | const idNode = ref.identifier;
|
---|
42 | const parent = idNode.parent;
|
---|
43 |
|
---|
44 | if (parent && parent.type === "NewExpression" && parent.callee === idNode) {
|
---|
45 | context.report({
|
---|
46 | node: idNode,
|
---|
47 | messageId: "noNewSymbol"
|
---|
48 | });
|
---|
49 | }
|
---|
50 | });
|
---|
51 | }
|
---|
52 | }
|
---|
53 | };
|
---|
54 |
|
---|
55 | }
|
---|
56 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.